···
1
-
{ config, lib, pkgs, extendModules, noUserModules, ... }:
1
+
{ config, options, lib, pkgs, utils, modules, baseModules, extraModules, modulesPath, ... }:
cfg = config.documentation;
/* Modules for which to show options even when not imported. */
extraDocModules = [ ../virtualisation/qemu-vm.nix ];
12
-
/* For the purpose of generating docs, evaluate options with each derivation
13
-
in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}".
14
-
It isn't perfect, but it seems to cover a vast majority of use cases.
15
-
Caveat: even if the package is reached by a different means,
16
-
the path above will be shown and not e.g. `${config.services.foo.package}`. */
16
+
instance = f (mapAttrs (n: _: abort "evaluating ${n} for `meta` failed") (functionArgs f));
18
+
cfg.nixos.splitOptionDocBuild
19
+
&& builtins.isPath m
21
+
&& instance ? options
22
+
&& instance.meta.buildDocsInSandbox or true;
26
+
p = partition canCacheDocs (baseModules ++ extraDocModules);
30
+
eager = p.wrong ++ optionals cfg.nixos.includeAllModules (extraModules ++ modules);
manual = import ../../doc/manual rec {
version = config.system.nixos.release;
···
extraSources = cfg.nixos.extraModuleSources;
24
-
extendNixOS = if cfg.nixos.includeAllModules then extendModules else noUserModules.extendModules;
25
-
scrubbedEval = extendNixOS {
26
-
modules = extraDocModules;
27
-
specialArgs.pkgs = scrubDerivations "pkgs" pkgs;
40
+
scrubbedEval = evalModules {
42
+
_module.check = false;
43
+
} ] ++ docModules.eager;
45
+
pkgs = scrubDerivations "pkgs" pkgs;
46
+
# allow access to arbitrary options for eager modules, eg for getting
47
+
# option types from lazy modules
49
+
inherit modulesPath utils;
scrubDerivations = namePrefix: pkgSet: mapAttrs
···
65
+
builtins.filterSource
67
+
(t == "directory" -> baseNameOf n != "tests")
68
+
&& (t == "file" -> hasSuffix ".nix" n)
71
+
pkgs.runCommand "lazy-options.json" {
72
+
libPath = filter "${toString pkgs.path}/lib";
73
+
pkgsLibPath = filter "${toString pkgs.path}/pkgs/pkgs-lib";
74
+
nixosPath = filter "${toString pkgs.path}/nixos";
75
+
modules = map (p: ''"${removePrefix "${modulesPath}/" (toString p)}"'') docModules.lazy;
77
+
export NIX_STORE_DIR=$TMPDIR/store
78
+
export NIX_STATE_DIR=$TMPDIR/state
79
+
${pkgs.nix}/bin/nix-instantiate \
81
+
--eval --json --strict \
82
+
--argstr libPath "$libPath" \
83
+
--argstr pkgsLibPath "$pkgsLibPath" \
84
+
--argstr nixosPath "$nixosPath" \
85
+
--arg modules "[ $modules ]" \
86
+
--argstr stateVersion "${options.system.stateVersion.default}" \
87
+
--argstr release "${config.system.nixos.release}" \
88
+
$nixosPath/lib/eval-cacheable-options.nix > $out \
91
+
echo 'Cacheable portion of option doc build failed.'
92
+
echo 'Usually this means that an option attribute that ends up in documentation (eg' \
93
+
'`default` or `description`) depends on the restricted module arguments' \
94
+
'`config` or `pkgs`.'
96
+
echo 'Rebuild your configuration with `--show-trace` to find the offending' \
97
+
'location. Remove the references to restricted arguments (eg by escaping' \
98
+
'their antiquotations or adding a `defaultText`) or disable the sandboxed' \
99
+
'build for the failing module by setting `meta.buildDocsInSandbox = false`.'
···
<listitem><para>This includes the HTML manual and the <command>nixos-help</command> command if
<option>documentation.doc.enable</option> is set.</para></listitem>
259
+
nixos.splitOptionDocBuild = mkOption {
263
+
Whether to split the option docs build into a cacheable and an uncacheable part.
264
+
Splitting the build can substantially decrease the amount of time needed to build
265
+
the manual, but some user modules may be incompatible with this splitting.