blob: 1cc1bf2c8e7cd6a91d43b30c75d3d5f4cadfe6aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
{
outputAttrPath,
optionsAttrPath,
optionsInternal ? true,
}: {
lib,
options,
pkgs,
...
}:
with lib; let
visibleOptionDocs = filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList options);
isLiteral = value:
value
? _type
&& (value._type == "literalExpression"
|| value._type == "literalExample"
|| value._type == "literalMD");
toValue = value:
if isLiteral value
then value.text
else generators.toPretty {} value;
toText = value:
if value ? _type
then value.text
else value;
toMarkdown = option: ''
## `${option.name}`
${toText option.description}
${optionalString (option ? default) ''
**Default value**:
```nix
${toValue option.default}
```
''}
**Type**: ${option.type}${optionalString option.readOnly " (read only)"}
${optionalString (option ? example) ''
**Example**:
```nix
${toValue option.example}
```
''}
Declared in:
${concatStringsSep "\n" (map (decl: "- ${decl}") option.declarations)}
'';
# TODO: rewrite "Declared in" so that it points to GitHub repository
options-md = concatStringsSep "\n" (map toMarkdown visibleOptionDocs);
in {
config = setAttrByPath outputAttrPath {
doc-options-md = pkgs.writeText "options.md" options-md;
};
}
|