Skip to content

Commit

Permalink
Hacking together with @hsjobeki
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil committed Nov 25, 2024
1 parent 415d193 commit 4973006
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
23 changes: 20 additions & 3 deletions lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,26 @@ let
t' = opt.options.type;
mergedType = t.typeMerge t'.functor;
typesMergeable = mergedType != null;
typeSet = if (bothHave "type") && typesMergeable
then { type = mergedType; }
else {};

addDeprecatedWrapped = t:
t // {
functor = t.functor // {
wrapped = t.functor.wrappedDeprecationMessage {
inherit loc;
};
};
};

typeSet =
if (bothHave "type") && typesMergeable then
{ type = addDeprecatedWrapped mergedType; }
else if opt.options.type ? functor.wrappedDeprecationMessage then
{
type = addDeprecatedWrapped opt.options.type;
}
else
{};

bothHave = k: opt.options ? ${k} && res ? ${k};
in
if bothHave "default" ||
Expand Down
18 changes: 11 additions & 7 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ rec {
let mergedWrapped = f.wrapped.typeMerge f'.wrapped.functor;
mergedPayload = f.binOp f.payload f'.payload;

mergedDeprecatedWrapped = f.wrapped.elemType.typeMerge f'.wrapped.elemType.functor;

hasPayload = assert (f'.payload != null) == (f.payload != null); f.payload != null;
hasWrapped = assert (f'.wrapped != null) == (f.wrapped != null); f.wrapped != null;
in
Expand All @@ -95,7 +97,9 @@ rec {
else

if hasPayload then
if hasWrapped then
if f ? wrappedDeprecationMessage || ! hasWrapped then
if mergedPayload == null then null else f.type mergedPayload
else
# Has both wrapped and payload
throw ''
Type ${f.name} defines both `functor.payload` and `functor.wrapped` at the same time, which is not supported.
Expand All @@ -104,9 +108,6 @@ rec {
If your code worked before remove `functor.payload` from the type definition.
''
else
# Has payload
if mergedPayload == null then null else f.type mergedPayload
else
if hasWrapped then
# Has wrapped
Expand Down Expand Up @@ -592,7 +593,11 @@ rec {
lazyAttrsOf = elemType: attrsWith { inherit elemType; lazy = true; };

# base type for lazyAttrsOf and attrsOf
attrsWith = {
attrsWith =
let
warnWrapped = loc: lib.warn "Using wrapped, use nestedTypes.elemType instead ${showOption loc}";
in
{
elemType,
lazy ? false,
}:
Expand Down Expand Up @@ -630,8 +635,7 @@ rec {
getSubModules = elemType.getSubModules;
substSubModules = m: attrsWith { elemType = elemType.substSubModules m; inherit lazy; };
functor = defaultFunctor "attrsWith" // {
# TODO: This breaks stuff
# wrapped = elemType;
wrappedDeprecationMessage = { loc }: warnWrapped loc elemType;
payload = {
# Important!: Add new function attributes here in case of future changes
inherit elemType lazy;
Expand Down

0 comments on commit 4973006

Please sign in to comment.