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.nix52
1 files changed, 52 insertions, 0 deletions
diff --git a/doc-options-md.nix b/doc-options-md.nix
new file mode 100644
index 0000000..ea21746
--- /dev/null
+++ b/doc-options-md.nix
@@ -0,0 +1,52 @@
1{ outputAttrPath, optionsAttrPath, optionsInternal ? true, }:
2
3{ lib, options, pkgs, ... }:
4
5with lib;
6
7let
8 visibleOptionDocs = filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList options);
9
10 toValue = value:
11 if value ? _type && value._type == "literalExpression" then value.text
12 else generators.toPretty { } value;
13
14 toMarkdown = option:
15 ''
16 ## `${option.name}`
17
18 ${option.description}
19
20 ${optionalString (option ? default) ''
21 **Default value**:
22
23 ```nix
24 ${toValue option.default}
25 ```
26 ''}
27
28 **Type**: ${option.type}${optionalString option.readOnly " (read only)"}
29
30 ${optionalString (option ? example) ''
31 **Example**:
32
33 ```nix
34 ${toValue option.example}
35 ```
36 ''}
37
38 Declared in:
39
40 ${concatStringsSep "\n" (map (decl: "- ${decl}") option.declarations)}
41
42 '';
43
44 # TODO: rewrite "Declared in" so that it points to GitHub repository
45
46 options-md = concatStringsSep "\n" (map toMarkdown visibleOptionDocs);
47in
48{
49 config = setAttrByPath outputAttrPath {
50 doc-options-md = pkgs.writeText "options.md" options-md;
51 };
52}