From 6797b92f8d0f357702da4f13cf69bcd43e006240 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 18 Jul 2021 19:09:38 +0200 Subject: [PATCH] flake.nix: Only add `_file`-key if position of `args.modules` is actually known to the evaluator This happens if the evaluator "loses" the position of an attr-declaration[1] because of e.g. too many nested function-calls to build the final attr-set. While the actual issue should be fixed in Nix itself, this is IMHO a fair workaround to unblock affected users[2]. [1] https://github.com/NixOS/nixpkgs/commit/e14c24593420bb9057e7f38b40d17137eaeff9dd#commitcomment-53645936 [2] It seems as everyone using `divnix/digga` or `flake-utils-plus` are affected: * https://github.com/divnix/digga/issues/87 --- flake.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 ]; };