summary refs log tree commit diff
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2023-09-17 19:43:07 +0200
committerGitHub <noreply@github.com>2023-09-17 19:43:07 +0200
commit00e548790637efcc141e7f3c41bf931be08e5e50 (patch)
treee411239f5da71ea8632ee6d4110f6b04bdc0b95d /lib/modules.nix
parent5cbbc68e1ba223349a7e0126e03107c1e28b6030 (diff)
parenta1d38823079bdf7836dd44392e5e1029087d8c85 (diff)
downloadnixpkgs-00e548790637efcc141e7f3c41bf931be08e5e50.tar
nixpkgs-00e548790637efcc141e7f3c41bf931be08e5e50.tar.gz
nixpkgs-00e548790637efcc141e7f3c41bf931be08e5e50.tar.bz2
nixpkgs-00e548790637efcc141e7f3c41bf931be08e5e50.tar.lz
nixpkgs-00e548790637efcc141e7f3c41bf931be08e5e50.tar.xz
nixpkgs-00e548790637efcc141e7f3c41bf931be08e5e50.tar.zst
nixpkgs-00e548790637efcc141e7f3c41bf931be08e5e50.zip
Merge pull request #249243 from lf-/jade/declarationsWithLocations
nixos/modules: Add declarationPositions
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 5c2fb48868c..4acbce39e94 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -537,7 +537,7 @@ let
     mergeModules' prefix modules
       (concatMap (m: map (config: { file = m._file; inherit config; }) (pushDownProperties m.config)) modules);
 
-  mergeModules' = prefix: options: configs:
+  mergeModules' = prefix: modules: configs:
     let
       # an attrset 'name' => list of submodules that declare ‘name’.
       declsByName =
@@ -554,11 +554,11 @@ let
               else
                 mapAttrs
                   (n: option:
-                    [{ inherit (module) _file; options = option; }]
+                    [{ inherit (module) _file; pos = builtins.unsafeGetAttrPos n subtree; options = option; }]
                   )
                   subtree
               )
-            options);
+            modules);
 
       # The root of any module definition must be an attrset.
       checkedConfigs =
@@ -762,9 +762,16 @@ let
             else res.options;
         in opt.options // res //
           { declarations = res.declarations ++ [opt._file];
+            # In the case of modules that are generated dynamically, we won't
+            # have exact declaration lines; fall back to just the file being
+            # evaluated.
+            declarationPositions = res.declarationPositions
+              ++ (if opt.pos != null
+                then [opt.pos]
+                else [{ file = opt._file; line = null; column = null; }]);
             options = submodules;
           } // typeSet
-    ) { inherit loc; declarations = []; options = []; } opts;
+    ) { inherit loc; declarations = []; declarationPositions = []; options = []; } opts;
 
   /* Merge all the definitions of an option to produce the final
      config value. */