|
1 | 1 | { |
2 | 2 | lib, |
3 | | - # build dependencies |
| 3 | + # Build Dependencies |
4 | 4 | runCommandLocal, |
5 | 5 | pandoc, |
6 | 6 | nixosOptionsDoc, |
7 | 7 | ndg-stylesheet, |
8 | | - # options |
| 8 | + # Options |
| 9 | + pandocCmd ? "pandoc", |
9 | 10 | genJsonDocs ? true, |
10 | 11 | checkModules ? false, |
11 | 12 | rawModules ? [ |
|
34 | 35 | templatePath ? ./assets/default-template.html, |
35 | 36 | styleSheetPath ? ./assets/default-styles.scss, |
36 | 37 | codeThemePath ? ./assets/default-syntax.theme, |
| 38 | + filters ? [], |
37 | 39 | optionsDocArgs ? {}, |
38 | 40 | sandboxing ? true, |
39 | 41 | embedResources ? false, |
40 | 42 | generateLinkAnchors ? true, |
41 | | -} @ args: |
42 | | -assert args ? specialArgs -> args ? rawModules; |
43 | | -assert args ? evaluatedModules -> !(args ? rawModules); let |
44 | | - inherit (lib.strings) optionalString; |
| 43 | + outPath ? "share/doc", |
| 44 | +} @ args: let |
| 45 | + inherit (builtins) isString; |
| 46 | + inherit (lib.asserts) assertMsg; |
| 47 | +in |
| 48 | + # TODO explain this one |
| 49 | + assert args ? specialArgs -> args ? rawModules; |
| 50 | + assert assertMsg (args ? evaluatedModules -> !(args ? rawModules)) "evaluatedModules and rawModules are mutually exclusive"; |
| 51 | + assert assertMsg (isString outPath) "outPath must be a string"; |
| 52 | + # TODO assert that outPath doesn't escape $out |
| 53 | + let |
| 54 | + inherit (lib.strings) optionalString concatStringsSep; |
| 55 | + inherit (lib.lists) optionals; |
45 | 56 |
|
46 | | - configMD = |
47 | | - (nixosOptionsDoc ( |
48 | | - (removeAttrs optionsDocArgs ["options"]) |
49 | | - // {inherit (evaluatedModules) options;} |
50 | | - )) |
51 | | - .optionsCommonMark; |
| 57 | + configMD = |
| 58 | + (nixosOptionsDoc ( |
| 59 | + (removeAttrs optionsDocArgs ["options"]) |
| 60 | + // {inherit (evaluatedModules) options;} |
| 61 | + )) |
| 62 | + .optionsCommonMark; |
52 | 63 |
|
53 | | - configJSON = |
54 | | - (nixosOptionsDoc ( |
55 | | - (removeAttrs optionsDocArgs ["options"]) |
56 | | - // {inherit (evaluatedModules) options;} |
57 | | - )) |
58 | | - .optionsJSON; |
59 | | -in |
60 | | - runCommandLocal "generate-option-docs.html" {nativeBuildInputs = [pandoc];} ( |
61 | | - '' |
62 | | - mkdir -p $out/share/doc |
| 64 | + configJSON = |
| 65 | + (nixosOptionsDoc ( |
| 66 | + (removeAttrs optionsDocArgs ["options"]) |
| 67 | + // {inherit (evaluatedModules) options;} |
| 68 | + )) |
| 69 | + .optionsJSON; |
| 70 | + |
| 71 | + pandocArgs = { |
| 72 | + luaFilters = filters ++ optionals generateLinkAnchors [./assets/filters/anchor.lua]; |
| 73 | + finalOutPath = "$out/${outPath}"; |
| 74 | + }; |
| 75 | + in |
| 76 | + runCommandLocal "generate-option-docs.html" {nativeBuildInputs = [pandoc];} ( |
| 77 | + '' |
| 78 | + mkdir -p ${pandocArgs.finalOutPath} |
63 | 79 |
|
64 | | - ${optionalString genJsonDocs '' |
65 | | - cp -vf ${configJSON}/share/doc/nixos/options.json $out/share/doc/options.json |
66 | | - ''} |
| 80 | + ${optionalString genJsonDocs '' |
| 81 | + cp -vf ${configJSON}/share/doc/nixos/options.json $out/share/doc/options.json |
| 82 | + ''} |
67 | 83 |
|
68 | | - # Convert to Pandoc markdown instead of using commonmark directly |
69 | | - # as the former automatically generates heading IDs and TOC links. |
70 | | - pandoc \ |
71 | | - --from commonmark \ |
72 | | - --to markdown \ |
73 | | - ${configMD} | |
| 84 | + # Convert to Pandoc markdown instead of using commonmark directly |
| 85 | + # as the former automatically generates heading IDs and TOC links. |
| 86 | + ${pandocCmd} \ |
| 87 | + --from commonmark \ |
| 88 | + --to markdown \ |
| 89 | + ${configMD} | |
74 | 90 |
|
75 | 91 |
|
76 | | - # Convert Pandoc markdown to HTML using our own template and css files |
77 | | - # where available. --sandbox is passed for extra security by default |
78 | | - # with an optional override to disable it. |
79 | | - pandoc \ |
80 | | - --from markdown \ |
81 | | - --to html \ |
82 | | - --metadata title="${title}" \ |
83 | | - --toc \ |
84 | | - --standalone \ |
85 | | - '' |
86 | | - + optionalString generateLinkAnchors ''--lua-filter=${./assets/filters/anchor.lua} \'' |
87 | | - + optionalString embedResources ''--self-contained \'' |
88 | | - + optionalString sandboxing ''--sandbox \'' |
89 | | - + optionalString (templatePath != null) ''--template ${templatePath} \'' |
90 | | - + optionalString (styleSheetPath != null) ''--css ${ndg-stylesheet.override {inherit styleSheetPath;}} \'' |
91 | | - + optionalString (codeThemePath != null) ''--highlight-style ${codeThemePath} \'' |
92 | | - + "-o $out/share/doc/index.html" |
93 | | - ) |
| 92 | + # Convert Pandoc markdown to HTML using our own template and css files |
| 93 | + # where available. --sandbox is passed for extra security by default |
| 94 | + # with an optional override to disable it. |
| 95 | + ${pandocCmd} \ |
| 96 | + --from markdown \ |
| 97 | + --to html \ |
| 98 | + --metadata title="${title}" \ |
| 99 | + --toc \ |
| 100 | + --standalone \ |
| 101 | + '' |
| 102 | + + optionalString (pandocArgs.luaFilters != []) ''${concatStringsSep " " (map (f: "--lua-filter=" + f) pandocArgs.luaFilters)} \'' |
| 103 | + + optionalString embedResources ''--embed-resources --standalone \'' |
| 104 | + + optionalString sandboxing ''--sandbox \'' |
| 105 | + + optionalString (templatePath != null) ''--template ${templatePath} \'' |
| 106 | + + optionalString (styleSheetPath != null) ''--css ${ndg-stylesheet.override {inherit styleSheetPath;}} \'' |
| 107 | + + optionalString (codeThemePath != null) ''--highlight-style ${codeThemePath} \'' |
| 108 | + + "-o ${pandocArgs.finalOutPath}/index.html" |
| 109 | + ) |
0 commit comments