Skip to content

Commit

Permalink
lib/types: init defaultComposedFunctor for types.{attrsWith,listOf}
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjobeki committed Dec 17, 2024
1 parent 08de518 commit 204bd60
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ rec {
payload = null;
binOp = a: b: null;
};
# Default composed type functor
defaultComposedFunctor = name: payload: {
inherit name payload;
type = mergedPayload: types.${name} mergedPayload;
binOp = a: b: if a == b then a else null;
# Legacy support attributes
wrappedDeprecationMessage = { loc }: lib.warn ''
The deprecated `type.functor.wrapped` attribute of the option `${showOption loc}` is accessed, use `type.nestedTypes.elemType` instead.
'' payload.elemType;
};

isOptionType = isType "option-type";
mkOptionType =
Expand Down Expand Up @@ -580,7 +590,9 @@ rec {
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["*"]);
getSubModules = elemType.getSubModules;
substSubModules = m: listOf (elemType.substSubModules m);
functor = (defaultFunctor name) // { wrapped = elemType; };
functor = (defaultComposedFunctor name { inherit elemType; }) // {
type = payload: types.listOf payload.elemType;
};
nestedTypes.elemType = elemType;
};

Expand Down Expand Up @@ -664,14 +676,10 @@ rec {
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<${placeholder}>"]);
getSubModules = elemType.getSubModules;
substSubModules = m: attrsWith { elemType = elemType.substSubModules m; inherit lazy placeholder; };
functor = defaultFunctor "attrsWith" // {
wrappedDeprecationMessage = { loc }: lib.warn ''
The deprecated `type.functor.wrapped` attribute of the option `${showOption loc}` is accessed, use `type.nestedTypes.elemType` instead.
'' elemType;
payload = {
# Important!: Add new function attributes here in case of future changes
functor = (defaultComposedFunctor "attrsWith" {
inherit elemType lazy placeholder;
};
}) // {
# Custom type merging required because of the "placeholder" attribute
inherit binOp;
};
nestedTypes.elemType = elemType;
Expand Down

0 comments on commit 204bd60

Please sign in to comment.