summary refs log tree commit diff
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2021-12-17 15:17:49 +0100
committerNaïm Favier <n@monade.li>2022-01-27 22:12:53 +0100
commit5a07097772e18ac68600038dbcafda2310227190 (patch)
treebd23702cc98bfc213f9cfe2d7ff2a80998ab2ebb /lib/modules.nix
parentf90310a12f268835167c8840da8aa0d3d1314e0f (diff)
downloadnixpkgs-5a07097772e18ac68600038dbcafda2310227190.tar
nixpkgs-5a07097772e18ac68600038dbcafda2310227190.tar.gz
nixpkgs-5a07097772e18ac68600038dbcafda2310227190.tar.bz2
nixpkgs-5a07097772e18ac68600038dbcafda2310227190.tar.lz
nixpkgs-5a07097772e18ac68600038dbcafda2310227190.tar.xz
nixpkgs-5a07097772e18ac68600038dbcafda2310227190.tar.zst
nixpkgs-5a07097772e18ac68600038dbcafda2310227190.zip
lib/modules: introduce setDefaultModuleLocation
Wraps a module with a default location for reporting errors.
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index c68bbfcaa3e..f1125aca0a3 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -334,6 +334,10 @@ rec {
     in modulesPath: initialModules: args:
       filterModules modulesPath (collectStructuredModules unknownModule "" initialModules args);
 
+  /* Wrap a module with a default location for reporting errors. */
+  setDefaultModuleLocation = file: m:
+    { _file = file; imports = [ m ]; };
+
   /* Massage a module into canonical form, that is, a set consisting
      of ‘options’, ‘config’ and ‘imports’ attributes. */
   unifyModuleSyntax = file: key: m:
@@ -534,11 +538,9 @@ rec {
      correspond to the definition of 'loc' in 'opt.file'. */
   mergeOptionDecls =
    let
-    packSubmodule = file: m:
-      { _file = file; imports = [ m ]; };
     coerceOption = file: opt:
-      if isFunction opt then packSubmodule file opt
-      else packSubmodule file { options = opt; };
+      if isFunction opt then setDefaultModuleLocation file opt
+      else setDefaultModuleLocation file { options = opt; };
    in loc: opts:
     foldl' (res: opt:
       let t  = res.type;
@@ -568,7 +570,7 @@ rec {
 
           getSubModules = opt.options.type.getSubModules or null;
           submodules =
-            if getSubModules != null then map (packSubmodule opt._file) getSubModules ++ res.options
+            if getSubModules != null then map (setDefaultModuleLocation opt._file) getSubModules ++ res.options
             else if opt.options ? options then map (coerceOption opt._file) options' ++ res.options
             else res.options;
         in opt.options // res //