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