1{ pkgs, options, version, revision }:
2
3with pkgs;
4with pkgs.lib;
5
6let
7
8 # Remove invisible and internal options.
9 optionsList = filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList options);
10
11 # Replace functions by the string <function>
12 substFunction = x:
13 if builtins.isAttrs x then mapAttrs (name: substFunction) x
14 else if builtins.isList x then map substFunction x
15 else if builtins.isFunction x then "<function>"
16 else x;
17
18 # Clean up declaration sites to not refer to the NixOS source tree.
19 optionsList' = flip map optionsList (opt: opt // {
20 declarations = map (fn: stripPrefix fn) opt.declarations;
21 }
22 // optionalAttrs (opt ? example) { example = substFunction opt.example; }
23 // optionalAttrs (opt ? default) { default = substFunction opt.default; }
24 // optionalAttrs (opt ? type) { type = substFunction opt.type; });
25
26 prefix = toString ../../..;
27
28 stripPrefix = fn:
29 if substring 0 (stringLength prefix) fn == prefix then
30 substring (stringLength prefix + 1) 1000 fn
31 else
32 fn;
33
34 # Convert the list of options into an XML file. The builtin
35 # unsafeDiscardStringContext is used to prevent the realisation of
36 # the store paths which are used in options definitions.
37 optionsXML = builtins.toFile "options.xml" (builtins.unsafeDiscardStringContext (builtins.toXML optionsList'));
38
39 optionsDocBook = runCommand "options-db.xml" {} ''
40 optionsXML=${optionsXML}
41 if grep /nixpkgs/nixos/modules $optionsXML; then
42 echo "The manual appears to depend on the location of Nixpkgs, which is bad"
43 echo "since this prevents sharing via the NixOS channel. This is typically"
44 echo "caused by an option default that refers to a relative path (see above"
45 echo "for hints about the offending path)."
46 exit 1
47 fi
48 ${libxslt}/bin/xsltproc \
49 --stringparam revision '${revision}' \
50 -o $out ${./options-to-docbook.xsl} $optionsXML
51 '';
52
53 sources = sourceFilesBySuffices ./. [".xml"];
54
55 copySources =
56 ''
57 cp -prd $sources/* . # */
58 chmod -R u+w .
59 cp ${../../modules/services/databases/postgresql.xml} configuration/postgresql.xml
60 ln -s ${optionsDocBook} options-db.xml
61 echo "${version}" > version
62 '';
63
64 toc = builtins.toFile "toc.xml"
65 ''
66 <toc role="chunk-toc">
67 <d:tocentry xmlns:d="http://docbook.org/ns/docbook" linkend="book-nixos-manual"><?dbhtml filename="index.html"?>
68 <d:tocentry linkend="ch-options"><?dbhtml filename="options.html"?></d:tocentry>
69 <d:tocentry linkend="ch-release-notes"><?dbhtml filename="release-notes.html"?></d:tocentry>
70 </d:tocentry>
71 </toc>
72 '';
73
74in rec {
75
76 # The NixOS options in JSON format.
77 optionsJSON = stdenv.mkDerivation {
78 name = "options-json";
79
80 buildCommand = ''
81 # Export list of options in different format.
82 dst=$out/share/doc/nixos
83 mkdir -p $dst
84
85 cp ${builtins.toFile "options.json" (builtins.unsafeDiscardStringContext (builtins.toJSON
86 (listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList'))))
87 } $dst/options.json
88
89 mkdir -p $out/nix-support
90 echo "file json $dst/options.json" >> $out/nix-support/hydra-build-products
91 ''; # */
92
93 meta.description = "List of NixOS options in JSON format";
94 };
95
96 # Generate the NixOS manual.
97 manual = stdenv.mkDerivation {
98 name = "nixos-manual";
99
100 inherit sources;
101
102 buildInputs = [ libxml2 libxslt ];
103
104 buildCommand = ''
105 ${copySources}
106
107 # Check the validity of the manual sources.
108 xmllint --noout --nonet --xinclude --noxincludenode \
109 --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \
110 manual.xml
111
112 # Generate the HTML manual.
113 dst=$out/share/doc/nixos
114 mkdir -p $dst
115 xsltproc \
116 --param section.autolabel 1 \
117 --param section.label.includes.component.label 1 \
118 --stringparam html.stylesheet style.css \
119 --param xref.with.number.and.title 1 \
120 --param toc.section.depth 3 \
121 --stringparam admon.style "" \
122 --stringparam callout.graphics.extension .gif \
123 --param chunk.section.depth 0 \
124 --param chunk.first.sections 1 \
125 --param use.id.as.filename 1 \
126 --stringparam generate.toc "book toc appendix toc" \
127 --stringparam chunk.toc ${toc} \
128 --nonet --xinclude --output $dst/ \
129 ${docbook5_xsl}/xml/xsl/docbook/xhtml/chunktoc.xsl ./manual.xml
130
131 mkdir -p $dst/images/callouts
132 cp ${docbook5_xsl}/xml/xsl/docbook/images/callouts/*.gif $dst/images/callouts/
133
134 cp ${./style.css} $dst/style.css
135
136 mkdir -p $out/nix-support
137 echo "nix-build out $out" >> $out/nix-support/hydra-build-products
138 echo "doc manual $dst" >> $out/nix-support/hydra-build-products
139 ''; # */
140
141 meta.description = "The NixOS manual in HTML format";
142 };
143
144 manualPDF = stdenv.mkDerivation {
145 name = "nixos-manual-pdf";
146
147 inherit sources;
148
149 buildInputs = [ libxml2 libxslt dblatex tetex ];
150
151 buildCommand = ''
152 # TeX needs a writable font cache.
153 export VARTEXFONTS=$TMPDIR/texfonts
154
155 ${copySources}
156
157 dst=$out/share/doc/nixos
158 mkdir -p $dst
159 xmllint --xinclude manual.xml | dblatex -o $dst/manual.pdf - \
160 -P doc.collab.show=0 \
161 -P latex.output.revhistory=0
162
163 mkdir -p $out/nix-support
164 echo "doc-pdf manual $dst/manual.pdf" >> $out/nix-support/hydra-build-products
165 ''; # */
166 };
167
168 # Generate the NixOS manpages.
169 manpages = stdenv.mkDerivation {
170 name = "nixos-manpages";
171
172 inherit sources;
173
174 buildInputs = [ libxml2 libxslt ];
175
176 buildCommand = ''
177 ${copySources}
178
179 # Check the validity of the manual sources.
180 xmllint --noout --nonet --xinclude --noxincludenode \
181 --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \
182 ./man-pages.xml
183
184 # Generate manpages.
185 mkdir -p $out/share/man
186 xsltproc --nonet --xinclude \
187 --param man.output.in.separate.dir 1 \
188 --param man.output.base.dir "'$out/share/man/'" \
189 --param man.endnotes.are.numbered 0 \
190 ${docbook5_xsl}/xml/xsl/docbook/manpages/docbook.xsl \
191 ./man-pages.xml
192 '';
193 };
194
195}