From 39da575262c673fbbdb02ac03fc9a5bb312d3a54 Mon Sep 17 00:00:00 2001 From: Christine Koppelt Date: Thu, 28 Jul 2016 04:27:39 +0200 Subject: add epub for NixOS manual (second try) (#17205) --- nixos/doc/manual/default.nix | 57 ++++++++++++++++++++++++++++++++++++-------- nixos/release.nix | 1 + 2 files changed, 48 insertions(+), 10 deletions(-) (limited to 'nixos') diff --git a/nixos/doc/manual/default.nix b/nixos/doc/manual/default.nix index 50b1bb9c7354..83dad5fd8dc7 100644 --- a/nixos/doc/manual/default.nix +++ b/nixos/doc/manual/default.nix @@ -1,27 +1,27 @@ { pkgs, options, version, revision, extraSources ? [] }: with pkgs; -with pkgs.lib; let + lib = pkgs.lib; # Remove invisible and internal options. - optionsList = filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList options); + optionsList = lib.filter (opt: opt.visible && !opt.internal) (lib.optionAttrSetToDocList options); # Replace functions by the string substFunction = x: - if builtins.isAttrs x then mapAttrs (name: substFunction) x + if builtins.isAttrs x then lib.mapAttrs (name: substFunction) x else if builtins.isList x then map substFunction x else if builtins.isFunction x then "" else x; # Clean up declaration sites to not refer to the NixOS source tree. - optionsList' = flip map optionsList (opt: opt // { + optionsList' = lib.flip map optionsList (opt: opt // { declarations = map stripAnyPrefixes opt.declarations; } - // optionalAttrs (opt ? example) { example = substFunction opt.example; } - // optionalAttrs (opt ? default) { default = substFunction opt.default; } - // optionalAttrs (opt ? type) { type = substFunction opt.type; }); + // lib.optionalAttrs (opt ? example) { example = substFunction opt.example; } + // lib.optionalAttrs (opt ? default) { default = substFunction opt.default; } + // lib.optionalAttrs (opt ? type) { type = substFunction opt.type; }); # We need to strip references to /nix/store/* from options, # including any `extraSources` if some modules came from elsewhere, @@ -30,7 +30,7 @@ let # E.g. if some `options` came from modules in ${pkgs.customModules}/nix, # you'd need to include `extraSources = [ pkgs.customModules ]` prefixesToStrip = map (p: "${toString p}/") ([ ../../.. ] ++ extraSources); - stripAnyPrefixes = flip (fold removePrefix) prefixesToStrip; + stripAnyPrefixes = lib.flip (lib.fold lib.removePrefix) prefixesToStrip; # Convert the list of options into an XML file. optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList'); @@ -49,7 +49,7 @@ let -o $out ${./options-to-docbook.xsl} $optionsXML ''; - sources = sourceFilesBySuffices ./. [".xml"]; + sources = lib.sourceFilesBySuffices ./. [".xml"]; copySources = '' @@ -143,7 +143,7 @@ in rec { mkdir -p $dst cp ${builtins.toFile "options.json" (builtins.unsafeDiscardStringContext (builtins.toJSON - (listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList')))) + (builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList')))) } $dst/options.json mkdir -p $out/nix-support @@ -193,6 +193,43 @@ in rec { allowedReferences = ["out"]; }; + + manualEpub = stdenv.mkDerivation { + name = "nixos-manual-epub"; + + inherit sources; + + buildInputs = [ libxml2 libxslt zip ]; + + buildCommand = '' + ${copySources} + + # Check the validity of the manual sources. + xmllint --noout --nonet --xinclude --noxincludenode \ + --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \ + manual.xml + + # Generate the epub manual. + dst=$out/share/doc/nixos + + xsltproc \ + ${manualXsltprocOptions} \ + --stringparam target.database.document "${olinkDB}/olinkdb.xml" \ + --nonet --xinclude --output $dst/epub/ \ + ${docbook5_xsl}/xml/xsl/docbook/epub/docbook.xsl ./manual.xml + + mkdir -p $dst/epub/OEBPS/images/callouts + cp -r ${docbook5_xsl}/xml/xsl/docbook/images/callouts/*.gif $dst/epub/OEBPS/images/callouts + echo "application/epub+zip" > mimetype + zip -0Xq "$dst/NixOS Manual - NixOS community.epub" mimetype + zip -Xr9D "$dst/NixOS Manual - NixOS community.epub" $dst/epub/* + + mkdir -p $out/nix-support + echo "doc-epub manual $dst/NixOS Manual - NixOS community.epub" >> $out/nix-support/hydra-build-products + ''; + }; + + manualPDF = stdenv.mkDerivation { name = "nixos-manual-pdf"; diff --git a/nixos/release.nix b/nixos/release.nix index 273c3e21a10d..b059de34132b 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -95,6 +95,7 @@ in rec { channel = import lib/make-channel.nix { inherit pkgs nixpkgs version versionSuffix; }; manual = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manual); + manualEpub = (buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manualEpub)); manualPDF = (buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manualPDF)).x86_64-linux; manpages = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manpages); options = (buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.optionsJSON)).x86_64-linux; -- cgit 1.4.1