1{ pkgs ? (import ./.. { }), nixpkgs ? { }}:
2let
3 inherit (pkgs) lib;
4 inherit (lib) hasPrefix removePrefix;
5
6 common = import ./common.nix;
7
8 lib-docs = import ./doc-support/lib-function-docs.nix {
9 inherit pkgs nixpkgs;
10 libsets = [
11 { name = "asserts"; description = "assertion functions"; }
12 { name = "attrsets"; description = "attribute set functions"; }
13 { name = "strings"; description = "string manipulation functions"; }
14 { name = "versions"; description = "version string functions"; }
15 { name = "trivial"; description = "miscellaneous functions"; }
16 { name = "fixedPoints"; baseName = "fixed-points"; description = "explicit recursion functions"; }
17 { name = "lists"; description = "list manipulation functions"; }
18 { name = "debug"; description = "debugging functions"; }
19 { name = "options"; description = "NixOS / nixpkgs option handling"; }
20 { name = "path"; description = "path functions"; }
21 { name = "filesystem"; description = "filesystem functions"; }
22 { name = "fileset"; description = "file set functions"; }
23 { name = "sources"; description = "source filtering functions"; }
24 { name = "cli"; description = "command-line serialization functions"; }
25 { name = "gvariant"; description = "GVariant formatted string serialization functions"; }
26 { name = "customisation"; description = "Functions to customise (derivation-related) functions, derivatons, or attribute sets"; }
27 ];
28 };
29
30 epub = pkgs.runCommand "manual.epub" {
31 nativeBuildInputs = with pkgs; [ libxslt zip ];
32
33 epub = ''
34 <book xmlns="http://docbook.org/ns/docbook"
35 xmlns:xlink="http://www.w3.org/1999/xlink"
36 version="5.0"
37 xml:id="nixpkgs-manual">
38 <info>
39 <title>Nixpkgs Manual</title>
40 <subtitle>Version ${pkgs.lib.version}</subtitle>
41 </info>
42 <chapter>
43 <title>Temporarily unavailable</title>
44 <para>
45 The Nixpkgs manual is currently not available in EPUB format,
46 please use the <link xlink:href="https://nixos.org/nixpkgs/manual">HTML manual</link>
47 instead.
48 </para>
49 <para>
50 If you've used the EPUB manual in the past and it has been useful to you, please
51 <link xlink:href="https://github.com/NixOS/nixpkgs/issues/237234">let us know</link>.
52 </para>
53 </chapter>
54 </book>
55 '';
56
57 passAsFile = [ "epub" ];
58 } ''
59 mkdir scratch
60 xsltproc \
61 --param chapter.autolabel 0 \
62 --nonet \
63 --output scratch/ \
64 ${pkgs.docbook_xsl_ns}/xml/xsl/docbook/epub/docbook.xsl \
65 $epubPath
66
67 echo "application/epub+zip" > mimetype
68 zip -0Xq "$out" mimetype
69 cd scratch && zip -Xr9D "$out" *
70 '';
71
72 # NB: This file describes the Nixpkgs manual, which happens to use module
73 # docs infra originally developed for NixOS.
74 optionsDoc = pkgs.nixosOptionsDoc {
75 inherit (pkgs.lib.evalModules {
76 modules = [ ../pkgs/top-level/config.nix ];
77 class = "nixpkgsConfig";
78 }) options;
79 documentType = "none";
80 transformOptions = opt:
81 opt // {
82 declarations =
83 map
84 (decl:
85 if hasPrefix (toString ../..) (toString decl)
86 then
87 let subpath = removePrefix "/" (removePrefix (toString ../.) (toString decl));
88 in { url = "https://github.com/NixOS/nixpkgs/blob/master/${subpath}"; name = subpath; }
89 else decl)
90 opt.declarations;
91 };
92 };
93in pkgs.stdenv.mkDerivation {
94 name = "nixpkgs-manual";
95
96 nativeBuildInputs = with pkgs; [
97 nixos-render-docs
98 ];
99
100 src = ./.;
101
102 postPatch = ''
103 ln -s ${optionsDoc.optionsJSON}/share/doc/nixos/options.json ./config-options.json
104 '';
105
106 buildPhase = ''
107 cat \
108 ./functions/library.md.in \
109 ${lib-docs}/index.md \
110 > ./functions/library.md
111 substitute ./manual.md.in ./manual.md \
112 --replace '@MANUAL_VERSION@' '${pkgs.lib.version}'
113
114 mkdir -p out/media
115
116 mkdir -p out/highlightjs
117 cp -t out/highlightjs \
118 ${pkgs.documentation-highlighter}/highlight.pack.js \
119 ${pkgs.documentation-highlighter}/LICENSE \
120 ${pkgs.documentation-highlighter}/mono-blue.css \
121 ${pkgs.documentation-highlighter}/loader.js
122
123 cp -t out ./overrides.css ./style.css
124
125 nixos-render-docs manual html \
126 --manpage-urls ./manpage-urls.json \
127 --revision ${pkgs.lib.trivial.revisionWithDefault (pkgs.rev or "master")} \
128 --stylesheet style.css \
129 --stylesheet overrides.css \
130 --stylesheet highlightjs/mono-blue.css \
131 --script ./highlightjs/highlight.pack.js \
132 --script ./highlightjs/loader.js \
133 --toc-depth 1 \
134 --section-toc-depth 1 \
135 manual.md \
136 out/index.html
137 '';
138
139 installPhase = ''
140 dest="$out/${common.outputPath}"
141 mkdir -p "$(dirname "$dest")"
142 mv out "$dest"
143 mv "$dest/index.html" "$dest/${common.indexPath}"
144
145 cp ${epub} "$dest/nixpkgs-manual.epub"
146
147 mkdir -p $out/nix-support/
148 echo "doc manual $dest ${common.indexPath}" >> $out/nix-support/hydra-build-products
149 echo "doc manual $dest nixpkgs-manual.epub" >> $out/nix-support/hydra-build-products
150 '';
151}