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