at 25.11-pre 4.0 kB view raw
1# This file describes the Nixpkgs manual, which happens to use module docs infra originally 2# developed for NixOS. To build this derivation, run `nix-build -A nixpkgs-manual`. 3# 4{ 5 lib, 6 stdenvNoCC, 7 callPackage, 8 devmode, 9 mkShellNoCC, 10 documentation-highlighter, 11 nixos-render-docs, 12 nixos-render-docs-redirects, 13 writeShellScriptBin, 14 nixpkgs ? { }, 15 markdown-code-runner, 16 roboto, 17}: 18 19stdenvNoCC.mkDerivation ( 20 finalAttrs: 21 let 22 inherit (finalAttrs.finalPackage.optionsDoc) optionsJSON; 23 inherit (finalAttrs.finalPackage) epub lib-docs pythonInterpreterTable; 24 in 25 { 26 name = "nixpkgs-manual"; 27 28 nativeBuildInputs = [ nixos-render-docs ]; 29 30 src = lib.cleanSourceWith { 31 src = ../.; 32 filter = 33 path: type: 34 type == "directory" 35 || lib.hasSuffix ".md" path 36 || lib.hasSuffix ".md.in" path 37 || lib.elem path ( 38 map toString [ 39 ../style.css 40 ../anchor-use.js 41 ../anchor.min.js 42 ../manpage-urls.json 43 ../redirects.json 44 ] 45 ); 46 }; 47 48 postPatch = '' 49 ln -s ${optionsJSON}/share/doc/nixos/options.json ./config-options.json 50 ''; 51 52 buildPhase = '' 53 runHook preBuild 54 55 substituteInPlace ./languages-frameworks/python.section.md \ 56 --subst-var-by python-interpreter-table "$(<"${pythonInterpreterTable}")" 57 58 cat \ 59 ./functions/library.md.in \ 60 ${lib-docs}/index.md \ 61 > ./functions/library.md 62 substitute ./manual.md.in ./manual.md \ 63 --replace-fail '@MANUAL_VERSION@' '${lib.version}' 64 65 mkdir -p out/media 66 67 mkdir -p out/highlightjs 68 cp -t out/highlightjs \ 69 ${documentation-highlighter}/highlight.pack.js \ 70 ${documentation-highlighter}/LICENSE \ 71 ${documentation-highlighter}/mono-blue.css \ 72 ${documentation-highlighter}/loader.js 73 74 cp -t out ./style.css ./anchor.min.js ./anchor-use.js 75 76 nixos-render-docs manual html \ 77 --manpage-urls ./manpage-urls.json \ 78 --redirects ./redirects.json \ 79 --revision ${nixpkgs.rev or "master"} \ 80 --stylesheet style.css \ 81 --stylesheet highlightjs/mono-blue.css \ 82 --script ./highlightjs/highlight.pack.js \ 83 --script ./highlightjs/loader.js \ 84 --script ./anchor.min.js \ 85 --script ./anchor-use.js \ 86 --toc-depth 1 \ 87 --section-toc-depth 1 \ 88 manual.md \ 89 out/index.html 90 91 runHook postBuild 92 ''; 93 94 installPhase = '' 95 runHook preInstall 96 97 dest="$out/share/doc/nixpkgs" 98 mkdir -p "$(dirname "$dest")" 99 mv out "$dest" 100 mv "$dest/index.html" "$dest/manual.html" 101 102 cp ${roboto.src}/web/Roboto\[ital\,wdth\,wght\].ttf "$dest/Roboto.ttf" 103 104 cp ${epub} "$dest/nixpkgs-manual.epub" 105 106 mkdir -p $out/nix-support/ 107 echo "doc manual $dest manual.html" >> $out/nix-support/hydra-build-products 108 echo "doc manual $dest nixpkgs-manual.epub" >> $out/nix-support/hydra-build-products 109 110 runHook postInstall 111 ''; 112 113 passthru = { 114 lib-docs = callPackage ./lib-function-docs.nix { inherit nixpkgs; }; 115 116 epub = callPackage ./epub.nix { }; 117 118 optionsDoc = callPackage ./options-doc.nix { }; 119 120 pythonInterpreterTable = callPackage ./python-interpreter-table.nix { }; 121 122 shell = 123 let 124 devmode' = devmode.override { 125 buildArgs = toString ../.; 126 open = "/share/doc/nixpkgs/manual.html"; 127 }; 128 nixos-render-docs-redirects' = writeShellScriptBin "redirects" "${lib.getExe nixos-render-docs-redirects} --file ${toString ../redirects.json} $@"; 129 in 130 mkShellNoCC { 131 packages = [ 132 devmode' 133 nixos-render-docs-redirects' 134 markdown-code-runner 135 ]; 136 }; 137 138 tests = { 139 manpage-urls = callPackage ../tests/manpage-urls.nix { }; 140 check-nix-code-blocks = callPackage ../tests/check-nix-code-blocks.nix { }; 141 }; 142 }; 143 } 144)