mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 03:23:29 +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
|
let pos = builtins.unsafeGetAttrPos name v; in
|
||||||
if pos == null then "" else " at ${pos.file}:${toString pos.line}:${toString pos.column}";
|
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 =
|
outer_types =
|
||||||
rec {
|
rec {
|
||||||
isType = type: x: (x._type or "") == type;
|
isType = type: x: (x._type or "") == type;
|
||||||
|
@ -664,14 +684,10 @@ rec {
|
||||||
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<${placeholder}>"]);
|
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<${placeholder}>"]);
|
||||||
getSubModules = elemType.getSubModules;
|
getSubModules = elemType.getSubModules;
|
||||||
substSubModules = m: attrsWith { elemType = elemType.substSubModules m; inherit lazy placeholder; };
|
substSubModules = m: attrsWith { elemType = elemType.substSubModules m; inherit lazy placeholder; };
|
||||||
functor = defaultFunctor "attrsWith" // {
|
functor = (elemTypeFunctor "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
|
|
||||||
inherit elemType lazy placeholder;
|
inherit elemType lazy placeholder;
|
||||||
};
|
}) // {
|
||||||
|
# Custom type merging required because of the "placeholder" attribute
|
||||||
inherit binOp;
|
inherit binOp;
|
||||||
};
|
};
|
||||||
nestedTypes.elemType = elemType;
|
nestedTypes.elemType = elemType;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue