2021-11-19 00:26:27 +01:00
|
|
|
{ config, options, lib, pkgs, utils, modules, baseModules, extraModules, modulesPath, ... }:
|
2018-03-26 20:22:04 +02:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2018-09-06 21:17:48 +02:00
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.documentation;
|
2021-11-19 00:26:27 +01:00
|
|
|
allOpts = options;
|
2018-09-06 21:17:48 +02:00
|
|
|
|
2021-12-02 19:19:56 +01:00
|
|
|
/* Modules for which to show options even when not imported. */
|
|
|
|
extraDocModules = [ ../virtualisation/qemu-vm.nix ];
|
2018-09-23 21:34:36 +02:00
|
|
|
|
2021-11-19 00:26:27 +01:00
|
|
|
canCacheDocs = m:
|
|
|
|
let
|
|
|
|
f = import m;
|
|
|
|
instance = f (mapAttrs (n: _: abort "evaluating ${n} for `meta` failed") (functionArgs f));
|
|
|
|
in
|
2021-12-18 19:37:41 +01:00
|
|
|
cfg.nixos.options.splitBuild
|
2021-11-19 00:26:27 +01:00
|
|
|
&& builtins.isPath m
|
|
|
|
&& isFunction f
|
|
|
|
&& instance ? options
|
|
|
|
&& instance.meta.buildDocsInSandbox or true;
|
|
|
|
|
|
|
|
docModules =
|
|
|
|
let
|
|
|
|
p = partition canCacheDocs (baseModules ++ extraDocModules);
|
|
|
|
in
|
|
|
|
{
|
|
|
|
lazy = p.right;
|
|
|
|
eager = p.wrong ++ optionals cfg.nixos.includeAllModules (extraModules ++ modules);
|
|
|
|
};
|
|
|
|
|
2018-09-06 21:17:48 +02:00
|
|
|
manual = import ../../doc/manual rec {
|
|
|
|
inherit pkgs config;
|
|
|
|
version = config.system.nixos.release;
|
|
|
|
revision = "release-${version}";
|
2019-11-13 02:29:30 +01:00
|
|
|
extraSources = cfg.nixos.extraModuleSources;
|
2018-09-06 21:17:48 +02:00
|
|
|
options =
|
|
|
|
let
|
2021-11-19 00:26:27 +01:00
|
|
|
scrubbedEval = evalModules {
|
|
|
|
modules = [ {
|
|
|
|
_module.check = false;
|
|
|
|
} ] ++ docModules.eager;
|
|
|
|
specialArgs = {
|
|
|
|
pkgs = scrubDerivations "pkgs" pkgs;
|
|
|
|
# allow access to arbitrary options for eager modules, eg for getting
|
|
|
|
# option types from lazy modules
|
|
|
|
options = allOpts;
|
|
|
|
inherit modulesPath utils;
|
|
|
|
};
|
2018-09-06 21:17:48 +02:00
|
|
|
};
|
|
|
|
scrubDerivations = namePrefix: pkgSet: mapAttrs
|
|
|
|
(name: value:
|
|
|
|
let wholeName = "${namePrefix}.${name}"; in
|
|
|
|
if isAttrs value then
|
|
|
|
scrubDerivations wholeName value
|
|
|
|
// (optionalAttrs (isDerivation value) { outPath = "\${${wholeName}}"; })
|
|
|
|
else value
|
|
|
|
)
|
|
|
|
pkgSet;
|
|
|
|
in scrubbedEval.options;
|
2021-11-19 00:26:27 +01:00
|
|
|
baseOptionsJSON =
|
|
|
|
let
|
2022-01-27 12:33:10 +01:00
|
|
|
filter =
|
2021-11-19 00:26:27 +01:00
|
|
|
builtins.filterSource
|
|
|
|
(n: t:
|
2022-04-08 14:19:30 +02:00
|
|
|
cleanSourceFilter n t
|
|
|
|
&& (t == "directory" -> baseNameOf n != "tests")
|
2021-11-19 00:26:27 +01:00
|
|
|
&& (t == "file" -> hasSuffix ".nix" n)
|
|
|
|
);
|
|
|
|
in
|
|
|
|
pkgs.runCommand "lazy-options.json" {
|
2022-01-27 12:33:16 +01:00
|
|
|
libPath = filter "${toString pkgs.path}/lib";
|
|
|
|
pkgsLibPath = filter "${toString pkgs.path}/pkgs/pkgs-lib";
|
|
|
|
nixosPath = filter "${toString pkgs.path}/nixos";
|
2021-11-19 00:26:27 +01:00
|
|
|
modules = map (p: ''"${removePrefix "${modulesPath}/" (toString p)}"'') docModules.lazy;
|
|
|
|
} ''
|
|
|
|
export NIX_STORE_DIR=$TMPDIR/store
|
|
|
|
export NIX_STATE_DIR=$TMPDIR/state
|
2022-01-08 16:03:23 +01:00
|
|
|
${pkgs.buildPackages.nix}/bin/nix-instantiate \
|
2021-11-19 00:26:27 +01:00
|
|
|
--show-trace \
|
|
|
|
--eval --json --strict \
|
|
|
|
--argstr libPath "$libPath" \
|
|
|
|
--argstr pkgsLibPath "$pkgsLibPath" \
|
|
|
|
--argstr nixosPath "$nixosPath" \
|
|
|
|
--arg modules "[ $modules ]" \
|
|
|
|
--argstr stateVersion "${options.system.stateVersion.default}" \
|
|
|
|
--argstr release "${config.system.nixos.release}" \
|
|
|
|
$nixosPath/lib/eval-cacheable-options.nix > $out \
|
|
|
|
|| {
|
|
|
|
echo -en "\e[1;31m"
|
|
|
|
echo 'Cacheable portion of option doc build failed.'
|
|
|
|
echo 'Usually this means that an option attribute that ends up in documentation (eg' \
|
|
|
|
'`default` or `description`) depends on the restricted module arguments' \
|
|
|
|
'`config` or `pkgs`.'
|
|
|
|
echo
|
|
|
|
echo 'Rebuild your configuration with `--show-trace` to find the offending' \
|
|
|
|
'location. Remove the references to restricted arguments (eg by escaping' \
|
|
|
|
'their antiquotations or adding a `defaultText`) or disable the sandboxed' \
|
|
|
|
'build for the failing module by setting `meta.buildDocsInSandbox = false`.'
|
|
|
|
echo -en "\e[0m"
|
|
|
|
exit 1
|
|
|
|
} >&2
|
|
|
|
'';
|
2021-12-18 19:37:41 +01:00
|
|
|
inherit (cfg.nixos.options) warningsAreErrors;
|
2018-09-06 21:17:48 +02:00
|
|
|
};
|
|
|
|
|
2020-11-05 11:51:02 +01:00
|
|
|
|
|
|
|
nixos-help = let
|
|
|
|
helpScript = pkgs.writeShellScriptBin "nixos-help" ''
|
2018-09-06 21:17:48 +02:00
|
|
|
# Finds first executable browser in a colon-separated list.
|
|
|
|
# (see how xdg-open defines BROWSER)
|
|
|
|
browser="$(
|
|
|
|
IFS=: ; for b in $BROWSER; do
|
|
|
|
[ -n "$(type -P "$b" || true)" ] && echo "$b" && break
|
|
|
|
done
|
|
|
|
)"
|
|
|
|
if [ -z "$browser" ]; then
|
|
|
|
browser="$(type -P xdg-open || true)"
|
|
|
|
if [ -z "$browser" ]; then
|
2019-06-01 17:20:19 +02:00
|
|
|
browser="${pkgs.w3m-nographics}/bin/w3m"
|
2018-09-06 21:17:48 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
exec "$browser" ${manual.manualHTMLIndex}
|
|
|
|
'';
|
|
|
|
|
2020-11-05 11:51:02 +01:00
|
|
|
desktopItem = pkgs.makeDesktopItem {
|
|
|
|
name = "nixos-manual";
|
|
|
|
desktopName = "NixOS Manual";
|
|
|
|
genericName = "View NixOS documentation in a web browser";
|
|
|
|
icon = "nix-snowflake";
|
|
|
|
exec = "nixos-help";
|
2022-02-22 15:56:15 +01:00
|
|
|
categories = ["System"];
|
2020-11-05 11:51:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
in pkgs.symlinkJoin {
|
|
|
|
name = "nixos-help";
|
|
|
|
paths = [
|
|
|
|
helpScript
|
|
|
|
desktopItem
|
|
|
|
];
|
|
|
|
};
|
2018-09-06 21:17:48 +02:00
|
|
|
|
|
|
|
in
|
2018-03-26 20:22:04 +02:00
|
|
|
|
|
|
|
{
|
2019-12-10 02:51:19 +01:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "programs" "info" "enable" ] [ "documentation" "info" "enable" ])
|
|
|
|
(mkRenamedOptionModule [ "programs" "man" "enable" ] [ "documentation" "man" "enable" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "nixosManual" "enable" ] [ "documentation" "nixos" "enable" ])
|
|
|
|
];
|
2018-03-26 20:22:04 +02:00
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
documentation = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to install documentation of packages from
|
|
|
|
<option>environment.systemPackages</option> into the generated system path.
|
2018-04-06 00:20:46 +02:00
|
|
|
|
|
|
|
See "Multiple-output packages" chapter in the nixpkgs manual for more info.
|
2018-03-26 20:22:04 +02:00
|
|
|
'';
|
2021-02-21 07:16:37 +01:00
|
|
|
# which is at ../../../doc/multiple-output.chapter.md
|
2018-03-26 20:22:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
man.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
2021-09-24 19:20:23 +02:00
|
|
|
Whether to install manual pages.
|
|
|
|
This also includes <literal>man</literal> outputs.
|
2018-03-26 20:22:04 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-05-01 18:48:39 +02:00
|
|
|
man.generateCaches = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-06-03 21:47:57 +02:00
|
|
|
description = mdDoc ''
|
2021-09-24 19:20:23 +02:00
|
|
|
Whether to generate the manual page index caches.
|
|
|
|
This allows searching for a page or
|
2022-06-03 21:47:57 +02:00
|
|
|
keyword using utilities like {manpage}`apropos(1)`
|
|
|
|
and the `-k` option of
|
|
|
|
{manpage}`man(1)`.
|
2020-05-01 18:48:39 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-06 00:20:46 +02:00
|
|
|
info.enable = mkOption {
|
2018-03-26 20:22:04 +02:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
2018-04-06 00:20:46 +02:00
|
|
|
Whether to install info pages and the <command>info</command> command.
|
|
|
|
This also includes "info" outputs.
|
2018-03-26 20:22:04 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-06 00:20:46 +02:00
|
|
|
doc.enable = mkOption {
|
2018-03-26 20:22:04 +02:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
2018-04-06 00:20:46 +02:00
|
|
|
Whether to install documentation distributed in packages' <literal>/share/doc</literal>.
|
|
|
|
Usually plain text and/or HTML.
|
|
|
|
This also includes "doc" outputs.
|
2018-03-26 20:22:04 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-06 00:27:46 +02:00
|
|
|
dev.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-06-03 21:47:57 +02:00
|
|
|
description = mdDoc ''
|
2018-04-06 00:27:46 +02:00
|
|
|
Whether to install documentation targeted at developers.
|
2022-06-03 21:47:57 +02:00
|
|
|
* This includes man pages targeted at developers if {option}`documentation.man.enable` is
|
|
|
|
set (this also includes "devman" outputs).
|
|
|
|
* This includes info pages targeted at developers if {option}`documentation.info.enable`
|
|
|
|
is set (this also includes "devinfo" outputs).
|
|
|
|
* This includes other pages targeted at developers if {option}`documentation.doc.enable`
|
|
|
|
is set (this also includes "devdoc" outputs).
|
2018-04-06 00:27:46 +02:00
|
|
|
'';
|
|
|
|
};
|
2018-04-06 00:20:46 +02:00
|
|
|
|
2018-09-06 21:17:48 +02:00
|
|
|
nixos.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to install NixOS's own documentation.
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem><para>This includes man pages like
|
|
|
|
<citerefentry><refentrytitle>configuration.nix</refentrytitle>
|
2021-09-15 22:43:44 +02:00
|
|
|
<manvolnum>5</manvolnum></citerefentry> if <option>documentation.man.enable</option> is
|
2018-09-06 21:17:48 +02:00
|
|
|
set.</para></listitem>
|
|
|
|
<listitem><para>This includes the HTML manual and the <command>nixos-help</command> command if
|
2021-09-15 22:43:44 +02:00
|
|
|
<option>documentation.doc.enable</option> is set.</para></listitem>
|
2018-09-06 21:17:48 +02:00
|
|
|
</itemizedlist>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-12-18 19:37:41 +01:00
|
|
|
nixos.options.splitBuild = mkOption {
|
2021-11-19 00:26:27 +01:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to split the option docs build into a cacheable and an uncacheable part.
|
|
|
|
Splitting the build can substantially decrease the amount of time needed to build
|
|
|
|
the manual, but some user modules may be incompatible with this splitting.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-12-18 19:37:41 +01:00
|
|
|
nixos.options.warningsAreErrors = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Treat warning emitted during the option documentation build (eg for missing option
|
|
|
|
descriptions) as errors.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-09-23 21:34:36 +02:00
|
|
|
nixos.includeAllModules = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether the generated NixOS's documentation should include documentation for all
|
|
|
|
the options from all the NixOS modules included in the current
|
|
|
|
<literal>configuration.nix</literal>. Disabling this will make the manual
|
|
|
|
generator to ignore options defined outside of <literal>baseModules</literal>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-11-13 02:29:30 +01:00
|
|
|
nixos.extraModuleSources = mkOption {
|
|
|
|
type = types.listOf (types.either types.path types.str);
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Which extra NixOS module paths the generated NixOS's documentation should strip
|
|
|
|
from options.
|
|
|
|
'';
|
2021-10-03 18:06:03 +02:00
|
|
|
example = literalExpression ''
|
2019-11-13 02:29:30 +01:00
|
|
|
# e.g. with options from modules in ''${pkgs.customModules}/nix:
|
|
|
|
[ pkgs.customModules ]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-03-26 20:22:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
2021-09-19 19:51:03 +02:00
|
|
|
{
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = !(cfg.man.man-db.enable && cfg.man.mandoc.enable);
|
|
|
|
message = ''
|
|
|
|
man-db and mandoc can't be used as the default man page viewer at the same time!
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
2018-03-26 20:22:04 +02:00
|
|
|
|
2021-09-19 19:51:03 +02:00
|
|
|
# The actual implementation for this lives in man-db.nix or mandoc.nix,
|
|
|
|
# depending on which backend is active.
|
2018-03-26 20:22:04 +02:00
|
|
|
(mkIf cfg.man.enable {
|
|
|
|
environment.pathsToLink = [ "/share/man" ];
|
2021-09-24 19:20:23 +02:00
|
|
|
environment.extraOutputsToInstall = [ "man" ] ++ optional cfg.dev.enable "devman";
|
2018-03-26 20:22:04 +02:00
|
|
|
})
|
|
|
|
|
2018-04-06 00:20:46 +02:00
|
|
|
(mkIf cfg.info.enable {
|
|
|
|
environment.systemPackages = [ pkgs.texinfoInteractive ];
|
|
|
|
environment.pathsToLink = [ "/share/info" ];
|
2018-05-05 10:41:28 +02:00
|
|
|
environment.extraOutputsToInstall = [ "info" ] ++ optional cfg.dev.enable "devinfo";
|
2018-08-15 11:59:44 +02:00
|
|
|
environment.extraSetup = ''
|
|
|
|
if [ -w $out/share/info ]; then
|
|
|
|
shopt -s nullglob
|
|
|
|
for i in $out/share/info/*.info $out/share/info/*.info.gz; do
|
2018-10-12 03:16:50 +02:00
|
|
|
${pkgs.buildPackages.texinfo}/bin/install-info $i $out/share/info/dir
|
2018-08-15 11:59:44 +02:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
'';
|
2018-04-06 00:20:46 +02:00
|
|
|
})
|
|
|
|
|
2018-03-26 20:22:04 +02:00
|
|
|
(mkIf cfg.doc.enable {
|
|
|
|
environment.pathsToLink = [ "/share/doc" ];
|
2018-05-05 10:41:28 +02:00
|
|
|
environment.extraOutputsToInstall = [ "doc" ] ++ optional cfg.dev.enable "devdoc";
|
2018-03-26 20:22:04 +02:00
|
|
|
})
|
|
|
|
|
2018-09-06 21:17:48 +02:00
|
|
|
(mkIf cfg.nixos.enable {
|
|
|
|
system.build.manual = manual;
|
|
|
|
|
|
|
|
environment.systemPackages = []
|
|
|
|
++ optional cfg.man.enable manual.manpages
|
2021-07-24 06:50:01 +02:00
|
|
|
++ optionals cfg.doc.enable [ manual.manualHTML nixos-help ];
|
2018-09-06 21:17:48 +02:00
|
|
|
|
2021-01-05 09:25:53 +01:00
|
|
|
services.getty.helpLine = mkIf cfg.doc.enable (
|
2020-03-23 10:29:12 +01:00
|
|
|
"\nRun 'nixos-help' for the NixOS manual."
|
2018-09-06 21:17:48 +02:00
|
|
|
);
|
|
|
|
})
|
|
|
|
|
2018-03-26 20:22:04 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
}
|