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