Skip to content

Commit dd85579

Browse files
committed
fix: docs expressions
1 parent 7f634b5 commit dd85579

File tree

4 files changed

+65
-35
lines changed

4 files changed

+65
-35
lines changed

modules/modules-docs.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,17 @@ let
114114
)
115115
);
116116

117+
inherit (import ../nix/commands/lib.nix { inherit pkgs; }) mkLocLast nestedOptionsType;
118+
117119
# TODO: display values like TOML instead.
118120
toMarkdown = optionsDocs:
119121
let
120-
optionsDocsPartitioned = partition (opt: (take 2 opt.loc) == [ "commands" "<name>" ]) optionsDocs;
122+
nixOnlyLocPrefix = [ "commands" "<name>" ];
123+
optionsDocsPartitioned = partition (opt: (take 2 opt.loc) == nixOnlyLocPrefix) optionsDocs;
121124
nixOnly = optionsDocsPartitioned.right;
125+
nixOnlyTopPartitioned = partition (opt: opt.loc == nixOnlyLocPrefix ++ [ "*" ]) nixOnly;
126+
nixOnlyPartitioned = partition (opt: ("${last opt.loc}" == "${mkLocLast nestedOptionsType.name}")) nixOnlyTopPartitioned.wrong;
127+
nixOnly_ = nixOnlyTopPartitioned.right ++ nixOnlyPartitioned.right ++ nixOnlyPartitioned.wrong;
122128
nixTOML = filter (opt: head opt.loc != "_module") optionsDocsPartitioned.wrong;
123129

124130
# TODO: handle opt.relatedPackages. What is it for?
@@ -168,7 +174,7 @@ let
168174
doc = [
169175
"# `devshell` options\n"
170176
"## Available only in `Nix`\n"
171-
(concatStringsSep "\n" (map optToMd nixOnly))
177+
(concatStringsSep "\n" (map optToMd nixOnly_))
172178
"## Available in `Nix` and `TOML`\n"
173179
(concatStringsSep "\n" (map optToMd nixTOML))
174180
];

nix/commands/flatOptions.nix

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ lib, strOrPackage }:
1+
{ lib, strOrPackage, flatOptionsType }:
22
with lib;
33
# These are all the options available for the commands.
44
{
@@ -14,16 +14,20 @@ with lib;
1414
type = types.nullOr types.str;
1515
default = null;
1616
description = ''
17-
Name of this command. Defaults to attribute name in commands.
17+
Name of this command.
18+
19+
Defaults to a `(${flatOptionsType.name}) package` name or pname if present.
20+
21+
The value of this option is required for a `(${flatOptionsType.name}) command`.
1822
'';
1923
};
2024

2125
category = mkOption {
2226
type = types.str;
2327
default = "[general commands]";
2428
description = ''
25-
Set a free text category under which this command is grouped
26-
and shown in the help menu.
29+
Sets a free text category under which this command is grouped
30+
and shown in the devshell menu.
2731
'';
2832
};
2933

@@ -64,7 +68,7 @@ with lib;
6468
type = types.bool;
6569
default = true;
6670
description = ''
67-
When `true`, the `command` or the `package` will be added to the environment.
71+
When `true`, the `(${flatOptionsType.name}) command` or the `(${flatOptionsType.name}) package` will be added to the environment.
6872
6973
Otherwise, they will not be added to the environment, but will be printed
7074
in the devshell description.

nix/commands/nestedOptions.nix

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
{ pkgs, strOrPackage, attrsNestedOf, pairHelpPackageType, pairHelpCommandType, flatOptionsType, maxDepth }:
1+
{ pkgs
2+
, strOrPackage
3+
, attrsNestedOf
4+
, pairHelpPackageType
5+
, pairHelpCommandType
6+
, flatOptionsType
7+
, nestedOptionsType
8+
, maxDepth
9+
}:
210
with pkgs.lib;
311
{
412
prefix = mkOption {
513
type = types.nullOr types.str;
614
default = "";
715
description = ''
8-
Possible `${flatOptionsType.name}.prefix`.
16+
Possible `(${flatOptionsType.name}) prefix`.
917
1018
Priority of this option when selecting a prefix: `1`.
1119
@@ -22,7 +30,7 @@ with pkgs.lib;
2230
type = types.nullOr (attrsNestedOf types.str);
2331
default = { };
2432
description = ''
25-
A leaf value becomes a `${flatOptionsType.name}.prefix`
33+
A leaf value becomes a `(${flatOptionsType.name}) prefix`
2634
of a `package` (`command`) with a matching path in `packages` (`commands`).
2735
2836
Priority of this option when selecting a prefix: `2`.
@@ -46,37 +54,38 @@ with pkgs.lib;
4654
]));
4755
default = { };
4856
description = ''
49-
A nested (max depth is ${toString maxDepth}) attrset of `${flatOptionsType.name}.package`-s
57+
A nested (max depth is ${toString maxDepth}) attrset of `(${flatOptionsType.name}) package`-s
5058
to describe in the devshell menu
5159
and optionally bring to the environment.
5260
5361
A path to a leaf value is concatenated via `.`
54-
and used as a suffix of `${flatOptionsType.name}.name`.
62+
and used as a `(${flatOptionsType.name}) name`.
5563
5664
A leaf value can be of three types.
5765
5866
1. When a `string` with a value `<string>`,
5967
devshell tries to resolve a derivation
60-
`pkgs.<string>` and use it as a `${flatOptionsType.name}.package`.
68+
`pkgs.<string>` and use it as a `(${flatOptionsType.name}) package`.
6169
62-
2. When a `derivation`, it's used as a `${flatOptionsType.name}.package`.
70+
2. When a `derivation`, it's used as a `(${flatOptionsType.name}) package`.
6371
6472
3. When a list with two elements:
6573
1. The first element is a `string`
66-
that is used to select a `${flatOptionsType.name}.help`.
67-
- Priority of this `string` (if present) when selecting a `${flatOptionsType.name}.help`: `4`.
74+
that is used to select a `(${flatOptionsType.name}) help`.
75+
- Priority of this `string` (if present) when selecting a `(${flatOptionsType.name}) help`: `4`.
6876
6977
Lowest priority: `1`.
7078
2. The second element is interpreted as if
7179
the leaf value were initially a `string` or a `derivation`.
7280
73-
Priority of `package.meta.description` (if present in the resolved `${flatOptionsType.name}.package`) when selecting a `${flatOptionsType.name}.help`: 2
81+
Priority of `package.meta.description` (if present in the resolved `(${flatOptionsType.name}) package`)
82+
when selecting a `(${flatOptionsType.name}) help`: 2
7483
7584
Lowest priority: `1`.
7685
7786
A user may prefer not to bring the environment some of the packages.
7887
79-
Priority of `expose = false` when selecting a `${flatOptionsType.name}.expose`: `1`.
88+
Priority of `expose = false` when selecting a `(${flatOptionsType.name}) expose`: `1`.
8089
8190
Lowest priority: `1`.
8291
'';
@@ -96,33 +105,33 @@ with pkgs.lib;
96105
]));
97106
default = { };
98107
description = ''
99-
A nested (max depth is ${toString maxDepth}) attrset of `${flatOptionsType.name}.command`-s
108+
A nested (max depth is ${toString maxDepth}) attrset of `(${flatOptionsType.name}) command`-s
100109
to describe in the devshell menu
101110
and bring to the environment.
102111
103112
A path to a leaf value is concatenated via `.`
104-
and used in the `${flatOptionsType.name}.name`.
113+
and used in the `(${flatOptionsType.name}) name`.
105114
106115
A leaf value can be of two types.
107116
108-
1. When a `string`, it's used as a `${flatOptionsType.name}.command`.
117+
1. When a `string`, it's used as a `(${flatOptionsType.name}) command`.
109118
110119
2. When a list with two elements:
111120
1. the first element of type `string` with a value `<string>`
112121
that is used to select a `help`;
113122
114-
Priority of the `<string>` (if present) when selecting a `${flatOptionsType.name}.help`: `4`
123+
Priority of the `<string>` (if present) when selecting a `(${flatOptionsType.name}) help`: `4`
115124
116125
Lowest priority: `1`.
117-
1. the second element of type `string` is used as a `command`.
126+
1. the second element of type `string` is used as a `(${flatOptionsType.name}) command`.
118127
'';
119128
};
120129

121130
help = mkOption {
122131
type = types.nullOr types.str;
123-
default = "no help message provided :(";
132+
default = "";
124133
description = ''
125-
Priority of this option when selecting a `${flatOptionsType.name}.help`: `1`.
134+
Priority of this option when selecting a `(${flatOptionsType.name}) help`: `1`.
126135
127136
Lowest priority: `1`.
128137
'';
@@ -137,9 +146,11 @@ with pkgs.lib;
137146
type = types.nullOr (attrsNestedOf types.str);
138147
default = { };
139148
description = ''
140-
A leaf value can be used as `${flatOptionsType.name}.help` for a `package` (`command`) with a matching path in `packages` (`commands`).
149+
A leaf value can be used as `(${flatOptionsType.name}) help`
150+
for a `(${flatOptionsType.name}) package` (`(${flatOptionsType.name}) command`)
151+
with a matching path in `(${nestedOptionsType.name}) packages` (`(${nestedOptionsType.name}) commands`).
141152
142-
Priority of this option when selecting a `${flatOptionsType.name}.help`: `3`.
153+
Priority of this option when selecting a `(${flatOptionsType.name}) help`: `3`.
143154
144155
Lowest priority: `1`.
145156
'';
@@ -160,7 +171,7 @@ with pkgs.lib;
160171
Otherwise, they can not be added to the environment,
161172
but will be printed in the devshell description.
162173
163-
Priority of this option when selecting a `${flatOptionsType.name}.expose`: `2`.
174+
Priority of this option when selecting a `(${flatOptionsType.name}) expose`: `2`.
164175
165176
Lowest priority: `1`.
166177
'';
@@ -175,11 +186,13 @@ with pkgs.lib;
175186
type = types.nullOr (attrsNestedOf types.bool);
176187
default = { };
177188
description = ''
178-
A nested (max depth is ${toString maxDepth}) attrset of `${flatOptionsType.name}.expose`-s.
189+
A nested (max depth is ${toString maxDepth}) attrset of `(${flatOptionsType.name}) expose`-s.
179190
180-
A leaf value can be used as `${flatOptionsType.name}.expose` for a `package` (`command`) with a matching path in `packages` (`commands`).
191+
A leaf value can be used as `(${flatOptionsType.name}) expose`
192+
for a `(${flatOptionsType.name}) package` (`(${flatOptionsType.name}) command`)
193+
with a matching path in `(${nestedOptionsType.name}) packages` (`(${nestedOptionsType.name}) commands`).
181194
182-
Priority of this option when selecting a `${flatOptionsType.name}.expose`: `3`.
195+
Priority of this option when selecting a `(${flatOptionsType.name}) expose`: `3`.
183196
184197
Lowest priority: `1`.
185198
'';

nix/commands/types.nix

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ rec {
3737
merge = mergeOneOption;
3838
};
3939

40-
flatOptions = import ./flatOptions.nix { inherit lib strOrPackage; };
40+
flatOptions = import ./flatOptions.nix { inherit lib strOrPackage flatOptionsType; };
4141

4242
mkAttrsToString = str: { __toString = _: str; };
4343

44+
mkLocLast = name: mkAttrsToString " (${name})";
45+
4446
flatOptionsType =
4547
let submodule = types.submodule { options = flatOptions; }; in
4648
submodule // rec {
@@ -50,7 +52,7 @@ rec {
5052
(name_: value: value // {
5153
loc = prefix ++ [
5254
name_
53-
(mkAttrsToString " (${name})")
55+
(mkLocLast name)
5456
];
5557
declarations = [ "${toString ../..}/nix/commands/flatOptions.nix" ];
5658
})
@@ -61,7 +63,12 @@ rec {
6163

6264
pairHelpCommandType = list2Of types.str types.str;
6365

64-
nestedOptions = import ./nestedOptions.nix { inherit pkgs strOrPackage attrsNestedOf pairHelpPackageType pairHelpCommandType flatOptionsType maxDepth; };
66+
nestedOptions = import ./nestedOptions.nix {
67+
inherit
68+
pkgs strOrPackage attrsNestedOf pairHelpPackageType
69+
pairHelpCommandType flatOptionsType maxDepth
70+
nestedOptionsType;
71+
};
6572

6673
nestedOptionsType =
6774
let submodule = types.submodule { options = nestedOptions; }; in
@@ -146,7 +153,7 @@ rec {
146153
mkOption {
147154
type = nestedConfigType;
148155
description = ''
149-
A config for command(s) when the `commands` option is an attrset ("nested").
156+
A config for command(s) when the `commands` option is an attrset.
150157
'';
151158
example = literalExpression ''
152159
{

0 commit comments

Comments
 (0)