diff --git a/flake.nix b/flake.nix index 92c0d97c4a2..ececd26c153 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 ]; };