at v206 6.1 kB view raw
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. 35 optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList'); 36 37 optionsDocBook = runCommand "options-db.xml" {} '' 38 optionsXML=${optionsXML} 39 if grep /nixpkgs/nixos/modules $optionsXML; then 40 echo "The manual appears to depend on the location of Nixpkgs, which is bad" 41 echo "since this prevents sharing via the NixOS channel. This is typically" 42 echo "caused by an option default that refers to a relative path (see above" 43 echo "for hints about the offending path)." 44 exit 1 45 fi 46 ${libxslt}/bin/xsltproc \ 47 --stringparam revision '${revision}' \ 48 -o $out ${./options-to-docbook.xsl} $optionsXML 49 ''; 50 51 sources = sourceFilesBySuffices ./. [".xml"]; 52 53 copySources = 54 '' 55 cp -prd $sources/* . # */ 56 chmod -R u+w . 57 cp ${../../modules/services/databases/postgresql.xml} configuration/postgresql.xml 58 ln -s ${optionsDocBook} options-db.xml 59 echo "${version}" > version 60 ''; 61 62 toc = builtins.toFile "toc.xml" 63 '' 64 <toc role="chunk-toc"> 65 <d:tocentry xmlns:d="http://docbook.org/ns/docbook" linkend="book-nixos-manual"><?dbhtml filename="index.html"?> 66 <d:tocentry linkend="ch-options"><?dbhtml filename="options.html"?></d:tocentry> 67 <d:tocentry linkend="ch-release-notes"><?dbhtml filename="release-notes.html"?></d:tocentry> 68 </d:tocentry> 69 </toc> 70 ''; 71 72in rec { 73 74 # The NixOS options in JSON format. 75 optionsJSON = stdenv.mkDerivation { 76 name = "options-json"; 77 78 buildCommand = '' 79 # Export list of options in different format. 80 dst=$out/share/doc/nixos 81 mkdir -p $dst 82 83 cp ${builtins.toFile "options.json" (builtins.unsafeDiscardStringContext (builtins.toJSON 84 (listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList')))) 85 } $dst/options.json 86 87 mkdir -p $out/nix-support 88 echo "file json $dst/options.json" >> $out/nix-support/hydra-build-products 89 ''; # */ 90 91 meta.description = "List of NixOS options in JSON format"; 92 }; 93 94 # Generate the NixOS manual. 95 manual = stdenv.mkDerivation { 96 name = "nixos-manual"; 97 98 inherit sources; 99 100 buildInputs = [ libxml2 libxslt ]; 101 102 buildCommand = '' 103 ${copySources} 104 105 # Check the validity of the manual sources. 106 xmllint --noout --nonet --xinclude --noxincludenode \ 107 --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \ 108 manual.xml 109 110 # Generate the HTML manual. 111 dst=$out/share/doc/nixos 112 mkdir -p $dst 113 xsltproc \ 114 --param section.autolabel 1 \ 115 --param section.label.includes.component.label 1 \ 116 --stringparam html.stylesheet style.css \ 117 --param xref.with.number.and.title 1 \ 118 --param toc.section.depth 3 \ 119 --stringparam admon.style "" \ 120 --stringparam callout.graphics.extension .gif \ 121 --param chunk.section.depth 0 \ 122 --param chunk.first.sections 1 \ 123 --param use.id.as.filename 1 \ 124 --stringparam generate.toc "book toc appendix toc" \ 125 --stringparam chunk.toc ${toc} \ 126 --nonet --xinclude --output $dst/ \ 127 ${docbook5_xsl}/xml/xsl/docbook/xhtml/chunktoc.xsl ./manual.xml 128 129 mkdir -p $dst/images/callouts 130 cp ${docbook5_xsl}/xml/xsl/docbook/images/callouts/*.gif $dst/images/callouts/ 131 132 cp ${./style.css} $dst/style.css 133 134 mkdir -p $out/nix-support 135 echo "nix-build out $out" >> $out/nix-support/hydra-build-products 136 echo "doc manual $dst" >> $out/nix-support/hydra-build-products 137 ''; # */ 138 139 meta.description = "The NixOS manual in HTML format"; 140 141 allowedReferences = ["out"]; 142 }; 143 144 manualPDF = stdenv.mkDerivation { 145 name = "nixos-manual-pdf"; 146 147 inherit sources; 148 149 buildInputs = [ libxml2 libxslt dblatex dblatex.tex ]; 150 151 buildCommand = '' 152 ${copySources} 153 154 dst=$out/share/doc/nixos 155 mkdir -p $dst 156 xmllint --xinclude manual.xml | dblatex -o $dst/manual.pdf - \ 157 -P doc.collab.show=0 \ 158 -P latex.output.revhistory=0 159 160 mkdir -p $out/nix-support 161 echo "doc-pdf manual $dst/manual.pdf" >> $out/nix-support/hydra-build-products 162 ''; 163 }; 164 165 # Generate the NixOS manpages. 166 manpages = stdenv.mkDerivation { 167 name = "nixos-manpages"; 168 169 inherit sources; 170 171 buildInputs = [ libxml2 libxslt ]; 172 173 buildCommand = '' 174 ${copySources} 175 176 # Check the validity of the manual sources. 177 xmllint --noout --nonet --xinclude --noxincludenode \ 178 --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \ 179 ./man-pages.xml 180 181 # Generate manpages. 182 mkdir -p $out/share/man 183 xsltproc --nonet --xinclude \ 184 --param man.output.in.separate.dir 1 \ 185 --param man.output.base.dir "'$out/share/man/'" \ 186 --param man.endnotes.are.numbered 0 \ 187 ${docbook5_xsl}/xml/xsl/docbook/manpages/docbook.xsl \ 188 ./man-pages.xml 189 ''; 190 191 allowedReferences = ["out"]; 192 }; 193 194}