2022-07-12 12:33:52 +00:00
|
|
|
{ config, options, lib, pkgs, utils, modules, baseModules, extraModules, modulesPath, specialArgs, ... }:
|
2018-03-26 18:22:04 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2018-09-06 19:17:48 +00:00
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.documentation;
|
2021-11-18 23:26:27 +00:00
|
|
|
allOpts = options;
|
2018-09-06 19:17:48 +00:00
|
|
|
|
2021-11-18 23:26:27 +00:00
|
|
|
canCacheDocs = m:
|
|
|
|
let
|
|
|
|
f = import m;
|
|
|
|
instance = f (mapAttrs (n: _: abort "evaluating ${n} for `meta` failed") (functionArgs f));
|
|
|
|
in
|
2021-12-18 18:37:41 +00:00
|
|
|
cfg.nixos.options.splitBuild
|
2021-11-18 23:26:27 +00:00
|
|
|
&& builtins.isPath m
|
|
|
|
&& isFunction f
|
|
|
|
&& instance ? options
|
|
|
|
&& instance.meta.buildDocsInSandbox or true;
|
|
|
|
|
|
|
|
docModules =
|
|
|
|
let
|
2022-07-14 09:26:04 +00:00
|
|
|
p = partition canCacheDocs (baseModules ++ cfg.nixos.extraModules);
|
2021-11-18 23:26:27 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
lazy = p.right;
|
|
|
|
eager = p.wrong ++ optionals cfg.nixos.includeAllModules (extraModules ++ modules);
|
|
|
|
};
|
|
|
|
|
2018-09-06 19:17:48 +00:00
|
|
|
manual = import ../../doc/manual rec {
|
|
|
|
inherit pkgs config;
|
|
|
|
version = config.system.nixos.release;
|
|
|
|
revision = "release-${version}";
|
2019-11-13 01:29:30 +00:00
|
|
|
extraSources = cfg.nixos.extraModuleSources;
|
2018-09-06 19:17:48 +00:00
|
|
|
options =
|
|
|
|
let
|
2021-11-18 23:26:27 +00:00
|
|
|
scrubbedEval = evalModules {
|
|
|
|
modules = [ {
|
|
|
|
_module.check = false;
|
|
|
|
} ] ++ docModules.eager;
|
2022-07-12 12:33:52 +00:00
|
|
|
specialArgs = specialArgs // {
|
2021-11-18 23:26:27 +00: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 19:17:48 +00:00
|
|
|
};
|
|
|
|
scrubDerivations = namePrefix: pkgSet: mapAttrs
|
|
|
|
(name: value:
|
2022-11-03 14:56:27 +00:00
|
|
|
let
|
|
|
|
wholeName = "${namePrefix}.${name}";
|
|
|
|
guard = lib.warn "Attempt to evaluate package ${wholeName} in option documentation; this is not supported and will eventually be an error. Use `mkPackageOption` or `literalExpression` instead.";
|
|
|
|
in if isAttrs value then
|
2018-09-06 19:17:48 +00:00
|
|
|
scrubDerivations wholeName value
|
2022-11-03 14:56:27 +00:00
|
|
|
// optionalAttrs (isDerivation value) {
|
|
|
|
outPath = guard "\${${wholeName}}";
|
|
|
|
drvPath = guard drvPath;
|
|
|
|
}
|
2018-09-06 19:17:48 +00:00
|
|
|
else value
|
|
|
|
)
|
|
|
|
pkgSet;
|
|
|
|
in scrubbedEval.options;
|
2022-10-28 15:05:03 +00:00
|
|
|
|
2021-11-18 23:26:27 +00:00
|
|
|
baseOptionsJSON =
|
|
|
|
let
|
2022-01-27 11:33:10 +00:00
|
|
|
filter =
|
2021-11-18 23:26:27 +00:00
|
|
|
builtins.filterSource
|
|
|
|
(n: t:
|
2022-04-08 12:19:30 +00:00
|
|
|
cleanSourceFilter n t
|
|
|
|
&& (t == "directory" -> baseNameOf n != "tests")
|
2021-11-18 23:26:27 +00:00
|
|
|
&& (t == "file" -> hasSuffix ".nix" n)
|
|
|
|
);
|
|
|
|
in
|
|
|
|
pkgs.runCommand "lazy-options.json" {
|
2022-10-28 15:05:03 +00:00
|
|
|
libPath = filter (pkgs.path + "/lib");
|
|
|
|
pkgsLibPath = filter (pkgs.path + "/pkgs/pkgs-lib");
|
|
|
|
nixosPath = filter (pkgs.path + "/nixos");
|
2021-11-18 23:26:27 +00:00
|
|
|
modules = map (p: ''"${removePrefix "${modulesPath}/" (toString p)}"'') docModules.lazy;
|
2022-12-18 22:35:29 +00:00
|
|
|
nativeBuildInputs = with pkgs; [ nix ];
|
2021-11-18 23:26:27 +00:00
|
|
|
} ''
|
|
|
|
export NIX_STORE_DIR=$TMPDIR/store
|
|
|
|
export NIX_STATE_DIR=$TMPDIR/state
|
2022-12-18 22:35:29 +00:00
|
|
|
nix-instantiate \
|
2021-11-18 23:26:27 +00: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 15:05:03 +00:00
|
|
|
|
2022-09-01 17:23:59 +00:00
|
|
|
inherit (cfg.nixos.options) warningsAreErrors allowDocBook;
|
2018-09-06 19:17:48 +00:00
|
|
|
};
|
|
|
|
|
2020-11-05 10:51:02 +00:00
|
|
|
|
|
|
|
nixos-help = let
|
|
|
|
helpScript = pkgs.writeShellScriptBin "nixos-help" ''
|
2018-09-06 19:17:48 +00: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 15:20:19 +00:00
|
|
|
browser="${pkgs.w3m-nographics}/bin/w3m"
|
2018-09-06 19:17:48 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
exec "$browser" ${manual.manualHTMLIndex}
|
|
|
|
'';
|
|
|
|
|
2020-11-05 10:51:02 +00: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 14:56:15 +00:00
|
|
|
categories = ["System"];
|
2020-11-05 10:51:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
in pkgs.symlinkJoin {
|
|
|
|
name = "nixos-help";
|
|
|
|
paths = [
|
|
|
|
helpScript
|
|
|
|
desktopItem
|
|
|
|
];
|
|
|
|
};
|
2018-09-06 19:17:48 +00:00
|
|
|
|
|
|
|
in
|
2018-03-26 18:22:04 +00:00
|
|
|
|
|
|
|
{
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
2022-07-14 09:28:21 +00:00
|
|
|
./man-db.nix
|
|
|
|
./mandoc.nix
|
|
|
|
./assertions.nix
|
|
|
|
./meta.nix
|
|
|
|
../config/system-path.nix
|
|
|
|
../system/etc/etc.nix
|
2019-12-10 01:51:19 +00: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 18:22:04 +00:00
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
documentation = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-05 17:39:00 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-03-26 18:22:04 +00:00
|
|
|
Whether to install documentation of packages from
|
2022-08-05 17:39:00 +00:00
|
|
|
{option}`environment.systemPackages` into the generated system path.
|
2018-04-05 22:20:46 +00:00
|
|
|
|
|
|
|
See "Multiple-output packages" chapter in the nixpkgs manual for more info.
|
2018-03-26 18:22:04 +00:00
|
|
|
'';
|
2021-02-21 06:16:37 +00:00
|
|
|
# which is at ../../../doc/multiple-output.chapter.md
|
2018-03-26 18:22:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
man.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-05 17:39:00 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-09-24 17:20:23 +00:00
|
|
|
Whether to install manual pages.
|
2022-08-05 17:39:00 +00:00
|
|
|
This also includes `man` outputs.
|
2018-03-26 18:22:04 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-05-01 16:48:39 +00:00
|
|
|
man.generateCaches = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-06-03 19:47:57 +00:00
|
|
|
description = mdDoc ''
|
2021-09-24 17:20:23 +00:00
|
|
|
Whether to generate the manual page index caches.
|
|
|
|
This allows searching for a page or
|
2022-06-03 19:47:57 +00:00
|
|
|
keyword using utilities like {manpage}`apropos(1)`
|
|
|
|
and the `-k` option of
|
|
|
|
{manpage}`man(1)`.
|
2020-05-01 16:48:39 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-05 22:20:46 +00:00
|
|
|
info.enable = mkOption {
|
2018-03-26 18:22:04 +00:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-05 17:39:00 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Whether to install info pages and the {command}`info` command.
|
2018-04-05 22:20:46 +00:00
|
|
|
This also includes "info" outputs.
|
2018-03-26 18:22:04 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-05 22:20:46 +00:00
|
|
|
doc.enable = mkOption {
|
2018-03-26 18:22:04 +00:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-05 17:39:00 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Whether to install documentation distributed in packages' `/share/doc`.
|
2018-04-05 22:20:46 +00:00
|
|
|
Usually plain text and/or HTML.
|
|
|
|
This also includes "doc" outputs.
|
2018-03-26 18:22:04 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-04-05 22:27:46 +00:00
|
|
|
dev.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-06-03 19:47:57 +00:00
|
|
|
description = mdDoc ''
|
2018-04-05 22:27:46 +00:00
|
|
|
Whether to install documentation targeted at developers.
|
2022-06-03 19:47:57 +00: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-05 22:27:46 +00:00
|
|
|
'';
|
|
|
|
};
|
2018-04-05 22:20:46 +00:00
|
|
|
|
2018-09-06 19:17:48 +00:00
|
|
|
nixos.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-29 21:34:22 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-09-06 19:17:48 +00:00
|
|
|
Whether to install NixOS's own documentation.
|
2022-08-29 21:34:22 +00: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 19:17:48 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-07-14 09:26:04 +00:00
|
|
|
nixos.extraModules = mkOption {
|
|
|
|
type = types.listOf types.raw;
|
|
|
|
default = [];
|
2022-08-15 05:16:25 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-14 09:26:04 +00:00
|
|
|
Modules for which to show options even when not imported.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-12-18 18:37:41 +00:00
|
|
|
nixos.options.splitBuild = mkOption {
|
2021-11-18 23:26:27 +00:00
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-05 17:39:00 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-11-18 23:26:27 +00: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 17:23:59 +00: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 18:37:41 +00:00
|
|
|
nixos.options.warningsAreErrors = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-05 17:39:00 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-12-18 18:37:41 +00:00
|
|
|
Treat warning emitted during the option documentation build (eg for missing option
|
|
|
|
descriptions) as errors.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-09-23 19:34:36 +00:00
|
|
|
nixos.includeAllModules = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-05 17:39:00 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-09-23 19:34:36 +00: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 17:39:00 +00:00
|
|
|
`configuration.nix`. Disabling this will make the manual
|
|
|
|
generator to ignore options defined outside of `baseModules`.
|
2018-09-23 19:34:36 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-11-13 01:29:30 +00:00
|
|
|
nixos.extraModuleSources = mkOption {
|
|
|
|
type = types.listOf (types.either types.path types.str);
|
|
|
|
default = [ ];
|
2022-08-05 17:39:00 +00:00
|
|
|
description = lib.mdDoc ''
|
2019-11-13 01:29:30 +00:00
|
|
|
Which extra NixOS module paths the generated NixOS's documentation should strip
|
|
|
|
from options.
|
|
|
|
'';
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression ''
|
2019-11-13 01:29:30 +00:00
|
|
|
# e.g. with options from modules in ''${pkgs.customModules}/nix:
|
|
|
|
[ pkgs.customModules ]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-03-26 18:22:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
2021-09-19 17:51:03 +00: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 18:22:04 +00:00
|
|
|
|
2021-09-19 17:51:03 +00:00
|
|
|
# The actual implementation for this lives in man-db.nix or mandoc.nix,
|
|
|
|
# depending on which backend is active.
|
2018-03-26 18:22:04 +00:00
|
|
|
(mkIf cfg.man.enable {
|
|
|
|
environment.pathsToLink = [ "/share/man" ];
|
2021-09-24 17:20:23 +00:00
|
|
|
environment.extraOutputsToInstall = [ "man" ] ++ optional cfg.dev.enable "devman";
|
2018-03-26 18:22:04 +00:00
|
|
|
})
|
|
|
|
|
2018-04-05 22:20:46 +00:00
|
|
|
(mkIf cfg.info.enable {
|
|
|
|
environment.systemPackages = [ pkgs.texinfoInteractive ];
|
|
|
|
environment.pathsToLink = [ "/share/info" ];
|
2018-05-05 08:41:28 +00:00
|
|
|
environment.extraOutputsToInstall = [ "info" ] ++ optional cfg.dev.enable "devinfo";
|
2018-08-15 09:59:44 +00: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 01:16:50 +00:00
|
|
|
${pkgs.buildPackages.texinfo}/bin/install-info $i $out/share/info/dir
|
2018-08-15 09:59:44 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
'';
|
2018-04-05 22:20:46 +00:00
|
|
|
})
|
|
|
|
|
2018-03-26 18:22:04 +00:00
|
|
|
(mkIf cfg.doc.enable {
|
|
|
|
environment.pathsToLink = [ "/share/doc" ];
|
2018-05-05 08:41:28 +00:00
|
|
|
environment.extraOutputsToInstall = [ "doc" ] ++ optional cfg.dev.enable "devdoc";
|
2018-03-26 18:22:04 +00:00
|
|
|
})
|
|
|
|
|
2018-09-06 19:17:48 +00:00
|
|
|
(mkIf cfg.nixos.enable {
|
|
|
|
system.build.manual = manual;
|
|
|
|
|
|
|
|
environment.systemPackages = []
|
|
|
|
++ optional cfg.man.enable manual.manpages
|
2021-07-24 04:50:01 +00:00
|
|
|
++ optionals cfg.doc.enable [ manual.manualHTML nixos-help ];
|
2018-09-06 19:17:48 +00:00
|
|
|
})
|
|
|
|
|
2018-03-26 18:22:04 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
}
|