3
0
Fork 0
forked from mirrors/nixpkgs

lib/modules: Evaluate single defs for readOnly error

If multiple definitions are passed, this evaluates them all as if they
were the only one, for a better error message. In particular this won't
show module-internal properties like `_type = "override"` and co.
This commit is contained in:
Silvan Mosberger 2020-09-21 18:10:06 +02:00
parent bdfcee2590
commit 910dfdc41e
No known key found for this signature in database
GPG key ID: E8F1E9EAD284E17D

View file

@ -449,7 +449,13 @@ rec {
# Handle properties, check types, and merge everything together.
res =
if opt.readOnly or false && length defs' > 1 then
throw "The option `${showOption loc}' is read-only, but it's set multiple times. Definition values:${showDefs defs'}"
let
# For a better error message, evaluate all readOnly definitions as
# if they were the only definition.
separateDefs = map (def: def // {
value = (mergeDefinitions loc opt.type [ def ]).mergedValue;
}) defs';
in throw "The option `${showOption loc}' is read-only, but it's set multiple times. Definition values:${showDefs separateDefs}"
else
mergeDefinitions loc opt.type defs';