mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-02-07 20:53:22 +00:00
add epub for NixOS manual (second try) (#17205)
This commit is contained in:
parent
b65e9d87e2
commit
39da575262
@ -1,27 +1,27 @@
|
|||||||
{ pkgs, options, version, revision, extraSources ? [] }:
|
{ pkgs, options, version, revision, extraSources ? [] }:
|
||||||
|
|
||||||
with pkgs;
|
with pkgs;
|
||||||
with pkgs.lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
|
lib = pkgs.lib;
|
||||||
|
|
||||||
# Remove invisible and internal options.
|
# 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>
|
# Replace functions by the string <function>
|
||||||
substFunction = x:
|
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.isList x then map substFunction x
|
||||||
else if builtins.isFunction x then "<function>"
|
else if builtins.isFunction x then "<function>"
|
||||||
else x;
|
else x;
|
||||||
|
|
||||||
# Clean up declaration sites to not refer to the NixOS source tree.
|
# 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;
|
declarations = map stripAnyPrefixes opt.declarations;
|
||||||
}
|
}
|
||||||
// optionalAttrs (opt ? example) { example = substFunction opt.example; }
|
// lib.optionalAttrs (opt ? example) { example = substFunction opt.example; }
|
||||||
// optionalAttrs (opt ? default) { default = substFunction opt.default; }
|
// lib.optionalAttrs (opt ? default) { default = substFunction opt.default; }
|
||||||
// optionalAttrs (opt ? type) { type = substFunction opt.type; });
|
// lib.optionalAttrs (opt ? type) { type = substFunction opt.type; });
|
||||||
|
|
||||||
# We need to strip references to /nix/store/* from options,
|
# We need to strip references to /nix/store/* from options,
|
||||||
# including any `extraSources` if some modules came from elsewhere,
|
# 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,
|
# E.g. if some `options` came from modules in ${pkgs.customModules}/nix,
|
||||||
# you'd need to include `extraSources = [ pkgs.customModules ]`
|
# you'd need to include `extraSources = [ pkgs.customModules ]`
|
||||||
prefixesToStrip = map (p: "${toString p}/") ([ ../../.. ] ++ extraSources);
|
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.
|
# Convert the list of options into an XML file.
|
||||||
optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList');
|
optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList');
|
||||||
@ -49,7 +49,7 @@ let
|
|||||||
-o $out ${./options-to-docbook.xsl} $optionsXML
|
-o $out ${./options-to-docbook.xsl} $optionsXML
|
||||||
'';
|
'';
|
||||||
|
|
||||||
sources = sourceFilesBySuffices ./. [".xml"];
|
sources = lib.sourceFilesBySuffices ./. [".xml"];
|
||||||
|
|
||||||
copySources =
|
copySources =
|
||||||
''
|
''
|
||||||
@ -143,7 +143,7 @@ in rec {
|
|||||||
mkdir -p $dst
|
mkdir -p $dst
|
||||||
|
|
||||||
cp ${builtins.toFile "options.json" (builtins.unsafeDiscardStringContext (builtins.toJSON
|
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
|
} $dst/options.json
|
||||||
|
|
||||||
mkdir -p $out/nix-support
|
mkdir -p $out/nix-support
|
||||||
@ -193,6 +193,43 @@ in rec {
|
|||||||
allowedReferences = ["out"];
|
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 {
|
manualPDF = stdenv.mkDerivation {
|
||||||
name = "nixos-manual-pdf";
|
name = "nixos-manual-pdf";
|
||||||
|
|
||||||
|
@ -95,6 +95,7 @@ in rec {
|
|||||||
channel = import lib/make-channel.nix { inherit pkgs nixpkgs version versionSuffix; };
|
channel = import lib/make-channel.nix { inherit pkgs nixpkgs version versionSuffix; };
|
||||||
|
|
||||||
manual = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manual);
|
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;
|
manualPDF = (buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manualPDF)).x86_64-linux;
|
||||||
manpages = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manpages);
|
manpages = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manpages);
|
||||||
options = (buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.optionsJSON)).x86_64-linux;
|
options = (buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.optionsJSON)).x86_64-linux;
|
||||||
|
Loading…
Reference in New Issue
Block a user