lib/modules: Use options apply function even if no values are defined

This allows `apply` functions to return a valid value if they completely
ignore their argument, which is the case for the option renaming
functions like `mkAliasOptionModule`. Therefore this solves issue #63693
This commit is contained in:
Silvan Mosberger 2019-08-10 00:04:07 +02:00
parent 3cde54ceb9
commit de9cb24938
No known key found for this signature in database
GPG Key ID: 9424360B4B85C9E7

View File

@ -323,16 +323,14 @@ rec {
else else
mergeDefinitions loc opt.type defs'; mergeDefinitions loc opt.type defs';
# Check whether the option is defined, and apply the apply
# function to the merged value. This allows options to yield a # The value with a check that it is defined
# value computed from the definitions. valueDefined = if res.isDefined then res.mergedValue else
value = throw "The option `${showOption loc}' is used but not defined.";
if !res.isDefined then
throw "The option `${showOption loc}' is used but not defined." # Apply the 'apply' function to the merged value. This allows options to
else if opt ? apply then # yield a value computed from the definitions
opt.apply res.mergedValue value = if opt ? apply then opt.apply valueDefined else valueDefined;
else
res.mergedValue;
in opt // in opt //
{ value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value; { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;