on iko/ghcjs-patch-master help sign in
module: generate using markdown template (#693)

The main motivation is that each option now is a heading and such a link!

commit59cf05606e7efbbc4741ae28fd8cc610cec94eb8 authorDomen Kožar <domen@dev.si> dateTue 16 Jun 2020, 11:13 (6 years ago) parent5a8b3cb
3 files changed+45−24
docs/reference/modules-preamble.md−10 scripts/options-doc.nix+44−12 scripts/update-docs.nix+1−2
docs/reference/modules-preamble.mddeleted−10
@@ -1,10 +0,0 @@
1−Haskell.nix modules options for packages and components.
2−
3−!!! note "Undocumented"
4− Please help write me.
5−
6− This documentation is generated from Nix sources in the
7− [`modules`](https://github.com/input-output-hk/haskell.nix/tree/master/modules)
8− subdirectory.
9−
10− The Markdown generation script could also be improved.
scripts/options-doc.nix+44−12
@@ -15,15 +15,47 @@ let
1515 # Apply the package set function to get NixOS options.
1616 inherit (import ../package-set.nix { hackage = null; inherit pkgs pkg-def; }) options;
1717
18− # Use code from the NixOS manual to generate Docbook XML options list.
19− manual = import (pkgs.path + /nixos/doc/manual) {
20− inherit pkgs options;
21− config.meta.doc = [];
22− version = "testing";
23− revision = "testing";
24− };
25−in
26− # Convert docbook options list to markdown
27− pkgs.runCommand "options.md" {} ''
28− ${pkgs.buildPackages.pandoc}/bin/pandoc -s -f docbook -t markdown_strict ${manual.generatedSources}/options-db.xml -o $out
29− ''
18+ optionsNix = (pkgs.nixosOptionsDoc { inherit options; }).optionsNix;
19+
20+ optionsMarkdown = lib.concatStringsSep "\n" (lib.mapAttrsToList singleMarkdown optionsNix);
21+
22+ singleMarkdown = name: value: ''
23+ ## ${name}
24+
25+ ${value.description}
26+
27+ **Type**: ${value.type}
28+
29+ ${ if lib.hasAttr "default" value
30+ then ''
31+ **Default**: ${builtins.toJSON value.default}
32+ ''
33+ else "**No Default**"
34+ }
35+ ${ if value.readOnly
36+ then "**Read Only**"
37+ else ""
38+ }
39+ ${ if lib.hasAttr "example" value
40+ then ''
41+ **Example**:
42+
43+ ${builtins.toJSON value.example}
44+ ''
45+ else "**No Example**"
46+ }
47+
48+ '';
49+
50+in builtins.toFile "options.md" ''
51+Haskell.nix modules options for packages and components.
52+
53+!!! note "Generated"
54+ This documentation is generated from Nix sources in the
55+ [`modules`](https://github.com/input-output-hk/haskell.nix/tree/master/modules)
56+ subdirectory using `scripts/update-docs.nix`
57+
58+# Configuration Options
59+
60+${optionsMarkdown}
61+''
scripts/update-docs.nix+1−2
@@ -21,8 +21,7 @@ in
2121 cd $(git rev-parse --show-toplevel)
2222
2323 echo "Preprocessing..."
24− cat docs/reference/modules-preamble.md ${generatedOptions} |
25− sed -e "s,$PWD/\?,," > docs/reference/modules.md
24+ cat ${generatedOptions} > docs/reference/modules.md
2625
2726 echo "Building..."
2827 rm -rf site