at 25.11-pre 7.8 kB view raw
1{ 2 pkgs, 3 options, 4 config, 5 version, 6 revision, 7 extraSources ? [ ], 8 baseOptionsJSON ? null, 9 warningsAreErrors ? true, 10 prefix ? ../../.., 11}: 12 13let 14 inherit (pkgs) buildPackages runCommand docbook_xsl_ns; 15 16 inherit (pkgs.lib) 17 hasPrefix 18 removePrefix 19 flip 20 foldr 21 types 22 mkOption 23 escapeShellArg 24 concatMapStringsSep 25 sourceFilesBySuffices 26 ; 27 28 common = import ./common.nix; 29 30 manpageUrls = pkgs.path + "/doc/manpage-urls.json"; 31 32 # We need to strip references to /nix/store/* from options, 33 # including any `extraSources` if some modules came from elsewhere, 34 # or else the build will fail. 35 # 36 # E.g. if some `options` came from modules in ${pkgs.customModules}/nix, 37 # you'd need to include `extraSources = [ pkgs.customModules ]` 38 prefixesToStrip = map (p: "${toString p}/") ([ prefix ] ++ extraSources); 39 stripAnyPrefixes = flip (foldr removePrefix) prefixesToStrip; 40 41 optionsDoc = buildPackages.nixosOptionsDoc { 42 inherit 43 options 44 revision 45 baseOptionsJSON 46 warningsAreErrors 47 ; 48 transformOptions = 49 opt: 50 opt 51 // { 52 # Clean up declaration sites to not refer to the NixOS source tree. 53 declarations = map stripAnyPrefixes opt.declarations; 54 }; 55 }; 56 57 nixos-lib = import ../../lib { }; 58 59 testOptionsDoc = 60 let 61 eval = nixos-lib.evalTest { 62 # Avoid evaluating a NixOS config prototype. 63 config.node.type = types.deferredModule; 64 options._module.args = mkOption { internal = true; }; 65 }; 66 in 67 buildPackages.nixosOptionsDoc { 68 inherit (eval) options; 69 inherit revision; 70 transformOptions = 71 opt: 72 opt 73 // { 74 # Clean up declaration sites to not refer to the NixOS source tree. 75 declarations = map ( 76 decl: 77 if hasPrefix (toString ../../..) (toString decl) then 78 let 79 subpath = removePrefix "/" (removePrefix (toString ../../..) (toString decl)); 80 in 81 { 82 url = "https://github.com/NixOS/nixpkgs/blob/master/${subpath}"; 83 name = subpath; 84 } 85 else 86 decl 87 ) opt.declarations; 88 }; 89 documentType = "none"; 90 variablelistId = "test-options-list"; 91 optionIdPrefix = "test-opt-"; 92 }; 93 94 testDriverMachineDocstrings = 95 pkgs.callPackage ../../../nixos/lib/test-driver/nixos-test-driver-docstrings.nix 96 { }; 97 98 prepareManualFromMD = '' 99 cp -r --no-preserve=all $inputs/* . 100 101 cp -r ${../../../doc/release-notes} ./release-notes-nixpkgs 102 103 substituteInPlace ./manual.md \ 104 --replace-fail '@NIXOS_VERSION@' "${version}" 105 substituteInPlace ./configuration/configuration.md \ 106 --replace-fail \ 107 '@MODULE_CHAPTERS@' \ 108 ${escapeShellArg (concatMapStringsSep "\n" (p: "${p.value}") config.meta.doc)} 109 substituteInPlace ./nixos-options.md \ 110 --replace-fail \ 111 '@NIXOS_OPTIONS_JSON@' \ 112 ${optionsDoc.optionsJSON}/${common.outputPath}/options.json 113 substituteInPlace ./development/writing-nixos-tests.section.md \ 114 --replace-fail \ 115 '@NIXOS_TEST_OPTIONS_JSON@' \ 116 ${testOptionsDoc.optionsJSON}/${common.outputPath}/options.json 117 sed -e '/@PYTHON_MACHINE_METHODS@/ {' -e 'r ${testDriverMachineDocstrings}/machine-methods.md' -e 'd' -e '}' \ 118 -i ./development/writing-nixos-tests.section.md 119 ''; 120 121in 122rec { 123 inherit (optionsDoc) optionsJSON optionsNix optionsDocBook; 124 125 # Generate the NixOS manual. 126 manualHTML = 127 runCommand "nixos-manual-html" 128 { 129 nativeBuildInputs = [ buildPackages.nixos-render-docs ]; 130 inputs = sourceFilesBySuffices ./. [ ".md" ]; 131 meta.description = "The NixOS manual in HTML format"; 132 allowedReferences = [ "out" ]; 133 } 134 '' 135 # Generate the HTML manual. 136 dst=$out/${common.outputPath} 137 mkdir -p $dst 138 139 cp ${../../../doc/style.css} $dst/style.css 140 cp ${../../../doc/anchor.min.js} $dst/anchor.min.js 141 cp ${../../../doc/anchor-use.js} $dst/anchor-use.js 142 143 cp -r ${pkgs.documentation-highlighter} $dst/highlightjs 144 145 ${prepareManualFromMD} 146 147 nixos-render-docs -j $NIX_BUILD_CORES manual html \ 148 --manpage-urls ${manpageUrls} \ 149 --redirects ${./redirects.json} \ 150 --revision ${escapeShellArg revision} \ 151 --generator "nixos-render-docs ${pkgs.lib.version}" \ 152 --stylesheet style.css \ 153 --stylesheet highlightjs/mono-blue.css \ 154 --script ./highlightjs/highlight.pack.js \ 155 --script ./highlightjs/loader.js \ 156 --script ./anchor.min.js \ 157 --script ./anchor-use.js \ 158 --toc-depth 1 \ 159 --chunk-toc-depth 1 \ 160 ./manual.md \ 161 $dst/${common.indexPath} 162 163 cp ${pkgs.roboto.src}/web/Roboto\[ital\,wdth\,wght\].ttf "$dst/Roboto.ttf" 164 165 mkdir -p $out/nix-support 166 echo "nix-build out $out" >> $out/nix-support/hydra-build-products 167 echo "doc manual $dst" >> $out/nix-support/hydra-build-products 168 ''; # */ 169 170 # Alias for backward compatibility. TODO(@oxij): remove eventually. 171 manual = manualHTML; 172 173 # Index page of the NixOS manual. 174 manualHTMLIndex = "${manualHTML}/${common.outputPath}/${common.indexPath}"; 175 176 manualEpub = 177 runCommand "nixos-manual-epub" 178 { 179 nativeBuildInputs = [ 180 buildPackages.libxml2.bin 181 buildPackages.libxslt.bin 182 buildPackages.zip 183 ]; 184 doc = '' 185 <book xmlns="http://docbook.org/ns/docbook" 186 xmlns:xlink="http://www.w3.org/1999/xlink" 187 version="5.0" 188 xml:id="book-nixos-manual"> 189 <info> 190 <title>NixOS Manual</title> 191 <subtitle>Version ${pkgs.lib.version}</subtitle> 192 </info> 193 <chapter> 194 <title>Temporarily unavailable</title> 195 <para> 196 The NixOS manual is currently not available in EPUB format, 197 please use the <link xlink:href="https://nixos.org/nixos/manual">HTML manual</link> 198 instead. 199 </para> 200 <para> 201 If you've used the EPUB manual in the past and it has been useful to you, please 202 <link xlink:href="https://github.com/NixOS/nixpkgs/issues/237234">let us know</link>. 203 </para> 204 </chapter> 205 </book> 206 ''; 207 passAsFile = [ "doc" ]; 208 } 209 '' 210 # Generate the epub manual. 211 dst=$out/${common.outputPath} 212 213 xsltproc \ 214 --param chapter.autolabel 0 \ 215 --nonet --xinclude --output $dst/epub/ \ 216 ${docbook_xsl_ns}/xml/xsl/docbook/epub/docbook.xsl \ 217 $docPath 218 219 echo "application/epub+zip" > mimetype 220 manual="$dst/nixos-manual.epub" 221 zip -0Xq "$manual" mimetype 222 cd $dst/epub && zip -Xr9D "$manual" * 223 224 rm -rf $dst/epub 225 226 mkdir -p $out/nix-support 227 echo "doc-epub manual $manual" >> $out/nix-support/hydra-build-products 228 ''; 229 230 # Generate the `man configuration.nix` package 231 nixos-configuration-reference-manpage = 232 runCommand "nixos-configuration-reference-manpage" 233 { 234 nativeBuildInputs = [ 235 buildPackages.installShellFiles 236 buildPackages.nixos-render-docs 237 ]; 238 allowedReferences = [ "out" ]; 239 } 240 '' 241 # Generate manpages. 242 mkdir -p $out/share/man/man5 243 nixos-render-docs -j $NIX_BUILD_CORES options manpage \ 244 --revision ${escapeShellArg revision} \ 245 ${optionsJSON}/${common.outputPath}/options.json \ 246 $out/share/man/man5/configuration.nix.5 247 ''; 248 249}