make-derivation.nix: better error reporting for conflicting env attributes

This commit is contained in:
K900 2024-08-06 18:42:06 +03:00
parent 2a13929e1f
commit 7cd4d5d7a3

View File

@ -570,11 +570,14 @@ let
checkedEnv =
let
overlappingNames = attrNames (builtins.intersectAttrs env derivationArg);
prettyPrint = lib.generators.toPretty {};
makeError = name: " - ${name}: in `env`: ${prettyPrint env.${name}}; in derivation arguments: ${prettyPrint derivationArg.${name}}";
errors = lib.concatMapStringsSep "\n" makeError overlappingNames;
in
assert assertMsg envIsExportable
"When using structured attributes, `env` must be an attribute set of environment variables.";
assert assertMsg (overlappingNames == [ ])
"The env attribute set cannot contain any attributes passed to derivation. The following attributes are overlapping: ${concatStringsSep ", " overlappingNames}";
"The env attribute set cannot contain any attributes passed to derivation. The following attributes are overlapping:\n${errors}";
mapAttrs
(n: v: assert assertMsg (isString v || isBool v || isInt v || isDerivation v)
"The env attribute set can only contain derivation, string, boolean or integer attributes. The ${n} attribute is of type ${builtins.typeOf v}."; v)