diff options
author | Minijackson <minijackson@riseup.net> | 2021-11-08 16:26:42 +0100 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2021-11-08 16:26:42 +0100 |
commit | c7026a993c4b837dcee39f669e1cc4123f4eb53d (patch) | |
tree | 8cfea3898b391a3c2ab8e48a7b1dd2b711456739 /doc-options-md.nix | |
download | nix-module-doc-c7026a993c4b837dcee39f669e1cc4123f4eb53d.tar.gz nix-module-doc-c7026a993c4b837dcee39f669e1cc4123f4eb53d.zip |
initial commit
Diffstat (limited to 'doc-options-md.nix')
-rw-r--r-- | doc-options-md.nix | 52 |
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 | |||
5 | with lib; | ||
6 | |||
7 | let | ||
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); | ||
47 | in | ||
48 | { | ||
49 | config = setAttrByPath outputAttrPath { | ||
50 | doc-options-md = pkgs.writeText "options.md" options-md; | ||
51 | }; | ||
52 | } | ||