add epub for NixOS manual (second try) (#17205)

authored by

Christine Koppelt and committed by
Franz Pletz
39da5752 b65e9d87

+48 -10
+47 -10
nixos/doc/manual/default.nix
··· 1 1 { pkgs, options, version, revision, extraSources ? [] }: 2 2 3 3 with pkgs; 4 - with pkgs.lib; 5 4 6 5 let 6 + lib = pkgs.lib; 7 7 8 8 # Remove invisible and internal options. 9 - optionsList = filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList options); 9 + optionsList = lib.filter (opt: opt.visible && !opt.internal) (lib.optionAttrSetToDocList options); 10 10 11 11 # Replace functions by the string <function> 12 12 substFunction = x: 13 - if builtins.isAttrs x then mapAttrs (name: substFunction) x 13 + if builtins.isAttrs x then lib.mapAttrs (name: substFunction) x 14 14 else if builtins.isList x then map substFunction x 15 15 else if builtins.isFunction x then "<function>" 16 16 else x; 17 17 18 18 # Clean up declaration sites to not refer to the NixOS source tree. 19 - optionsList' = flip map optionsList (opt: opt // { 19 + optionsList' = lib.flip map optionsList (opt: opt // { 20 20 declarations = map stripAnyPrefixes opt.declarations; 21 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; }); 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 25 26 26 # We need to strip references to /nix/store/* from options, 27 27 # including any `extraSources` if some modules came from elsewhere, ··· 30 30 # E.g. if some `options` came from modules in ${pkgs.customModules}/nix, 31 31 # you'd need to include `extraSources = [ pkgs.customModules ]` 32 32 prefixesToStrip = map (p: "${toString p}/") ([ ../../.. ] ++ extraSources); 33 - stripAnyPrefixes = flip (fold removePrefix) prefixesToStrip; 33 + stripAnyPrefixes = lib.flip (lib.fold lib.removePrefix) prefixesToStrip; 34 34 35 35 # Convert the list of options into an XML file. 36 36 optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList'); ··· 49 49 -o $out ${./options-to-docbook.xsl} $optionsXML 50 50 ''; 51 51 52 - sources = sourceFilesBySuffices ./. [".xml"]; 52 + sources = lib.sourceFilesBySuffices ./. [".xml"]; 53 53 54 54 copySources = 55 55 '' ··· 143 143 mkdir -p $dst 144 144 145 145 cp ${builtins.toFile "options.json" (builtins.unsafeDiscardStringContext (builtins.toJSON 146 - (listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList')))) 146 + (builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList')))) 147 147 } $dst/options.json 148 148 149 149 mkdir -p $out/nix-support ··· 192 192 193 193 allowedReferences = ["out"]; 194 194 }; 195 + 196 + 197 + manualEpub = stdenv.mkDerivation { 198 + name = "nixos-manual-epub"; 199 + 200 + inherit sources; 201 + 202 + buildInputs = [ libxml2 libxslt zip ]; 203 + 204 + buildCommand = '' 205 + ${copySources} 206 + 207 + # Check the validity of the manual sources. 208 + xmllint --noout --nonet --xinclude --noxincludenode \ 209 + --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \ 210 + manual.xml 211 + 212 + # Generate the epub manual. 213 + dst=$out/share/doc/nixos 214 + 215 + xsltproc \ 216 + ${manualXsltprocOptions} \ 217 + --stringparam target.database.document "${olinkDB}/olinkdb.xml" \ 218 + --nonet --xinclude --output $dst/epub/ \ 219 + ${docbook5_xsl}/xml/xsl/docbook/epub/docbook.xsl ./manual.xml 220 + 221 + mkdir -p $dst/epub/OEBPS/images/callouts 222 + cp -r ${docbook5_xsl}/xml/xsl/docbook/images/callouts/*.gif $dst/epub/OEBPS/images/callouts 223 + echo "application/epub+zip" > mimetype 224 + zip -0Xq "$dst/NixOS Manual - NixOS community.epub" mimetype 225 + zip -Xr9D "$dst/NixOS Manual - NixOS community.epub" $dst/epub/* 226 + 227 + mkdir -p $out/nix-support 228 + echo "doc-epub manual $dst/NixOS Manual - NixOS community.epub" >> $out/nix-support/hydra-build-products 229 + ''; 230 + }; 231 + 195 232 196 233 manualPDF = stdenv.mkDerivation { 197 234 name = "nixos-manual-pdf";
+1
nixos/release.nix
··· 95 95 channel = import lib/make-channel.nix { inherit pkgs nixpkgs version versionSuffix; }; 96 96 97 97 manual = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manual); 98 + manualEpub = (buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manualEpub)); 98 99 manualPDF = (buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manualPDF)).x86_64-linux; 99 100 manpages = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manpages); 100 101 options = (buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.optionsJSON)).x86_64-linux;