Skip to content

Commit

Permalink
lib.types.attrsWith: Improved type merging
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil committed Oct 5, 2024
1 parent 3bd01bc commit 11a6fd8
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,35 @@ rec {
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<${name}>"]);
getSubModules = elemType.getSubModules;
substSubModules = m: attrsWith { elemType = elemType.substSubModules m; inherit name lazy; };
functor = (defaultFunctor typeName) // { wrapped = elemType; type = t: attrsWith { elemType = t; inherit name lazy; }; };
functor = defaultFunctor "attrsWith" // {
payload = {
inherit elemType name lazy;
};
binOp = lhs: rhs:
let
elemType = lhs.elemType.typeMerge rhs.elemType.functor;
name =
if lhs.name == rhs.name then
lhs.name
else if lhs.name == "name" then
rhs.name
else if rhs.name == "name" then
lhs.name
else
null;
lazy =
if lhs.lazy == rhs.lazy then
lhs.lazy
else
null;
in
if elemType == null || name == null || lazy == null then
null
else
{
inherit elemType name lazy;
};
};
nestedTypes.elemType = elemType;
};

Expand Down

0 comments on commit 11a6fd8

Please sign in to comment.