summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--flake.nix10
1 files changed, 8 insertions, 2 deletions
diff --git a/flake.nix b/flake.nix
index 92c0d97c4a2b3..ececd26c153c6 100644
--- a/flake.nix
+++ b/flake.nix
@@ -49,12 +49,18 @@
                   })).config;
 
                 moduleDeclarationFile =
-                  (builtins.unsafeGetAttrPos "modules" args).file;
+                  let
+                    # Even though `modules` is a mandatory argument for `nixosSystem`, it doesn't
+                    # mean that the evaluator always keeps track of its position. If there
+                    # are too many levels of indirection, the position gets lost at some point.
+                    intermediatePos = builtins.unsafeGetAttrPos "modules" args;
+                  in
+                    if intermediatePos == null then null else intermediatePos.file;
 
                 # Add the invoking file as error message location for modules
                 # that don't have their own locations; presumably inline modules.
                 addModuleDeclarationFile =
-                  m: {
+                  m: if moduleDeclarationFile == null then m else {
                     _file = moduleDeclarationFile;
                     imports = [ m ];
                   };