2021-12-18 19:37:41 +01:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
options,
|
|
|
|
config,
|
|
|
|
version,
|
|
|
|
revision,
|
|
|
|
extraSources ? [ ],
|
|
|
|
baseOptionsJSON ? null,
|
|
|
|
warningsAreErrors ? true,
|
|
|
|
prefix ? ../../..,
|
2025-05-31 19:54:53 +02:00
|
|
|
checkRedirects ? true,
|
2021-12-18 19:37:41 +01:00
|
|
|
}:
|
2008-06-05 15:33:17 +00:00
|
|
|
|
2011-09-14 18:20:50 +00:00
|
|
|
let
|
2024-03-27 21:18:50 -07:00
|
|
|
inherit (pkgs) buildPackages runCommand docbook_xsl_ns;
|
|
|
|
|
|
|
|
inherit (pkgs.lib)
|
|
|
|
hasPrefix
|
|
|
|
removePrefix
|
|
|
|
flip
|
|
|
|
foldr
|
|
|
|
types
|
|
|
|
mkOption
|
|
|
|
escapeShellArg
|
|
|
|
concatMapStringsSep
|
|
|
|
sourceFilesBySuffices
|
|
|
|
;
|
2009-10-05 23:15:06 +00:00
|
|
|
|
2023-07-13 11:28:19 +02:00
|
|
|
common = import ./common.nix;
|
|
|
|
|
2023-01-31 04:19:28 +01:00
|
|
|
manpageUrls = pkgs.path + "/doc/manpage-urls.json";
|
|
|
|
|
2016-01-22 14:22:12 -05: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 ]`
|
2016-01-29 19:34:00 +01:00
|
|
|
prefixesToStrip = map (p: "${toString p}/") ([ prefix ] ++ extraSources);
|
2024-03-27 21:18:50 -07:00
|
|
|
stripAnyPrefixes = flip (foldr 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 15:10:37 +00: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.
|
2024-03-27 21:18:50 -07:00
|
|
|
config.node.type = types.deferredModule;
|
|
|
|
options._module.args = mkOption { internal = true; };
|
2022-06-27 17:52:08 +02:00
|
|
|
};
|
|
|
|
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-07-07 23:01:55 +02:00
|
|
|
testDriverMachineDocstrings =
|
|
|
|
pkgs.callPackage ../../../nixos/lib/test-driver/nixos-test-driver-docstrings.nix
|
|
|
|
{ };
|
|
|
|
|
2023-02-20 18:55:15 +01:00
|
|
|
prepareManualFromMD = ''
|
|
|
|
cp -r --no-preserve=all $inputs/* .
|
|
|
|
|
2025-01-01 19:19:18 +02:00
|
|
|
cp -r ${../../../doc/release-notes} ./release-notes-nixpkgs
|
|
|
|
|
2023-02-20 18:55:15 +01:00
|
|
|
substituteInPlace ./manual.md \
|
2024-04-30 19:21:39 +02:00
|
|
|
--replace-fail '@NIXOS_VERSION@' "${version}"
|
2023-02-20 18:55:15 +01:00
|
|
|
substituteInPlace ./configuration/configuration.md \
|
2024-04-30 19:21:39 +02:00
|
|
|
--replace-fail \
|
2023-02-20 18:55:15 +01:00
|
|
|
'@MODULE_CHAPTERS@' \
|
2024-03-27 21:18:50 -07:00
|
|
|
${escapeShellArg (concatMapStringsSep "\n" (p: "${p.value}") config.meta.doc)}
|
2023-02-20 18:55:15 +01:00
|
|
|
substituteInPlace ./nixos-options.md \
|
2024-04-30 19:21:39 +02:00
|
|
|
--replace-fail \
|
2023-02-20 18:55:15 +01:00
|
|
|
'@NIXOS_OPTIONS_JSON@' \
|
2023-07-13 11:28:19 +02:00
|
|
|
${optionsDoc.optionsJSON}/${common.outputPath}/options.json
|
2023-02-20 18:55:15 +01:00
|
|
|
substituteInPlace ./development/writing-nixos-tests.section.md \
|
2024-04-30 19:21:39 +02:00
|
|
|
--replace-fail \
|
2023-02-20 18:55:15 +01:00
|
|
|
'@NIXOS_TEST_OPTIONS_JSON@' \
|
2023-07-13 11:28:19 +02:00
|
|
|
${testOptionsDoc.optionsJSON}/${common.outputPath}/options.json
|
2023-07-07 23:01:55 +02:00
|
|
|
sed -e '/@PYTHON_MACHINE_METHODS@/ {' -e 'r ${testDriverMachineDocstrings}/machine-methods.md' -e 'd' -e '}' \
|
|
|
|
-i ./development/writing-nixos-tests.section.md
|
2023-02-20 18:55:15 +01:00
|
|
|
'';
|
|
|
|
|
2010-08-11 12:28:53 +00: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 12:28:53 +00:00
|
|
|
# Generate the NixOS manual.
|
2018-09-06 19:17:44 +00:00
|
|
|
manualHTML =
|
|
|
|
runCommand "nixos-manual-html"
|
2023-06-11 20:36:29 +02:00
|
|
|
{
|
|
|
|
nativeBuildInputs = [ buildPackages.nixos-render-docs ];
|
2024-03-27 21:18:50 -07:00
|
|
|
inputs = sourceFilesBySuffices ./. [ ".md" ];
|
2016-09-27 15:26:37 +02:00
|
|
|
meta.description = "The NixOS manual in HTML format";
|
|
|
|
allowedReferences = [ "out" ];
|
|
|
|
}
|
|
|
|
''
|
2009-10-05 13:17:45 +00:00
|
|
|
# Generate the HTML manual.
|
2023-07-13 11:28:19 +02:00
|
|
|
dst=$out/${common.outputPath}
|
2014-06-30 14:56:10 +02:00
|
|
|
mkdir -p $dst
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2018-04-05 07:54:01 -04:00
|
|
|
cp ${../../../doc/style.css} $dst/style.css
|
2024-03-16 12:16:59 -07:00
|
|
|
cp ${../../../doc/anchor.min.js} $dst/anchor.min.js
|
|
|
|
cp ${../../../doc/anchor-use.js} $dst/anchor-use.js
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2018-04-05 07:54:01 -04:00
|
|
|
cp -r ${pkgs.documentation-highlighter} $dst/highlightjs
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2023-06-11 20:36:29 +02:00
|
|
|
${prepareManualFromMD}
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2023-06-11 20:36:29 +02:00
|
|
|
nixos-render-docs -j $NIX_BUILD_CORES manual html \
|
|
|
|
--manpage-urls ${manpageUrls} \
|
2025-05-31 19:54:53 +02:00
|
|
|
${if checkRedirects then "--redirects ${./redirects.json}" else ""} \
|
2024-03-27 21:18:50 -07:00
|
|
|
--revision ${escapeShellArg revision} \
|
|
|
|
--generator "nixos-render-docs ${pkgs.lib.version}" \
|
2023-06-11 20:36:29 +02:00
|
|
|
--stylesheet style.css \
|
|
|
|
--stylesheet highlightjs/mono-blue.css \
|
|
|
|
--script ./highlightjs/highlight.pack.js \
|
|
|
|
--script ./highlightjs/loader.js \
|
2024-03-16 12:16:59 -07:00
|
|
|
--script ./anchor.min.js \
|
|
|
|
--script ./anchor-use.js \
|
2023-06-11 20:36:29 +02:00
|
|
|
--toc-depth 1 \
|
|
|
|
--chunk-toc-depth 1 \
|
|
|
|
./manual.md \
|
2023-07-13 11:28:19 +02:00
|
|
|
$dst/${common.indexPath}
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2025-04-21 08:22:28 +02:00
|
|
|
cp ${pkgs.roboto.src}/web/Roboto\[ital\,wdth\,wght\].ttf "$dst/Roboto.ttf"
|
|
|
|
|
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 11:54:24 -04:00
|
|
|
''; # */
|
2013-10-24 20:06:02 +02:00
|
|
|
|
2018-09-06 19:17:44 +00:00
|
|
|
# Alias for backward compatibility. TODO(@oxij): remove eventually.
|
|
|
|
manual = manualHTML;
|
|
|
|
|
|
|
|
# Index page of the NixOS manual.
|
2023-07-13 11:28:19 +02:00
|
|
|
manualHTMLIndex = "${manualHTML}/${common.outputPath}/${common.indexPath}";
|
2010-08-11 12:28:53 +00: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>
|
2024-03-27 21:18:50 -07:00
|
|
|
<subtitle>Version ${pkgs.lib.version}</subtitle>
|
2023-06-11 19:26:30 +02:00
|
|
|
</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>
|
2025-04-01 20:10:43 +02:00
|
|
|
'';
|
2023-06-11 19:26:30 +02:00
|
|
|
passAsFile = [ "doc" ];
|
2025-04-01 20:10:43 +02:00
|
|
|
}
|
|
|
|
''
|
2016-07-28 04:27:39 +02:00
|
|
|
# Generate the epub manual.
|
2023-07-13 11:28:19 +02:00
|
|
|
dst=$out/${common.outputPath}
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2016-07-28 04:27:39 +02:00
|
|
|
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 16:11:16 -04:00
|
|
|
${docbook_xsl_ns}/xml/xsl/docbook/epub/docbook.xsl \
|
2025-04-01 20:10:43 +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" *
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2016-08-01 11:02:41 +02:00
|
|
|
rm -rf $dst/epub
|
2025-04-01 20:10:43 +02:00
|
|
|
|
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
|
2023-06-11 19:26:30 +02:00
|
|
|
'';
|
2010-08-11 12:28:53 +00:00
|
|
|
|
2023-08-16 06:24:37 +00:00
|
|
|
# Generate the `man configuration.nix` package
|
2023-08-12 18:47:43 +03:00
|
|
|
nixos-configuration-reference-manpage =
|
|
|
|
runCommand "nixos-configuration-reference-manpage"
|
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 13:17:45 +00:00
|
|
|
# Generate manpages.
|
2023-06-11 20:36:29 +02:00
|
|
|
mkdir -p $out/share/man/man5
|
|
|
|
nixos-render-docs -j $NIX_BUILD_CORES options manpage \
|
2024-03-27 21:18:50 -07:00
|
|
|
--revision ${escapeShellArg revision} \
|
2023-07-13 11:28:19 +02:00
|
|
|
${optionsJSON}/${common.outputPath}/options.json \
|
2023-06-11 20:36:29 +02:00
|
|
|
$out/share/man/man5/configuration.nix.5
|
2008-01-04 14:24:42 +00:00
|
|
|
'';
|
2015-09-24 11:47:00 +02:00
|
|
|
|
2011-09-14 18:20:50 +00:00
|
|
|
}
|