Skip to content

Commit

Permalink
lib/modules: Evaluate single defs for readOnly error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
infinisil committed Sep 21, 2020
1 parent bdfcee2 commit 910dfdc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/modules.nix
Expand Up @@ -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';

Expand Down

0 comments on commit 910dfdc

Please sign in to comment.