lib/modules: Scope module evaluation variables more tightly

This is a purely cosmetic change so it's easier to see dependencies
between variables.
This commit is contained in:
Silvan Mosberger 2020-03-19 23:45:23 +01:00
parent b3f869febb
commit b02a3d7b08
No known key found for this signature in database
GPG Key ID: E8F1E9EAD284E17D
1 changed files with 29 additions and 26 deletions

View File

@ -65,13 +65,15 @@ rec {
}; };
}; };
collected = collectModules options =
let collected = collectModules
(specialArgs.modulesPath or "") (specialArgs.modulesPath or "")
(modules ++ [ internalModule ]) (modules ++ [ internalModule ])
({ inherit config options lib; } // specialArgs); ({ inherit lib options config; } // specialArgs);
in mergeModules prefix (reverseList collected);
options = mergeModules prefix (reverseList collected);
config =
let
# Traverse options and extract the option values into the final # Traverse options and extract the option values into the final
# config set. At the same time, check whether all option # config set. At the same time, check whether all option
# definitions have matching declarations. # definitions have matching declarations.
@ -79,7 +81,6 @@ rec {
# without an infinite recursion. One way around this is to make the # without an infinite recursion. One way around this is to make the
# 'config' passed around to the modules be unconditionally unchecked, # 'config' passed around to the modules be unconditionally unchecked,
# and only do the check in 'result'. # and only do the check in 'result'.
config = yieldConfig prefix options;
yieldConfig = prefix: set: yieldConfig = prefix: set:
let res = removeAttrs (mapAttrs (n: v: let res = removeAttrs (mapAttrs (n: v:
if isOption v then v.value if isOption v then v.value
@ -93,6 +94,8 @@ rec {
res set._definedNames res set._definedNames
else else
res; res;
in yieldConfig prefix options;
result = { result = {
inherit options; inherit options;
config = removeAttrs config [ "_module" ]; config = removeAttrs config [ "_module" ];