2022-07-12 14:33:52 +02:00
|
|
|
{ config, options, lib, pkgs, utils, modules, baseModules, extraModules, modulesPath, specialArgs, ... }:
|
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-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
|
2022-07-14 11:26:04 +02:00
|
|
|
p = partition canCacheDocs (baseModules ++ cfg.nixos.extraModules);
|
2021-11-19 00:26:27 +01:00
|
|
|
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;
|
2022-07-12 14:33:52 +02:00
|
|
|
specialArgs = specialArgs // {
|
2021-11-19 00:26:27 +01:00
|
|
|
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:
|
2022-11-03 15:56:27 +01:00
|
|
|
let
|
|
|
|
wholeName = "${namePrefix}.${name}";
|
2022-12-30 21:04:52 +01:00
|
|
|
guard = lib.warn "Attempt to evaluate package ${wholeName} in option documentation; this is not supported and will eventually be an error. Use `mkPackageOption{,MD}` or `literalExpression` instead.";
|
2022-11-03 15:56:27 +01:00
|
|
|
in if isAttrs value then
|
2018-09-06 21:17:48 +02:00
|
|
|
scrubDerivations wholeName value
|
2022-11-03 15:56:27 +01:00
|
|
|
// optionalAttrs (isDerivation value) {
|
|
|
|
outPath = guard "\${${wholeName}}";
|
|
|
|
drvPath = guard drvPath;
|
|
|
|
}
|
2018-09-06 21:17:48 +02:00
|
|
|
else value
|
|
|
|
)
|
|
|
|
pkgSet;
|
|
|
|
in scrubbedEval.options;
|
2022-10-28 17:05:03 +02:00
|
|
|
|
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-10-28 17:05:03 +02:00
|
|
|
libPath = filter (pkgs.path + "/lib");
|
|
|
|
pkgsLibPath = filter (pkgs.path + "/pkgs/pkgs-lib");
|
|
|
|
nixosPath = filter (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-12-26 19:05:35 +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
|
|
|
|
'';
|
2022-10-28 17:05:03 +02:00
|
|
|
|
2022-09-01 19:23:59 +02:00
|
|
|
inherit (cfg.nixos.options) warningsAreErrors allowDocBook;
|
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 = [
|
2022-07-14 11:28:21 +02:00
|
|
|
./man-db.nix
|
|
|
|
./mandoc.nix
|
|
|
|
./assertions.nix
|
|
|
|
./meta.nix
|
|
|
|
../config/system-path.nix
|
|
|
|
../system/etc/etc.nix
|
2019-12-10 02:51:19 +01:00
|
|
|
(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;
|
2022-08-05 19:39:00 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-03-26 20:22:04 +02:00
|
|
|
Whether to install documentation of packages from
|
2022-08-05 19:39:00 +02:00
|
|
|
{option}`environment.systemPackages` 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;
|
2022-08-05 19:39:00 +02:00
|
|
|
description = lib.mdDoc ''
|
2021-09-24 19:20:23 +02:00
|
|
|
Whether to install manual pages.
|
2022-08-05 19:39:00 +02:00
|
|
|
This also includes `man` 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;
|
2022-08-05 19:39:00 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Whether to install info pages and the {command}`info` command.
|
2018-04-06 00:20:46 +02:00
|
|
|
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;
|
2022-08-05 19:39:00 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Whether to install documentation distributed in packages' `/share/doc`.
|
2018-04-06 00:20:46 +02:00
|
|
|
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;
|
2022-08-29 23:34:22 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-09-06 21:17:48 +02:00
|
|
|
Whether to install NixOS's own documentation.
|
2022-08-29 23:34:22 +02:00
|
|
|
|
|
|
|
- This includes man pages like
|
|
|
|
{manpage}`configuration.nix(5)` if {option}`documentation.man.enable` is
|
|
|
|
set.
|
|
|
|
- This includes the HTML manual and the {command}`nixos-help` command if
|
|
|
|
{option}`documentation.doc.enable` is set.
|
2018-09-06 21:17:48 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-07-14 11:26:04 +02:00
|
|
|
nixos.extraModules = mkOption {
|
|
|
|
type = types.listOf types.raw;
|
|
|
|
default = [];
|
2022-08-15 07:16:25 +02:00
|
|
|
description = lib.mdDoc ''
|
2022-07-14 11:26:04 +02:00
|
|
|
Modules for which to show options even when not imported.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
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;
|
2022-08-05 19:39:00 +02:00
|
|
|
description = lib.mdDoc ''
|
2021-11-19 00:26:27 +01:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-09-01 19:23:59 +02:00
|
|
|
nixos.options.allowDocBook = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Whether to allow DocBook option docs. When set to `false` all option using
|
|
|
|
DocBook documentation will cause a manual build error; additionally a new
|
|
|
|
renderer may be used.
|
|
|
|
|
|
|
|
::: {.note}
|
|
|
|
The `false` setting for this option is not yet fully supported. While it
|
|
|
|
should work fine and produce the same output as the previous toolchain
|
|
|
|
using DocBook it may not work in all circumstances. Whether markdown option
|
|
|
|
documentation is allowed is independent of this option.
|
|
|
|
:::
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-12-18 19:37:41 +01:00
|
|
|
nixos.options.warningsAreErrors = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-05 19:39:00 +02:00
|
|
|
description = lib.mdDoc ''
|
2021-12-18 19:37:41 +01:00
|
|
|
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;
|
2022-08-05 19:39:00 +02:00
|
|
|
description = lib.mdDoc ''
|
2018-09-23 21:34:36 +02:00
|
|
|
Whether the generated NixOS's documentation should include documentation for all
|
|
|
|
the options from all the NixOS modules included in the current
|
2022-08-05 19:39:00 +02:00
|
|
|
`configuration.nix`. Disabling this will make the manual
|
|
|
|
generator to ignore options defined outside of `baseModules`.
|
2018-09-23 21:34:36 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-11-13 02:29:30 +01:00
|
|
|
nixos.extraModuleSources = mkOption {
|
|
|
|
type = types.listOf (types.either types.path types.str);
|
|
|
|
default = [ ];
|
2022-08-05 19:39:00 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-11-13 02:29:30 +01:00
|
|
|
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;
|
|
|
|
|
2023-01-15 14:56:46 +01:00
|
|
|
system.activationScripts.check-manual-docbook = ''
|
|
|
|
if [[ $(cat ${manual.optionsUsedDocbook}) = 1 ]]; then
|
|
|
|
echo -e "\e[31;1mwarning\e[0m: This configuration contains option documentation in docbook." \
|
|
|
|
"Support for docbook is deprecated and will be removed after NixOS 23.05." \
|
|
|
|
"See nix-store --read-log ${builtins.unsafeDiscardStringContext manual.optionsJSON.drvPath}"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2018-09-06 21:17:48 +02:00
|
|
|
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
|
|
|
})
|
|
|
|
|
2018-03-26 20:22:04 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
}
|