Skip to content

Commit 269b9c3

Browse files
committed
refactor: use nixpkgs from flake
1 parent 4c3afca commit 269b9c3

1 file changed

Lines changed: 27 additions & 24 deletions

File tree

modules/modules-docs.nix

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,61 +117,64 @@ let
117117
# TODO: display values like TOML instead.
118118
toMarkdown = optionsDocs:
119119
let
120+
optionsDocsPartitioned = partition (opt: head opt.loc != "_module") optionsDocs;
121+
120122
# TODO: handle opt.relatedPackages. What is it for?
121123
optToMd = opt:
122124
let heading = (lib.showOption (filter isString opt.loc)) + (concatStrings (filter (x: !(isString x)) opt.loc)); in
123125
''
124-
## `${heading}`
126+
### `${heading}`
125127
126128
''
127129
+ (lib.optionalString opt.internal "\n**internal**\n")
128-
+ opt.description + "\n"
129-
+ (lib.optionalString (opt ? default && opt.default != null) ''
130+
+ opt.description
131+
+ ''
130132
133+
**Type**:
134+
135+
```console
136+
${opt.type}
137+
```
138+
''
139+
+ (lib.optionalString (opt ? default && opt.default != null) ''
140+
131141
**Default value**:
142+
132143
```nix
133-
${
134-
# When defaultText is set on the module, we only get back a
135-
# string here and defaultText has disappeared. Re-hydrate that
136-
# knowledge by looking at the type.
137-
if builtins.isString opt.default && !(lib.hasPrefix "string" opt.type) then
138-
# If it's a defaultText, assume it's already formatted as nix
139-
# code.
140-
opt.default
141-
else
142-
builtins.toJSON opt.default
143-
}
144+
${removeSuffix "\n" opt.default.text}
144145
```
145-
146146
'')
147-
+ ''
148-
149-
**Type**: ${opt.type}
150-
''
151147
+ (lib.optionalString (opt ? example) ''
152148
153149
**Example value**:
150+
154151
```nix
155-
${builtins.toJSON opt.example}
152+
${removeSuffix "\n" opt.example.text}
156153
```
157-
158154
'')
159155
+ ''
160156
161-
Declared in:
157+
**Declared in**:
158+
162159
''
163160
+ (
164161
lib.concatStringsSep
165162
"\n"
166163
(map
167-
(decl: "* [${decl.path}](${decl.url})")
164+
(decl: "- [${decl.path}](${decl.url})")
168165
opt.declarations
169166
)
170167
)
171168
+ "\n"
172169
;
170+
doc = [
171+
"## Options\n"
172+
(concatStringsSep "\n" (map optToMd optionsDocsPartitioned.right))
173+
"## Extra options\n"
174+
(concatStringsSep "\n" (map optToMd optionsDocsPartitioned.wrong))
175+
];
173176
in
174-
concatStringsSep "\n" (map optToMd optionsDocs);
177+
concatStringsSep "\n" doc;
175178
in
176179
{
177180
options.modules-docs = {

0 commit comments

Comments
 (0)