diff --git a/lib/modules.nix b/lib/modules.nix index 2468b6fbdd22f..ee1aa16dbb04e 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -101,9 +101,31 @@ rec { check ? true }: let + withWarnings = x: + lib.warnIf (evalModulesArgs?args) "The args argument to evalModules is deprecated. Please set config._module.args instead." + lib.warnIf (evalModulesArgs?check) "The check argument to evalModules is deprecated. Please set config._module.check instead." + x; + + legacyModules = + optional (evalModulesArgs?args) { + config = { + _module.args = args; + }; + } + ++ optional (evalModulesArgs?check) { + config = { + _module.check = mkDefault check; + }; + }; + regularModules = modules ++ legacyModules; + # This internal module declare internal options under the `_module' # attribute. These options are fragile, as they are used by the # module system to change the interpretation of modules. + # + # When extended with extendModules or moduleType, a fresh instance of + # this module is used, to avoid conflicts and allow chaining of + # extendModules. internalModule = rec { _file = ./modules.nix; @@ -125,7 +147,7 @@ rec { _module.check = mkOption { type = types.bool; internal = true; - default = check; + default = true; description = "Whether to check whether all option definitions have matching declarations."; }; @@ -151,14 +173,14 @@ rec { _module.args = { inherit extendModules; moduleType = type; - } // args; + }; }; }; merged = let collected = collectModules (specialArgs.modulesPath or "") - (modules ++ [ internalModule ]) + (regularModules ++ [ internalModule ]) ({ inherit lib options config specialArgs; } // specialArgs); in mergeModules prefix (reverseList collected); @@ -222,7 +244,7 @@ rec { prefix ? [], }: evalModules (evalModulesArgs // { - modules = evalModulesArgs.modules ++ modules; + modules = regularModules ++ modules; specialArgs = evalModulesArgs.specialArgs or {} // specialArgs; prefix = extendArgs.prefix or evalModulesArgs.prefix; }); @@ -231,7 +253,7 @@ rec { inherit modules specialArgs; }; - result = { + result = withWarnings { options = checked options; config = checked (removeAttrs config [ "_module" ]); _module = checked (config._module); diff --git a/nixos/lib/eval-config.nix b/nixos/lib/eval-config.nix index 74b52daa3c8eb..d4567409f4015 100644 --- a/nixos/lib/eval-config.nix +++ b/nixos/lib/eval-config.nix @@ -8,6 +8,7 @@ # as subcomponents (e.g. the container feature, or nixops if network # expressions are ever made modular at the top level) can just use # types.submodule instead of using eval-config.nix +evalConfigArgs@ { # !!! system can be set modularly, would be nice to remove system ? builtins.currentSystem , # !!! is this argument needed any more? The pkgs argument can @@ -28,7 +29,7 @@ in if e == "" then [] else [(import e)] }: -let extraArgs_ = extraArgs; pkgs_ = pkgs; +let pkgs_ = pkgs; in let @@ -51,28 +52,49 @@ let }; }; - noUserModules = lib.evalModules { - inherit prefix check; - modules = baseModules ++ extraModules ++ [ pkgsModule ]; - args = extraArgs; + withWarnings = x: + lib.warnIf (evalConfigArgs?args) "The extraArgs argument to eval-config.nix is deprecated. Please set config._module.args instead." + lib.warnIf (evalConfigArgs?check) "The check argument to eval-config.nix is deprecated. Please set config._module.check instead." + x; + + legacyModules = + lib.optional (evalConfigArgs?args) { + config = { + _module.args = extraArgs; + }; + } + ++ lib.optional (evalConfigArgs?check) { + config = { + _module.check = lib.mkDefault check; + }; + }; + allUserModules = modules ++ legacyModules; + + noUserModules = lib.evalModules ({ + inherit prefix; + modules = baseModules ++ extraModules ++ [ pkgsModule modulesModule ]; specialArgs = { modulesPath = builtins.toString ../modules; } // specialArgs; - }; + }); - # These are the extra arguments passed to every module. In - # particular, Nixpkgs is passed through the "pkgs" argument. - extraArgs = extraArgs_ // { - inherit noUserModules baseModules extraModules modules; + # Extra arguments that are useful for constructing a similar configuration. + modulesModule = { + config = { + _module.args = { + inherit noUserModules baseModules extraModules modules; + }; + }; }; -in rec { + nixosWithUserModules = noUserModules.extendModules { modules = allUserModules; }; + +in withWarnings { # Merge the option definitions in all modules, forming the full # system configuration. - inherit (noUserModules.extendModules { inherit modules; }) - config options _module type; + inherit (nixosWithUserModules) config options _module type; inherit extraArgs; - inherit (_module.args) pkgs; + inherit (nixosWithUserModules._module.args) pkgs; } diff --git a/nixos/modules/misc/documentation.nix b/nixos/modules/misc/documentation.nix index 1f837f9efa22d..64b1c15086fc8 100644 --- a/nixos/modules/misc/documentation.nix +++ b/nixos/modules/misc/documentation.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, baseModules, extraModules, modules, modulesPath, ... }: +{ config, lib, pkgs, extendModules, noUserModules, ... }: with lib; @@ -6,11 +6,8 @@ let cfg = config.documentation; - manualModules = - baseModules - # Modules for which to show options even when not imported - ++ [ ../virtualisation/qemu-vm.nix ] - ++ optionals cfg.nixos.includeAllModules (extraModules ++ modules); + /* Modules for which to show options even when not imported. */ + extraDocModules = [ ../virtualisation/qemu-vm.nix ]; /* For the purpose of generating docs, evaluate options with each derivation in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}". @@ -24,13 +21,10 @@ let extraSources = cfg.nixos.extraModuleSources; options = let - scrubbedEval = evalModules { - modules = [ { nixpkgs.localSystem = config.nixpkgs.localSystem; } ] ++ manualModules; - args = (config._module.args) // { modules = [ ]; }; - specialArgs = { - pkgs = scrubDerivations "pkgs" pkgs; - inherit modulesPath; - }; + extendNixOS = if cfg.nixos.includeAllModules then extendModules else noUserModules.extendModules; + scrubbedEval = extendNixOS { + modules = extraDocModules; + specialArgs.pkgs = scrubDerivations "pkgs" pkgs; }; scrubDerivations = namePrefix: pkgSet: mapAttrs (name: value: