mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-16 14:54:29 +01:00
Merge pull request #148315 from hercules-ci/nixos-evalModules-legacy-cleanup
NixOS/evalModules legacy cleanup
This commit is contained in:
commit
490d46f044
3 changed files with 70 additions and 32 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
||||
# Extra arguments that are useful for constructing a similar configuration.
|
||||
modulesModule = {
|
||||
config = {
|
||||
_module.args = {
|
||||
inherit noUserModules baseModules extraModules modules;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# 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;
|
||||
};
|
||||
nixosWithUserModules = noUserModules.extendModules { modules = allUserModules; };
|
||||
|
||||
in rec {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue