at 16.09-beta 8.7 kB view raw
1{ pkgs, options, config, version, revision, extraSources ? [] }: 2 3with pkgs; 4 5let 6 lib = pkgs.lib; 7 8 # Remove invisible and internal options. 9 optionsList = lib.filter (opt: opt.visible && !opt.internal) (lib.optionAttrSetToDocList options); 10 11 # Replace functions by the string <function> 12 substFunction = x: 13 if builtins.isAttrs x then lib.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' = lib.flip map optionsList (opt: opt // { 20 declarations = map stripAnyPrefixes opt.declarations; 21 } 22 // lib.optionalAttrs (opt ? example) { example = substFunction opt.example; } 23 // lib.optionalAttrs (opt ? default) { default = substFunction opt.default; } 24 // lib.optionalAttrs (opt ? type) { type = substFunction opt.type; }); 25 26 # We need to strip references to /nix/store/* from options, 27 # including any `extraSources` if some modules came from elsewhere, 28 # or else the build will fail. 29 # 30 # E.g. if some `options` came from modules in ${pkgs.customModules}/nix, 31 # you'd need to include `extraSources = [ pkgs.customModules ]` 32 prefixesToStrip = map (p: "${toString p}/") ([ ../../.. ] ++ extraSources); 33 stripAnyPrefixes = lib.flip (lib.fold lib.removePrefix) prefixesToStrip; 34 35 # Convert the list of options into an XML file. 36 optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList'); 37 38 optionsDocBook = runCommand "options-db.xml" {} '' 39 optionsXML=${optionsXML} 40 if grep /nixpkgs/nixos/modules $optionsXML; then 41 echo "The manual appears to depend on the location of Nixpkgs, which is bad" 42 echo "since this prevents sharing via the NixOS channel. This is typically" 43 echo "caused by an option default that refers to a relative path (see above" 44 echo "for hints about the offending path)." 45 exit 1 46 fi 47 ${libxslt.bin}/bin/xsltproc \ 48 --stringparam revision '${revision}' \ 49 -o $out ${./options-to-docbook.xsl} $optionsXML 50 ''; 51 52 sources = lib.sourceFilesBySuffices ./. [".xml"]; 53 54 modulesDoc = builtins.toFile "modules.xml" '' 55 <section xmlns:xi="http://www.w3.org/2001/XInclude" id="modules"> 56 ${(lib.concatMapStrings (path: '' 57 <xi:include href="${path}" /> 58 '') (lib.catAttrs "value" config.meta.doc))} 59 </section> 60 ''; 61 62 copySources = 63 '' 64 cp -prd $sources/* . # */ 65 chmod -R u+w . 66 ln -s ${modulesDoc} configuration/modules.xml 67 ln -s ${optionsDocBook} options-db.xml 68 echo "${version}" > version 69 ''; 70 71 toc = builtins.toFile "toc.xml" 72 '' 73 <toc role="chunk-toc"> 74 <d:tocentry xmlns:d="http://docbook.org/ns/docbook" linkend="book-nixos-manual"><?dbhtml filename="index.html"?> 75 <d:tocentry linkend="ch-options"><?dbhtml filename="options.html"?></d:tocentry> 76 <d:tocentry linkend="ch-release-notes"><?dbhtml filename="release-notes.html"?></d:tocentry> 77 </d:tocentry> 78 </toc> 79 ''; 80 81 manualXsltprocOptions = toString [ 82 "--param section.autolabel 1" 83 "--param section.label.includes.component.label 1" 84 "--stringparam html.stylesheet style.css" 85 "--param xref.with.number.and.title 1" 86 "--param toc.section.depth 3" 87 "--stringparam admon.style ''" 88 "--stringparam callout.graphics.extension .gif" 89 "--stringparam current.docid manual" 90 "--param chunk.section.depth 0" 91 "--param chunk.first.sections 1" 92 "--param use.id.as.filename 1" 93 "--stringparam generate.toc 'book toc appendix toc'" 94 "--stringparam chunk.toc ${toc}" 95 ]; 96 97 olinkDB = stdenv.mkDerivation { 98 name = "manual-olinkdb"; 99 100 inherit sources; 101 102 buildInputs = [ libxml2 libxslt ]; 103 104 buildCommand = '' 105 ${copySources} 106 107 xsltproc \ 108 ${manualXsltprocOptions} \ 109 --stringparam collect.xref.targets only \ 110 --stringparam targets.filename "$out/manual.db" \ 111 --nonet --xinclude \ 112 ${docbook5_xsl}/xml/xsl/docbook/xhtml/chunktoc.xsl \ 113 ./manual.xml 114 115 # Check the validity of the man pages sources. 116 xmllint --noout --nonet --xinclude --noxincludenode \ 117 --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \ 118 ./man-pages.xml 119 120 cat > "$out/olinkdb.xml" <<EOF 121 <?xml version="1.0" encoding="utf-8"?> 122 <!DOCTYPE targetset SYSTEM 123 "file://${docbook5_xsl}/xml/xsl/docbook/common/targetdatabase.dtd" [ 124 <!ENTITY manualtargets SYSTEM "file://$out/manual.db"> 125 ]> 126 <targetset> 127 <targetsetinfo> 128 Allows for cross-referencing olinks between the manpages 129 and manual. 130 </targetsetinfo> 131 132 <document targetdoc="manual">&manualtargets;</document> 133 </targetset> 134 EOF 135 ''; 136 }; 137 138in rec { 139 140 # The NixOS options in JSON format. 141 optionsJSON = stdenv.mkDerivation { 142 name = "options-json"; 143 144 buildCommand = '' 145 # Export list of options in different format. 146 dst=$out/share/doc/nixos 147 mkdir -p $dst 148 149 cp ${builtins.toFile "options.json" (builtins.unsafeDiscardStringContext (builtins.toJSON 150 (builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList')))) 151 } $dst/options.json 152 153 mkdir -p $out/nix-support 154 echo "file json $dst/options.json" >> $out/nix-support/hydra-build-products 155 ''; # */ 156 157 meta.description = "List of NixOS options in JSON format"; 158 }; 159 160 # Generate the NixOS manual. 161 manual = stdenv.mkDerivation { 162 name = "nixos-manual"; 163 164 inherit sources; 165 166 buildInputs = [ libxml2 libxslt ]; 167 168 buildCommand = '' 169 ${copySources} 170 171 # Check the validity of the manual sources. 172 xmllint --noout --nonet --xinclude --noxincludenode \ 173 --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \ 174 manual.xml 175 176 # Generate the HTML manual. 177 dst=$out/share/doc/nixos 178 mkdir -p $dst 179 xsltproc \ 180 ${manualXsltprocOptions} \ 181 --stringparam target.database.document "${olinkDB}/olinkdb.xml" \ 182 --nonet --xinclude --output $dst/ \ 183 ${docbook5_xsl}/xml/xsl/docbook/xhtml/chunktoc.xsl ./manual.xml 184 185 mkdir -p $dst/images/callouts 186 cp ${docbook5_xsl}/xml/xsl/docbook/images/callouts/*.gif $dst/images/callouts/ 187 188 cp ${./style.css} $dst/style.css 189 190 mkdir -p $out/nix-support 191 echo "nix-build out $out" >> $out/nix-support/hydra-build-products 192 echo "doc manual $dst" >> $out/nix-support/hydra-build-products 193 ''; # */ 194 195 meta.description = "The NixOS manual in HTML format"; 196 197 allowedReferences = ["out"]; 198 }; 199 200 201 manualEpub = stdenv.mkDerivation { 202 name = "nixos-manual-epub"; 203 204 inherit sources; 205 206 buildInputs = [ libxml2 libxslt zip ]; 207 208 buildCommand = '' 209 ${copySources} 210 211 # Check the validity of the manual sources. 212 xmllint --noout --nonet --xinclude --noxincludenode \ 213 --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \ 214 manual.xml 215 216 # Generate the epub manual. 217 dst=$out/share/doc/nixos 218 219 xsltproc \ 220 ${manualXsltprocOptions} \ 221 --stringparam target.database.document "${olinkDB}/olinkdb.xml" \ 222 --nonet --xinclude --output $dst/epub/ \ 223 ${docbook5_xsl}/xml/xsl/docbook/epub/docbook.xsl ./manual.xml 224 225 mkdir -p $dst/epub/OEBPS/images/callouts 226 cp -r ${docbook5_xsl}/xml/xsl/docbook/images/callouts/*.gif $dst/epub/OEBPS/images/callouts 227 echo "application/epub+zip" > mimetype 228 manual="$dst/nixos-manual.epub" 229 zip -0Xq "$manual" mimetype 230 cd $dst/epub && zip -Xr9D "$manual" * 231 232 rm -rf $dst/epub 233 234 mkdir -p $out/nix-support 235 echo "doc-epub manual $manual" >> $out/nix-support/hydra-build-products 236 ''; 237 }; 238 239 # Generate the NixOS manpages. 240 manpages = stdenv.mkDerivation { 241 name = "nixos-manpages"; 242 243 inherit sources; 244 245 buildInputs = [ libxml2 libxslt ]; 246 247 buildCommand = '' 248 ${copySources} 249 250 # Check the validity of the man pages sources. 251 xmllint --noout --nonet --xinclude --noxincludenode \ 252 --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \ 253 ./man-pages.xml 254 255 # Generate manpages. 256 mkdir -p $out/share/man 257 xsltproc --nonet --xinclude \ 258 --param man.output.in.separate.dir 1 \ 259 --param man.output.base.dir "'$out/share/man/'" \ 260 --param man.endnotes.are.numbered 0 \ 261 --param man.break.after.slash 1 \ 262 --stringparam target.database.document "${olinkDB}/olinkdb.xml" \ 263 ${docbook5_xsl}/xml/xsl/docbook/manpages/docbook.xsl \ 264 ./man-pages.xml 265 ''; 266 267 allowedReferences = ["out"]; 268 }; 269 270}