From 4973006da0243ed36e3fa5ac2fe52e582c672b0b Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 25 Nov 2024 16:58:58 +0100 Subject: [PATCH] Hacking together with @hsjobeki --- lib/modules.nix | 23 ++++++++++++++++++++--- lib/types.nix | 18 +++++++++++------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lib/modules.nix b/lib/modules.nix index 855ffaf25ed81e..bd11ce3904937c 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -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" || diff --git a/lib/types.nix b/lib/types.nix index a286f16227a0f3..ea6de3ee4fd097 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -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 @@ -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. @@ -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 @@ -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, }: @@ -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;