summary refs log tree commit diff
path: root/nixos/doc/manual/default.nix
diff options
context:
space:
mode:
authorChristine Koppelt <cko@users.noreply.github.com>2016-07-28 04:27:39 +0200
committerFranz Pletz <fpletz@fnordicwalking.de>2016-07-28 04:27:39 +0200
commit39da575262c673fbbdb02ac03fc9a5bb312d3a54 (patch)
tree739e615767f98303966887fc49c345185d299365 /nixos/doc/manual/default.nix
parentb65e9d87e2681bebb336f1c9a79d9ed8380b0907 (diff)
downloadnixpkgs-39da575262c673fbbdb02ac03fc9a5bb312d3a54.tar
nixpkgs-39da575262c673fbbdb02ac03fc9a5bb312d3a54.tar.gz
nixpkgs-39da575262c673fbbdb02ac03fc9a5bb312d3a54.tar.bz2
nixpkgs-39da575262c673fbbdb02ac03fc9a5bb312d3a54.tar.lz
nixpkgs-39da575262c673fbbdb02ac03fc9a5bb312d3a54.tar.xz
nixpkgs-39da575262c673fbbdb02ac03fc9a5bb312d3a54.tar.zst
nixpkgs-39da575262c673fbbdb02ac03fc9a5bb312d3a54.zip
add epub for NixOS manual (second try) (#17205)
Diffstat (limited to 'nixos/doc/manual/default.nix')
-rw-r--r--nixos/doc/manual/default.nix57
1 files changed, 47 insertions, 10 deletions
diff --git a/nixos/doc/manual/default.nix b/nixos/doc/manual/default.nix
index 50b1bb9c735..83dad5fd8dc 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 <function>
   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 "<function>"
     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";