From 5d72133a228d173e3048e8efa2bb6578c2cb2bd3 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Fri, 30 May 2025 22:04:52 +0200 Subject: [PATCH] lib/addCheck: add support for new merge --- lib/types.nix | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index b550125a4f28..a6b3e6fb83fb 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -20,7 +20,6 @@ let toList ; inherit (lib.lists) - all concatLists count elemAt @@ -758,16 +757,14 @@ let nonEmptyListOf = elemType: let - list = types.listOf elemType; + list = addCheck (types.listOf elemType) (l: l != [ ]); in - addCheck ( - list - // { - description = "non-empty ${optionDescriptionPhrase (class: class == "noun") list}"; - emptyValue = { }; # no .value attr, meaning unset - substSubModules = m: nonEmptyListOf (elemType.substSubModules m); - } - ) (l: l != [ ]); + list + // { + description = "non-empty ${optionDescriptionPhrase (class: class == "noun") list}"; + emptyValue = { }; # no .value attr, meaning unset + substSubModules = m: nonEmptyListOf (elemType.substSubModules m); + }; attrsOf = elemType: attrsWith { inherit elemType; }; @@ -1500,7 +1497,7 @@ let } convertible to it"; check = x: (coercedType.check x && finalType.check (coerceFunc x)) || finalType.check x; merge = { - __funtor = + __functor = self: loc: defs: (self.v2 { inherit loc defs; }).value; v2 = @@ -1558,15 +1555,31 @@ let */ addCheck = elemType: check: - let - final = elemType // { + if elemType.merge ? v2 then + elemType + // { + check = x: elemType.check x && check x; + merge = { + __functor = + self: loc: defs: + (self.v2 { inherit loc defs; }).value; + v2 = + { loc, defs }: + let + orig = elemType.merge.v2 { inherit loc defs; }; + headError' = if orig.headError != null then orig.headError else checkDefsForError check loc defs; + in + orig + // { + headError = headError'; + }; + }; + } + else + elemType + // { check = x: elemType.check x && check x; - # addCheck discards the merge.v2 function - # - merge = if elemType.merge ? v2 then elemType.merge.__functor { inherit final; } else elemType.merge; }; - in - final; }; /**