Merge pull request #130570 from Ma27/flake-pos-eval-error

flake.nix: Only add `_file`-key if position of `args.modules` is actually know to the evaluator
This commit is contained in:
Maximilian Bosch 2021-07-19 08:23:05 +02:00 committed by GitHub
commit 6564e7ef13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,12 +49,18 @@
})).config; })).config;
moduleDeclarationFile = 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 # Add the invoking file as error message location for modules
# that don't have their own locations; presumably inline modules. # that don't have their own locations; presumably inline modules.
addModuleDeclarationFile = addModuleDeclarationFile =
m: { m: if moduleDeclarationFile == null then m else {
_file = moduleDeclarationFile; _file = moduleDeclarationFile;
imports = [ m ]; imports = [ m ];
}; };