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