summary refs log tree commit diff
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2020-03-19 23:45:23 +0100
committerSilvan Mosberger <contact@infinisil.com>2020-08-03 22:37:00 +0200
commitb02a3d7b0808eb7f31713488af68c7f7997e77cf (patch)
treefd432ee455ac83ac7f7b03ab66936be74579c279 /lib/modules.nix
parentb3f869febbe16ace6b962b5aa4df5658978234ae (diff)
downloadnixpkgs-b02a3d7b0808eb7f31713488af68c7f7997e77cf.tar
nixpkgs-b02a3d7b0808eb7f31713488af68c7f7997e77cf.tar.gz
nixpkgs-b02a3d7b0808eb7f31713488af68c7f7997e77cf.tar.bz2
nixpkgs-b02a3d7b0808eb7f31713488af68c7f7997e77cf.tar.lz
nixpkgs-b02a3d7b0808eb7f31713488af68c7f7997e77cf.tar.xz
nixpkgs-b02a3d7b0808eb7f31713488af68c7f7997e77cf.tar.zst
nixpkgs-b02a3d7b0808eb7f31713488af68c7f7997e77cf.zip
lib/modules: Scope module evaluation variables more tightly
This is a purely cosmetic change so it's easier to see dependencies
between variables.
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix59
1 files changed, 31 insertions, 28 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index c18fec66c70..c8f832a00f0 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -65,34 +65,37 @@ rec {
         };
       };
 
-      collected = collectModules
-        (specialArgs.modulesPath or "")
-        (modules ++ [ internalModule ])
-        ({ inherit config options lib; } // specialArgs);
-
-      options = mergeModules prefix (reverseList collected);
-
-      # Traverse options and extract the option values into the final
-      # config set.  At the same time, check whether all option
-      # definitions have matching declarations.
-      # !!! _module.check's value can't depend on any other config values
-      # without an infinite recursion. One way around this is to make the
-      # 'config' passed around to the modules be unconditionally unchecked,
-      # and only do the check in 'result'.
-      config = yieldConfig prefix options;
-      yieldConfig = prefix: set:
-        let res = removeAttrs (mapAttrs (n: v:
-          if isOption v then v.value
-          else yieldConfig (prefix ++ [n]) v) set) ["_definedNames"];
-        in
-        if options._module.check.value && set ? _definedNames then
-          foldl' (res: m:
-            foldl' (res: name:
-              if set ? ${name} then res else throw "The option `${showOption (prefix ++ [name])}' defined in `${m.file}' does not exist.")
-              res m.names)
-            res set._definedNames
-        else
-          res;
+      options =
+        let collected = collectModules
+          (specialArgs.modulesPath or "")
+          (modules ++ [ internalModule ])
+          ({ inherit lib options config; } // specialArgs);
+        in mergeModules prefix (reverseList collected);
+
+      config =
+        let
+          # Traverse options and extract the option values into the final
+          # config set.  At the same time, check whether all option
+          # definitions have matching declarations.
+          # !!! _module.check's value can't depend on any other config values
+          # without an infinite recursion. One way around this is to make the
+          # 'config' passed around to the modules be unconditionally unchecked,
+          # and only do the check in 'result'.
+          yieldConfig = prefix: set:
+            let res = removeAttrs (mapAttrs (n: v:
+              if isOption v then v.value
+              else yieldConfig (prefix ++ [n]) v) set) ["_definedNames"];
+            in
+            if options._module.check.value && set ? _definedNames then
+              foldl' (res: m:
+                foldl' (res: name:
+                  if set ? ${name} then res else throw "The option `${showOption (prefix ++ [name])}' defined in `${m.file}' does not exist.")
+                  res m.names)
+                res set._definedNames
+            else
+              res;
+        in yieldConfig prefix options;
+
       result = {
         inherit options;
         config = removeAttrs config [ "_module" ];