mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-09 19:13:26 +03:00
lib/types: refactor elemTypeFunctor for types.attrsWith
This commit is contained in:
parent
3f49e3dc06
commit
3d92f38fbd
1 changed files with 23 additions and 7 deletions
|
@ -71,6 +71,26 @@ let
|
|||
let pos = builtins.unsafeGetAttrPos name v; in
|
||||
if pos == null then "" else " at ${pos.file}:${toString pos.line}:${toString pos.column}";
|
||||
|
||||
# Internal functor to help for migrating functor.wrapped to functor.payload.elemType
|
||||
# Note that individual attributes can be overriden if needed.
|
||||
elemTypeFunctor = name: { elemType, ... }@payload: {
|
||||
inherit name payload;
|
||||
type = outer_types.types.${name};
|
||||
binOp = a: b:
|
||||
let
|
||||
merged = a.elemType.typeMerge b.elemType.functor;
|
||||
in
|
||||
if merged == null
|
||||
then
|
||||
null
|
||||
else
|
||||
{ elemType = merged; };
|
||||
wrappedDeprecationMessage = { loc }: lib.warn ''
|
||||
The deprecated `type.functor.wrapped` attribute of the option `${showOption loc}` is accessed, use `type.nestedTypes.elemType` instead.
|
||||
'' payload.elemType;
|
||||
};
|
||||
|
||||
|
||||
outer_types =
|
||||
rec {
|
||||
isType = type: x: (x._type or "") == type;
|
||||
|
@ -664,14 +684,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 = (elemTypeFunctor "attrsWith" {
|
||||
inherit elemType lazy placeholder;
|
||||
};
|
||||
}) // {
|
||||
# Custom type merging required because of the "placeholder" attribute
|
||||
inherit binOp;
|
||||
};
|
||||
nestedTypes.elemType = elemType;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue