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 treefmt,
18 nixosOptionsDoc,
19}:
20stdenvNoCC.mkDerivation (
21 finalAttrs:
22 let
23 inherit (finalAttrs.finalPackage.optionsDoc) optionsJSON;
24 inherit (finalAttrs.finalPackage) epub lib-docs pythonInterpreterTable;
25
26 # Make anything from lib (the module system internals) invisible
27 hide-lib =
28 opt:
29 opt
30 // {
31 visible = if lib.all (decl: decl == "lib/modules.nix") opt.declarations then false else opt.visible;
32 };
33
34 toURL =
35 decl:
36 let
37 declStr = toString decl;
38 root = toString (../..);
39 subpath = lib.removePrefix "/" (lib.removePrefix root declStr);
40 in
41 if lib.hasPrefix root declStr then
42 {
43 url = "https://github.com/NixOS/nixpkgs/blob/master/${subpath}";
44 name = "nixpkgs/${subpath}";
45 }
46 else
47 decl;
48
49 mapURLs = opt: opt // { declarations = map toURL opt.declarations; };
50
51 docs.generic.meta-maintainers = nixosOptionsDoc {
52 inherit (lib.evalModules { modules = [ ../../modules/generic/meta-maintainers.nix ]; }) options;
53 transformOptions = opt: hide-lib (mapURLs opt);
54 };
55 in
56 {
57 name = "nixpkgs-manual";
58
59 nativeBuildInputs = [ nixos-render-docs ];
60
61 src = lib.cleanSourceWith {
62 src = ../.;
63 filter =
64 path: type:
65 type == "directory"
66 || lib.hasSuffix ".md" path
67 || lib.hasSuffix ".md.in" path
68 || lib.elem path (
69 map toString [
70 ../style.css
71 ../anchor-use.js
72 ../anchor.min.js
73 ../manpage-urls.json
74 ../redirects.json
75 ]
76 );
77 };
78
79 postPatch = ''
80 ln -s ${optionsJSON}/share/doc/nixos/options.json ./config-options.json
81 ln -s ${treefmt.functionsDoc.markdown} ./packages/treefmt-functions.section.md
82 ln -s ${treefmt.optionsDoc.optionsJSON}/share/doc/nixos/options.json ./treefmt-options.json
83 ln -s ${docs.generic.meta-maintainers.optionsJSON}/share/doc/nixos/options.json ./options-modules-generic-meta-maintainers.json
84 '';
85
86 buildPhase = ''
87 runHook preBuild
88
89 substituteInPlace ./languages-frameworks/python.section.md \
90 --subst-var-by python-interpreter-table "$(<"${pythonInterpreterTable}")"
91
92 cat ./functions/library.md.in ${lib-docs}/index.md > ./functions/library.md
93
94 substitute ./manual.md.in ./manual.md \
95 --replace-fail '@MANUAL_VERSION@' '${lib.version}'
96
97 mkdir -p out/media
98
99 mkdir -p out/highlightjs
100 cp -t out/highlightjs \
101 ${documentation-highlighter}/highlight.pack.js \
102 ${documentation-highlighter}/LICENSE \
103 ${documentation-highlighter}/mono-blue.css \
104 ${documentation-highlighter}/loader.js
105
106 cp -t out ./style.css ./anchor.min.js ./anchor-use.js
107
108 nixos-render-docs manual html \
109 --manpage-urls ./manpage-urls.json \
110 --redirects ./redirects.json \
111 --revision ${nixpkgs.rev or "master"} \
112 --stylesheet style.css \
113 --stylesheet highlightjs/mono-blue.css \
114 --script ./highlightjs/highlight.pack.js \
115 --script ./highlightjs/loader.js \
116 --script ./anchor.min.js \
117 --script ./anchor-use.js \
118 --toc-depth 1 \
119 --section-toc-depth 1 \
120 manual.md \
121 out/index.html
122
123 runHook postBuild
124 '';
125
126 installPhase = ''
127 runHook preInstall
128
129 dest="$out/share/doc/nixpkgs"
130 mkdir -p "$(dirname "$dest")"
131 mv out "$dest"
132 cp "$dest/index.html" "$dest/manual.html"
133
134 cp ${roboto.src}/web/Roboto\[ital\,wdth\,wght\].ttf "$dest/Roboto.ttf"
135
136 cp ${epub} "$dest/nixpkgs-manual.epub"
137
138 mkdir -p $out/nix-support/
139 echo "doc manual $dest index.html" >> $out/nix-support/hydra-build-products
140 echo "doc manual $dest nixpkgs-manual.epub" >> $out/nix-support/hydra-build-products
141
142 runHook postInstall
143 '';
144
145 passthru = {
146 lib-docs = callPackage ./lib-function-docs.nix { inherit nixpkgs; };
147
148 epub = callPackage ./epub.nix { };
149
150 optionsDoc = callPackage ./options-doc.nix { };
151
152 pythonInterpreterTable = callPackage ./python-interpreter-table.nix { };
153
154 shell =
155 let
156 devmode' = devmode.override {
157 buildArgs = toString ../.;
158 open = "/share/doc/nixpkgs/index.html";
159 };
160 nixos-render-docs-redirects' = writeShellScriptBin "redirects" "${lib.getExe nixos-render-docs-redirects} --file ${toString ../redirects.json} $@";
161 in
162 mkShellNoCC {
163 packages = [
164 devmode'
165 nixos-render-docs-redirects'
166 markdown-code-runner
167 ];
168 };
169
170 tests = {
171 manpage-urls = callPackage ../tests/manpage-urls.nix { };
172 };
173 };
174 }
175)