Skip to content

Commit

Permalink
lib/types: prioritise coercedType in coercedTo
Browse files Browse the repository at this point in the history
This more intuitively matches `types.either` and allows paths to be
coerced to submodules again, which was inhibited by NixOS#76861

(cherry picked from commit 92b464d)
  • Loading branch information
arcnmx authored and dtzWill committed Jan 19, 2020
1 parent deaab52 commit 401bc7b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,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)
Expand All @@ -597,12 +597,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;
Expand Down

0 comments on commit 401bc7b

Please sign in to comment.