1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00

lib/types-dag: implement v2 merge protocol for dagOf type

This commit properly implements the v2 merge protocol for dagOf by:

- Making `check` a functor with `isV2MergeCoherent = true` that
  delegates to the underlying attrsOf type's check function
- Making `merge` a functor with a `v2` attribute that properly
  delegates to the underlying type's v2 merge implementation

This ensures compatibility with the v2 merge mechanism while
maintaining all existing dagOf functionality.

Fixes evaluation errors like:
  error: The option '...' has a type `DAG of X' that uses
  an ad-hoc `type // { check = ...; }' override, which is
  incompatible with the v2 merge mechanism.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman 2025-10-30 12:14:48 -05:00
parent 4ac96eb21c
commit f0f6923fd8
No known key found for this signature in database

View file

@ -37,15 +37,21 @@ let
mkOptionType {
name = "dagEntryOf";
description = "DAG entry of ${elemType.description}";
# leave the checking to the submodule type
merge =
loc: defs:
submoduleType.merge loc (
map (def: {
merge = {
__functor =
self: loc: defs:
(self.v2 { inherit loc defs; }).value;
v2 =
{ loc, defs }:
# Delegate to submodule's v2 merge to propagate any errors
submoduleType.merge.v2 {
inherit loc;
defs = map (def: {
inherit (def) file;
value = maybeConvert def;
}) defs
);
}) defs;
};
};
};
in
@ -65,9 +71,24 @@ rec {
mkOptionType rec {
name = "dagOf";
description = "DAG of ${elemType.description}";
inherit (attrEquivalent) check merge emptyValue;
check = {
__functor = _self: attrEquivalent.check;
isV2MergeCoherent = true;
};
merge = {
__functor =
self: loc: defs:
(self.v2 { inherit loc defs; }).value;
v2 =
{ loc, defs }:
# Directly delegate to attrsOf's v2 merge
attrEquivalent.merge.v2 {
inherit loc defs;
};
};
inherit (attrEquivalent) emptyValue;
inherit (elemType) getSubModules;
getSubOptions = prefix: elemType.getSubOptions (prefix ++ [ "<name>" ]);
getSubModules = elemType.getSubModules;
substSubModules = m: dagOf (elemType.substSubModules m);
functor = (defaultFunctor name) // {
wrapped = elemType;