diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index fbbf95e7c30f..765ca31a48e7 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -734,6 +734,8 @@ checkConfigOutput 'ok' config.freeformItems.foo.bar ./adhoc-freeformType-survive # Test that specifying both functor.wrapped and functor.payload isn't allowed checkConfigError 'Type foo defines both `functor.payload` and `functor.wrapped` at the same time, which is not supported.' config.result ./default-type-merge-both.nix +# Test that not including functor.wrapped is allowed +checkConfigOutput 'ok' config.result ./default-type-merge-payload.nix # Anonymous submodules don't get nixed by import resolution/deduplication # because of an `extendModules` bug, issue 168767. diff --git a/lib/tests/modules/default-type-merge-payload.nix b/lib/tests/modules/default-type-merge-payload.nix new file mode 100644 index 000000000000..d6cdc5906074 --- /dev/null +++ b/lib/tests/modules/default-type-merge-payload.nix @@ -0,0 +1,32 @@ +{ lib, options, ... }: +let + fooOf = + elemType: + lib.mkOptionType { + name = "foo"; + functor = { + name = "foo"; + type = payload: fooOf payload.elemType; + binOp = a: _b: a; + payload.elemType = elemType; + }; + }; +in +{ + imports = [ + { + options.foo = lib.mkOption { + type = fooOf lib.types.int; + }; + } + { + options.foo = lib.mkOption { + type = fooOf lib.types.int; + }; + } + ]; + + options.result = lib.mkOption { + default = builtins.seq options.foo "ok"; + }; +} diff --git a/lib/types.nix b/lib/types.nix index b3c40208c2c9..9fb99b9cc66e 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -158,8 +158,11 @@ rec { assert (f'.payload != null) == (f.payload != null); f.payload != null; hasWrapped = - assert (f'.wrapped != null) == (f.wrapped != null); - f.wrapped != null; + let + hasWrappedNonNull = set: set ? "wrapped" && set.wrapped != null; + in + assert (hasWrappedNonNull f') == (hasWrappedNonNull f); + hasWrappedNonNull f; typeFromPayload = if mergedPayload == null then null else f.type mergedPayload; typeFromWrapped = if mergedWrapped == null then null else f.type mergedWrapped;