git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #148315 from hercules-ci/nixos-evalModules-legacy-cleanup

NixOS/evalModules legacy cleanup

commit490d46f044d3c82b4948626fa2fca5be7903434e authorSilvan Mosberger <contact@infinisil.com> dateTue 7 Dec 2021, 18:30 (5 years ago) parentbb89009260b941
3 files changed+70−32
lib/modules.nix+27−5 nixos/lib/eval-config.nix+36−14 nixos/modules/misc/documentation.nix+7−13
lib/modules.nix+27−5
@@ -101,9 +101,31 @@ rec {
101101 check ? true
102102 }:
103103 let
104+ withWarnings = x:
105+ lib.warnIf (evalModulesArgs?args) "The args argument to evalModules is deprecated. Please set config._module.args instead."
106+ lib.warnIf (evalModulesArgs?check) "The check argument to evalModules is deprecated. Please set config._module.check instead."
107+ x;
108+
109+ legacyModules =
110+ optional (evalModulesArgs?args) {
111+ config = {
112+ _module.args = args;
113+ };
114+ }
115+ ++ optional (evalModulesArgs?check) {
116+ config = {
117+ _module.check = mkDefault check;
118+ };
119+ };
120+ regularModules = modules ++ legacyModules;
121+
104122 # This internal module declare internal options under the `_module'
105123 # attribute. These options are fragile, as they are used by the
106124 # module system to change the interpretation of modules.
125+ #
126+ # When extended with extendModules or moduleType, a fresh instance of
127+ # this module is used, to avoid conflicts and allow chaining of
128+ # extendModules.
107129 internalModule = rec {
108130 _file = ./modules.nix;
109131
@@ -125,7 +147,7 @@ rec {
125147 _module.check = mkOption {
126148 type = types.bool;
127149 internal = true;
128− default = check;
150+ default = true;
129151 description = "Whether to check whether all option definitions have matching declarations.";
130152 };
131153
@@ -151,14 +173,14 @@ rec {
151173 _module.args = {
152174 inherit extendModules;
153175 moduleType = type;
154− } // args;
176+ };
155177 };
156178 };
157179
158180 merged =
159181 let collected = collectModules
160182 (specialArgs.modulesPath or "")
161− (modules ++ [ internalModule ])
183+ (regularModules ++ [ internalModule ])
162184 ({ inherit lib options config specialArgs; } // specialArgs);
163185 in mergeModules prefix (reverseList collected);
164186
@@ -222,7 +244,7 @@ rec {
222244 prefix ? [],
223245 }:
224246 evalModules (evalModulesArgs // {
225− modules = evalModulesArgs.modules ++ modules;
247+ modules = regularModules ++ modules;
226248 specialArgs = evalModulesArgs.specialArgs or {} // specialArgs;
227249 prefix = extendArgs.prefix or evalModulesArgs.prefix;
228250 });
@@ -231,7 +253,7 @@ rec {
231253 inherit modules specialArgs;
232254 };
233255
234− result = {
256+ result = withWarnings {
235257 options = checked options;
236258 config = checked (removeAttrs config [ "_module" ]);
237259 _module = checked (config._module);
nixos/lib/eval-config.nix+36−14
@@ -8,6 +8,7 @@
88# as subcomponents (e.g. the container feature, or nixops if network
99# expressions are ever made modular at the top level) can just use
1010# types.submodule instead of using eval-config.nix
11+evalConfigArgs@
1112{ # !!! system can be set modularly, would be nice to remove
1213 system ? builtins.currentSystem
1314, # !!! is this argument needed any more? The pkgs argument can
@@ -28,7 +29,7 @@
2829 in if e == "" then [] else [(import e)]
2930}:
3031
31−let extraArgs_ = extraArgs; pkgs_ = pkgs;
32+let pkgs_ = pkgs;
3233in
3334
3435let
@@ -51,28 +52,49 @@ let
5152 };
5253 };
5354
54− noUserModules = lib.evalModules {
55− inherit prefix check;
56− modules = baseModules ++ extraModules ++ [ pkgsModule ];
57− args = extraArgs;
55+ withWarnings = x:
56+ lib.warnIf (evalConfigArgs?args) "The extraArgs argument to eval-config.nix is deprecated. Please set config._module.args instead."
57+ lib.warnIf (evalConfigArgs?check) "The check argument to eval-config.nix is deprecated. Please set config._module.check instead."
58+ x;
59+
60+ legacyModules =
61+ lib.optional (evalConfigArgs?args) {
62+ config = {
63+ _module.args = extraArgs;
64+ };
65+ }
66+ ++ lib.optional (evalConfigArgs?check) {
67+ config = {
68+ _module.check = lib.mkDefault check;
69+ };
70+ };
71+ allUserModules = modules ++ legacyModules;
72+
73+ noUserModules = lib.evalModules ({
74+ inherit prefix;
75+ modules = baseModules ++ extraModules ++ [ pkgsModule modulesModule ];
5876 specialArgs =
5977 { modulesPath = builtins.toString ../modules; } // specialArgs;
60− };
78+ });
6179
62− # These are the extra arguments passed to every module. In
63− # particular, Nixpkgs is passed through the "pkgs" argument.
64− extraArgs = extraArgs_ // {
65− inherit noUserModules baseModules extraModules modules;
80+ # Extra arguments that are useful for constructing a similar configuration.
81+ modulesModule = {
82+ config = {
83+ _module.args = {
84+ inherit noUserModules baseModules extraModules modules;
85+ };
86+ };
6687 };
6788
68−in rec {
89+ nixosWithUserModules = noUserModules.extendModules { modules = allUserModules; };
90+
91+in withWarnings {
6992
7093 # Merge the option definitions in all modules, forming the full
7194 # system configuration.
72− inherit (noUserModules.extendModules { inherit modules; })
73− config options _module type;
95+ inherit (nixosWithUserModules) config options _module type;
7496
7597 inherit extraArgs;
7698
77− inherit (_module.args) pkgs;
99+ inherit (nixosWithUserModules._module.args) pkgs;
78100}
nixos/modules/misc/documentation.nix+7−13
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs, baseModules, extraModules, modules, modulesPath, ... }:
1+{ config, lib, pkgs, extendModules, noUserModules, ... }:
22
33with lib;
44
@@ -6,11 +6,8 @@ let
66
77 cfg = config.documentation;
88
9− manualModules =
10− baseModules
11− # Modules for which to show options even when not imported
12− ++ [ ../virtualisation/qemu-vm.nix ]
13− ++ optionals cfg.nixos.includeAllModules (extraModules ++ modules);
9+ /* Modules for which to show options even when not imported. */
10+ extraDocModules = [ ../virtualisation/qemu-vm.nix ];
1411
1512 /* For the purpose of generating docs, evaluate options with each derivation
1613 in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}".
@@ -24,13 +21,10 @@ let
2421 extraSources = cfg.nixos.extraModuleSources;
2522 options =
2623 let
27− scrubbedEval = evalModules {
28− modules = [ { nixpkgs.localSystem = config.nixpkgs.localSystem; } ] ++ manualModules;
29− args = (config._module.args) // { modules = [ ]; };
30− specialArgs = {
31− pkgs = scrubDerivations "pkgs" pkgs;
32− inherit modulesPath;
33− };
24+ extendNixOS = if cfg.nixos.includeAllModules then extendModules else noUserModules.extendModules;
25+ scrubbedEval = extendNixOS {
26+ modules = extraDocModules;
27+ specialArgs.pkgs = scrubDerivations "pkgs" pkgs;
3428 };
3529 scrubDerivations = namePrefix: pkgSet: mapAttrs
3630 (name: value: