diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index 022e459c3945..073df78797c7 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -100,6 +100,32 @@ rec { ]; }; + # given two patterns, return a pattern which is their logical AND. + # Since a pattern is a list-of-disjuncts, this needs to + patternLogicalAnd = pat1_: pat2_: + let + # patterns can be either a list or a (bare) singleton; turn + # them into singletons for uniform handling + pat1 = lib.toList pat1_; + pat2 = lib.toList pat2_; + in + lib.concatMap (attr1: + map (attr2: + lib.recursiveUpdateUntil + (path: subattr1: subattr2: + if (builtins.intersectAttrs subattr1 subattr2) == {} || subattr1 == subattr2 + then true + else throw '' + pattern conflict at path ${toString path}: + ${builtins.toJSON subattr1} + ${builtins.toJSON subattr2} + '') + attr1 + attr2 + ) + pat2) + pat1; + matchAnyAttrs = patterns: if builtins.isList patterns then attrs: any (pattern: matchAttrs pattern attrs) patterns else matchAttrs patterns;