7 , baseOptionsJSON ? null
8 , warningsAreErrors ? true
13 inherit (pkgs) buildPackages runCommand docbook_xsl_ns;
27 common = import ./common.nix;
29 manpageUrls = pkgs.path + "/doc/manpage-urls.json";
31 # We need to strip references to /nix/store/* from options,
32 # including any `extraSources` if some modules came from elsewhere,
33 # or else the build will fail.
35 # E.g. if some `options` came from modules in ${pkgs.customModules}/nix,
36 # you'd need to include `extraSources = [ pkgs.customModules ]`
37 prefixesToStrip = map (p: "${toString p}/") ([ prefix ] ++ extraSources);
38 stripAnyPrefixes = flip (foldr removePrefix) prefixesToStrip;
40 optionsDoc = buildPackages.nixosOptionsDoc {
41 inherit options revision baseOptionsJSON warningsAreErrors;
42 transformOptions = opt: opt // {
43 # Clean up declaration sites to not refer to the NixOS source tree.
44 declarations = map stripAnyPrefixes opt.declarations;
48 nixos-lib = import ../../lib { };
51 eval = nixos-lib.evalTest {
52 # Avoid evaluating a NixOS config prototype.
53 config.node.type = types.deferredModule;
54 options._module.args = mkOption { internal = true; };
56 in buildPackages.nixosOptionsDoc {
57 inherit (eval) options;
59 transformOptions = opt: opt // {
60 # Clean up declaration sites to not refer to the NixOS source tree.
64 if hasPrefix (toString ../../..) (toString decl)
66 let subpath = removePrefix "/" (removePrefix (toString ../../..) (toString decl));
67 in { url = "https://github.com/NixOS/nixpkgs/blob/master/${subpath}"; name = subpath; }
71 documentType = "none";
72 variablelistId = "test-options-list";
73 optionIdPrefix = "test-opt-";
76 testDriverMachineDocstrings = pkgs.callPackage
77 ../../../nixos/lib/test-driver/nixos-test-driver-docstrings.nix {};
79 prepareManualFromMD = ''
80 cp -r --no-preserve=all $inputs/* .
82 substituteInPlace ./manual.md \
83 --replace '@NIXOS_VERSION@' "${version}"
84 substituteInPlace ./configuration/configuration.md \
87 ${escapeShellArg (concatMapStringsSep "\n" (p: "${p.value}") config.meta.doc)}
88 substituteInPlace ./nixos-options.md \
90 '@NIXOS_OPTIONS_JSON@' \
91 ${optionsDoc.optionsJSON}/${common.outputPath}/options.json
92 substituteInPlace ./development/writing-nixos-tests.section.md \
94 '@NIXOS_TEST_OPTIONS_JSON@' \
95 ${testOptionsDoc.optionsJSON}/${common.outputPath}/options.json
96 sed -e '/@PYTHON_MACHINE_METHODS@/ {' -e 'r ${testDriverMachineDocstrings}/machine-methods.md' -e 'd' -e '}' \
97 -i ./development/writing-nixos-tests.section.md
101 inherit (optionsDoc) optionsJSON optionsNix optionsDocBook;
103 # Generate the NixOS manual.
104 manualHTML = runCommand "nixos-manual-html"
105 { nativeBuildInputs = [ buildPackages.nixos-render-docs ];
106 inputs = sourceFilesBySuffices ./. [ ".md" ];
107 meta.description = "The NixOS manual in HTML format";
108 allowedReferences = ["out"];
111 # Generate the HTML manual.
112 dst=$out/${common.outputPath}
115 cp ${../../../doc/style.css} $dst/style.css
116 cp ${../../../doc/anchor.min.js} $dst/anchor.min.js
117 cp ${../../../doc/anchor-use.js} $dst/anchor-use.js
119 cp -r ${pkgs.documentation-highlighter} $dst/highlightjs
121 ${prepareManualFromMD}
123 nixos-render-docs -j $NIX_BUILD_CORES manual html \
124 --manpage-urls ${manpageUrls} \
125 --revision ${escapeShellArg revision} \
126 --generator "nixos-render-docs ${pkgs.lib.version}" \
127 --stylesheet style.css \
128 --stylesheet highlightjs/mono-blue.css \
129 --script ./highlightjs/highlight.pack.js \
130 --script ./highlightjs/loader.js \
131 --script ./anchor.min.js \
132 --script ./anchor-use.js \
134 --chunk-toc-depth 1 \
136 $dst/${common.indexPath}
138 mkdir -p $out/nix-support
139 echo "nix-build out $out" >> $out/nix-support/hydra-build-products
140 echo "doc manual $dst" >> $out/nix-support/hydra-build-products
143 # Alias for backward compatibility. TODO(@oxij): remove eventually.
146 # Index page of the NixOS manual.
147 manualHTMLIndex = "${manualHTML}/${common.outputPath}/${common.indexPath}";
149 manualEpub = runCommand "nixos-manual-epub"
150 { nativeBuildInputs = [ buildPackages.libxml2.bin buildPackages.libxslt.bin buildPackages.zip ];
152 <book xmlns="http://docbook.org/ns/docbook"
153 xmlns:xlink="http://www.w3.org/1999/xlink"
155 xml:id="book-nixos-manual">
157 <title>NixOS Manual</title>
158 <subtitle>Version ${pkgs.lib.version}</subtitle>
161 <title>Temporarily unavailable</title>
163 The NixOS manual is currently not available in EPUB format,
164 please use the <link xlink:href="https://nixos.org/nixos/manual">HTML manual</link>
168 If you've used the EPUB manual in the past and it has been useful to you, please
169 <link xlink:href="https://github.com/NixOS/nixpkgs/issues/237234">let us know</link>.
174 passAsFile = [ "doc" ];
177 # Generate the epub manual.
178 dst=$out/${common.outputPath}
181 --param chapter.autolabel 0 \
182 --nonet --xinclude --output $dst/epub/ \
183 ${docbook_xsl_ns}/xml/xsl/docbook/epub/docbook.xsl \
186 echo "application/epub+zip" > mimetype
187 manual="$dst/nixos-manual.epub"
188 zip -0Xq "$manual" mimetype
189 cd $dst/epub && zip -Xr9D "$manual" *
193 mkdir -p $out/nix-support
194 echo "doc-epub manual $manual" >> $out/nix-support/hydra-build-products
198 # Generate the `man configuration.nix` package
199 nixos-configuration-reference-manpage = runCommand "nixos-configuration-reference-manpage"
200 { nativeBuildInputs = [
201 buildPackages.installShellFiles
202 buildPackages.nixos-render-docs
204 allowedReferences = ["out"];
208 mkdir -p $out/share/man/man5
209 nixos-render-docs -j $NIX_BUILD_CORES options manpage \
210 --revision ${escapeShellArg revision} \
211 ${optionsJSON}/${common.outputPath}/options.json \
212 $out/share/man/man5/configuration.nix.5