lib.types.defaultTypeMerge: Fix for functors with no wrapped attr (#476219)

This commit is contained in:
Johannes Kirschbauer
2026-04-14 07:15:44 +00:00
committed by GitHub
3 changed files with 39 additions and 2 deletions

View File

@@ -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.

View File

@@ -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";
};
}

View File

@@ -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;