2021-12-18 19:37:41 +01:00
|
|
|
{ pkgs
|
|
|
|
, options
|
|
|
|
, config
|
|
|
|
, version
|
|
|
|
, revision
|
|
|
|
, extraSources ? []
|
|
|
|
, baseOptionsJSON ? null
|
|
|
|
, warningsAreErrors ? true
|
|
|
|
, prefix ? ../../..
|
|
|
|
}:
|
2008-06-05 17:33:17 +02:00
|
|
|
|
2014-08-09 16:30:44 +02:00
|
|
|
with pkgs;
|
2013-10-17 14:09:05 +02:00
|
|
|
|
2011-09-14 20:20:50 +02:00
|
|
|
let
|
2022-06-27 20:06:30 +02:00
|
|
|
inherit (lib) hasPrefix removePrefix;
|
|
|
|
|
2016-07-28 04:27:39 +02:00
|
|
|
lib = pkgs.lib;
|
2009-10-06 01:15:06 +02:00
|
|
|
|
2023-01-31 04:19:28 +01:00
|
|
|
manpageUrls = pkgs.path + "/doc/manpage-urls.json";
|
|
|
|
|
2016-01-22 20:22:12 +01:00
|
|
|
# We need to strip references to /nix/store/* from options,
|
|
|
|
# including any `extraSources` if some modules came from elsewhere,
|
|
|
|
# or else the build will fail.
|
|
|
|
#
|
|
|
|
# E.g. if some `options` came from modules in ${pkgs.customModules}/nix,
|
2016-01-29 16:20:22 +01:00
|
|
|
# you'd need to include `extraSources = [ pkgs.customModules ]`
|
2021-11-19 00:26:27 +01:00
|
|
|
prefixesToStrip = map (p: "${toString p}/") ([ prefix ] ++ extraSources);
|
2021-01-25 07:57:48 +01:00
|
|
|
stripAnyPrefixes = lib.flip (lib.foldr lib.removePrefix) prefixesToStrip;
|
2013-10-23 19:32:19 +02:00
|
|
|
|
2019-08-08 12:59:25 +02:00
|
|
|
optionsDoc = buildPackages.nixosOptionsDoc {
|
2023-06-13 12:38:22 +02:00
|
|
|
inherit options revision baseOptionsJSON warningsAreErrors;
|
2019-08-08 12:59:25 +02:00
|
|
|
transformOptions = opt: opt // {
|
|
|
|
# Clean up declaration sites to not refer to the NixOS source tree.
|
|
|
|
declarations = map stripAnyPrefixes opt.declarations;
|
|
|
|
};
|
|
|
|
};
|
2009-09-18 17:10:37 +02:00
|
|
|
|
2022-06-27 17:52:08 +02:00
|
|
|
nixos-lib = import ../../lib { };
|
|
|
|
|
|
|
|
testOptionsDoc = let
|
|
|
|
eval = nixos-lib.evalTest {
|
|
|
|
# Avoid evaluating a NixOS config prototype.
|
|
|
|
config.node.type = lib.types.deferredModule;
|
|
|
|
options._module.args = lib.mkOption { internal = true; };
|
|
|
|
};
|
|
|
|
in buildPackages.nixosOptionsDoc {
|
|
|
|
inherit (eval) options;
|
2022-12-18 23:22:17 +01:00
|
|
|
inherit revision;
|
2022-06-27 17:52:08 +02:00
|
|
|
transformOptions = opt: opt // {
|
|
|
|
# Clean up declaration sites to not refer to the NixOS source tree.
|
|
|
|
declarations =
|
|
|
|
map
|
|
|
|
(decl:
|
|
|
|
if hasPrefix (toString ../../..) (toString decl)
|
|
|
|
then
|
|
|
|
let subpath = removePrefix "/" (removePrefix (toString ../../..) (toString decl));
|
|
|
|
in { url = "https://github.com/NixOS/nixpkgs/blob/master/${subpath}"; name = subpath; }
|
|
|
|
else decl)
|
|
|
|
opt.declarations;
|
|
|
|
};
|
|
|
|
documentType = "none";
|
|
|
|
variablelistId = "test-options-list";
|
2022-09-29 12:41:59 +02:00
|
|
|
optionIdPrefix = "test-opt-";
|
2022-06-27 17:52:08 +02:00
|
|
|
};
|
|
|
|
|
2023-02-20 18:55:15 +01:00
|
|
|
prepareManualFromMD = ''
|
|
|
|
cp -r --no-preserve=all $inputs/* .
|
|
|
|
|
|
|
|
substituteInPlace ./manual.md \
|
|
|
|
--replace '@NIXOS_VERSION@' "${version}"
|
|
|
|
substituteInPlace ./configuration/configuration.md \
|
|
|
|
--replace \
|
|
|
|
'@MODULE_CHAPTERS@' \
|
|
|
|
${lib.escapeShellArg (lib.concatMapStringsSep "\n" (p: "${p.value}") config.meta.doc)}
|
|
|
|
substituteInPlace ./nixos-options.md \
|
|
|
|
--replace \
|
|
|
|
'@NIXOS_OPTIONS_JSON@' \
|
|
|
|
${optionsDoc.optionsJSON}/share/doc/nixos/options.json
|
|
|
|
substituteInPlace ./development/writing-nixos-tests.section.md \
|
|
|
|
--replace \
|
|
|
|
'@NIXOS_TEST_OPTIONS_JSON@' \
|
|
|
|
${testOptionsDoc.optionsJSON}/share/doc/nixos/options.json
|
|
|
|
'';
|
|
|
|
|
2010-08-11 14:28:53 +02:00
|
|
|
in rec {
|
2023-06-13 12:21:38 +02:00
|
|
|
inherit (optionsDoc) optionsJSON optionsNix optionsDocBook;
|
2014-11-17 13:41:18 +01:00
|
|
|
|
2010-08-11 14:28:53 +02:00
|
|
|
# Generate the NixOS manual.
|
2018-09-06 21:17:44 +02:00
|
|
|
manualHTML = runCommand "nixos-manual-html"
|
2023-06-11 20:36:29 +02:00
|
|
|
{ nativeBuildInputs = [ buildPackages.nixos-render-docs ];
|
|
|
|
inputs = lib.sourceFilesBySuffices ./. [ ".md" ];
|
2016-09-27 15:26:37 +02:00
|
|
|
meta.description = "The NixOS manual in HTML format";
|
|
|
|
allowedReferences = ["out"];
|
|
|
|
}
|
|
|
|
''
|
2009-10-05 15:17:45 +02:00
|
|
|
# Generate the HTML manual.
|
2009-07-14 17:47:03 +02:00
|
|
|
dst=$out/share/doc/nixos
|
2014-06-30 14:56:10 +02:00
|
|
|
mkdir -p $dst
|
2013-01-09 13:43:57 +01:00
|
|
|
|
2018-04-05 13:54:01 +02:00
|
|
|
cp ${../../../doc/style.css} $dst/style.css
|
|
|
|
cp ${../../../doc/overrides.css} $dst/overrides.css
|
|
|
|
cp -r ${pkgs.documentation-highlighter} $dst/highlightjs
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2023-06-11 20:36:29 +02:00
|
|
|
${prepareManualFromMD}
|
|
|
|
|
|
|
|
nixos-render-docs -j $NIX_BUILD_CORES manual html \
|
|
|
|
--manpage-urls ${manpageUrls} \
|
|
|
|
--revision ${lib.escapeShellArg revision} \
|
2023-06-13 12:39:05 +02:00
|
|
|
--generator "nixos-render-docs ${lib.version}" \
|
2023-06-11 20:36:29 +02:00
|
|
|
--stylesheet style.css \
|
|
|
|
--stylesheet overrides.css \
|
|
|
|
--stylesheet highlightjs/mono-blue.css \
|
|
|
|
--script ./highlightjs/highlight.pack.js \
|
|
|
|
--script ./highlightjs/loader.js \
|
|
|
|
--toc-depth 1 \
|
|
|
|
--chunk-toc-depth 1 \
|
|
|
|
./manual.md \
|
|
|
|
$dst/index.html
|
2023-02-20 18:55:15 +01:00
|
|
|
|
2013-10-24 20:06:02 +02:00
|
|
|
mkdir -p $out/nix-support
|
|
|
|
echo "nix-build out $out" >> $out/nix-support/hydra-build-products
|
2014-09-10 15:03:49 +02:00
|
|
|
echo "doc manual $dst" >> $out/nix-support/hydra-build-products
|
2012-07-25 17:54:24 +02:00
|
|
|
''; # */
|
2013-10-24 20:06:02 +02:00
|
|
|
|
2018-09-06 21:17:44 +02:00
|
|
|
# Alias for backward compatibility. TODO(@oxij): remove eventually.
|
|
|
|
manual = manualHTML;
|
|
|
|
|
|
|
|
# Index page of the NixOS manual.
|
|
|
|
manualHTMLIndex = "${manualHTML}/share/doc/nixos/index.html";
|
2010-08-11 14:28:53 +02:00
|
|
|
|
2016-09-27 15:26:37 +02:00
|
|
|
manualEpub = runCommand "nixos-manual-epub"
|
2023-02-12 09:40:07 +01:00
|
|
|
{ nativeBuildInputs = [ buildPackages.libxml2.bin buildPackages.libxslt.bin buildPackages.zip ];
|
2023-06-11 19:26:30 +02:00
|
|
|
doc = ''
|
|
|
|
<book xmlns="http://docbook.org/ns/docbook"
|
|
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
|
|
version="5.0"
|
|
|
|
xml:id="book-nixos-manual">
|
|
|
|
<info>
|
|
|
|
<title>NixOS Manual</title>
|
|
|
|
<subtitle>Version ${lib.version}</subtitle>
|
|
|
|
</info>
|
|
|
|
<chapter>
|
|
|
|
<title>Temporarily unavailable</title>
|
|
|
|
<para>
|
|
|
|
The NixOS manual is currently not available in EPUB format,
|
|
|
|
please use the <link xlink:href="https://nixos.org/nixos/manual">HTML manual</link>
|
|
|
|
instead.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If you've used the EPUB manual in the past and it has been useful to you, please
|
|
|
|
<link xlink:href="https://github.com/NixOS/nixpkgs/issues/237234">let us know</link>.
|
|
|
|
</para>
|
|
|
|
</chapter>
|
|
|
|
</book>
|
|
|
|
'';
|
|
|
|
passAsFile = [ "doc" ];
|
2016-09-27 15:26:37 +02:00
|
|
|
}
|
|
|
|
''
|
2016-07-28 04:27:39 +02:00
|
|
|
# Generate the epub manual.
|
|
|
|
dst=$out/share/doc/nixos
|
|
|
|
|
|
|
|
xsltproc \
|
2023-06-11 19:26:30 +02:00
|
|
|
--param chapter.autolabel 0 \
|
2016-07-28 04:27:39 +02:00
|
|
|
--nonet --xinclude --output $dst/epub/ \
|
2018-07-17 22:11:16 +02:00
|
|
|
${docbook_xsl_ns}/xml/xsl/docbook/epub/docbook.xsl \
|
2023-06-11 19:26:30 +02:00
|
|
|
$docPath
|
2016-07-28 04:27:39 +02:00
|
|
|
|
|
|
|
echo "application/epub+zip" > mimetype
|
2016-08-01 11:02:41 +02:00
|
|
|
manual="$dst/nixos-manual.epub"
|
|
|
|
zip -0Xq "$manual" mimetype
|
|
|
|
cd $dst/epub && zip -Xr9D "$manual" *
|
|
|
|
|
|
|
|
rm -rf $dst/epub
|
2016-07-28 04:27:39 +02:00
|
|
|
|
|
|
|
mkdir -p $out/nix-support
|
2016-08-01 11:02:41 +02:00
|
|
|
echo "doc-epub manual $manual" >> $out/nix-support/hydra-build-products
|
2016-07-28 04:27:39 +02:00
|
|
|
'';
|
|
|
|
|
2010-08-11 14:28:53 +02:00
|
|
|
|
2016-09-27 15:26:37 +02:00
|
|
|
# Generate the NixOS manpages.
|
|
|
|
manpages = runCommand "nixos-manpages"
|
2023-02-07 14:17:43 +01:00
|
|
|
{ nativeBuildInputs = [
|
2023-01-31 04:19:28 +01:00
|
|
|
buildPackages.installShellFiles
|
|
|
|
buildPackages.nixos-render-docs
|
2023-01-29 01:07:26 +01:00
|
|
|
];
|
2016-09-27 15:26:37 +02:00
|
|
|
allowedReferences = ["out"];
|
|
|
|
}
|
|
|
|
''
|
2009-10-05 15:17:45 +02:00
|
|
|
# Generate manpages.
|
2023-01-29 01:07:26 +01:00
|
|
|
mkdir -p $out/share/man/man8
|
|
|
|
installManPage ${./manpages}/*
|
2023-06-11 20:36:29 +02:00
|
|
|
mkdir -p $out/share/man/man5
|
|
|
|
nixos-render-docs -j $NIX_BUILD_CORES options manpage \
|
|
|
|
--revision ${lib.escapeShellArg revision} \
|
|
|
|
${optionsJSON}/share/doc/nixos/options.json \
|
|
|
|
$out/share/man/man5/configuration.nix.5
|
2008-01-04 15:24:42 +01:00
|
|
|
'';
|
2015-09-24 11:47:00 +02:00
|
|
|
|
2011-09-14 20:20:50 +02:00
|
|
|
}
|