summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorarcnmx <arcnmx@users.noreply.github.com>2020-01-14 09:06:59 -0800
committerarcnmx <arcnmx@users.noreply.github.com>2020-01-14 09:30:53 -0800
commit92b464d57d9cf26996f2b04dfbca19caddc87d85 (patch)
treebae58b469b325882bd701a7250d351ac5bb5b0d3 /lib
parentf4c645a3a4994b954a9e7539d82edf8d650877f6 (diff)
lib/types: prioritise coercedType in coercedTo
This more intuitively matches `types.either` and allows paths to be coerced to submodules again, which was inhibited by #76861
Diffstat (limited to 'lib')
-rw-r--r--lib/types.nix8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/types.nix b/lib/types.nix
index 57ddb45a2371..d8a5db0c89f0 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -590,7 +590,7 @@ rec {
tail' = tail ts;
in foldl' either head' tail';
- # Either value of type `finalType` or `coercedType`, the latter is
+ # Either value of type `coercedType` or `finalType`, the former is
# converted to `finalType` using `coerceFunc`.
coercedTo = coercedType: coerceFunc: finalType:
assert lib.assertMsg (coercedType.getSubModules == null)
@@ -599,12 +599,12 @@ rec {
mkOptionType rec {
name = "coercedTo";
description = "${finalType.description} or ${coercedType.description} convertible to it";
- check = x: finalType.check x || (coercedType.check x && finalType.check (coerceFunc x));
+ check = x: (coercedType.check x && finalType.check (coerceFunc x)) || finalType.check x;
merge = loc: defs:
let
coerceVal = val:
- if finalType.check val then val
- else coerceFunc val;
+ if coercedType.check val then coerceFunc val
+ else val;
in finalType.merge loc (map (def: def // { value = coerceVal def.value; }) defs);
emptyValue = finalType.emptyValue;
getSubOptions = finalType.getSubOptions;