diff options
author | Silvan Mosberger <infinisil@icloud.com> | 2019-10-12 19:32:59 +0200 |
---|---|---|
committer | Silvan Mosberger <contact@infinisil.com> | 2020-01-10 16:19:54 +0100 |
commit | 130a0c987830c0a6f61b21765fcab27b883b2263 (patch) | |
tree | a712db5d27ec8e30e0aa638f50121f1dce843ce9 | |
parent | 112eea6b906f7f60d886deb9a15edd19b46e39c5 (diff) |
lib/modules: Move the isDefined check into mergedValue
Without this change, accessing `mergedValue` from `mergeDefinitions` in case there are no definitions will throw an error like error: evaluation aborted with the following error message: 'This case should never happen.' This change makes it throw the appropriate error error: The option `foo' is used but not defined. This is fully backwards compatible.
-rw-r--r-- | lib/modules.nix | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/lib/modules.nix b/lib/modules.nix index 559697b3d57e1..228cde002db9e 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -365,16 +365,9 @@ rec { else mergeDefinitions loc opt.type defs'; - - # The value with a check that it is defined - valueDefined = if res.isDefined then res.mergedValue else - # (nixos-option detects this specific error message and gives it special - # handling. If changed here, please change it there too.) - throw "The option `${showOption loc}' is used but not defined."; - # Apply the 'apply' function to the merged value. This allows options to # yield a value computed from the definitions - value = if opt ? apply then opt.apply valueDefined else valueDefined; + value = if opt ? apply then opt.apply res.mergedValue else res.mergedValue; in opt // { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value; @@ -408,11 +401,17 @@ rec { }; defsFinal = defsFinal'.values; - # Type-check the remaining definitions, and merge them. - mergedValue = foldl' (res: def: - if type.check def.value then res - else throw "The option value `${showOption loc}' in `${def.file}' is not of type `${type.description}'.") - (type.merge loc defsFinal) defsFinal; + # Type-check the remaining definitions, and merge them. Or throw if no definitions. + mergedValue = + if isDefined then + foldl' (res: def: + if type.check def.value then res + else throw "The option value `${showOption loc}' in `${def.file}' is not of type `${type.description}'." + ) (type.merge loc defsFinal) defsFinal + else + # (nixos-option detects this specific error message and gives it special + # handling. If changed here, please change it there too.) + throw "The option `${showOption loc}' is used but not defined."; isDefined = defsFinal != []; |