lib.systems.inspect: add patternLogicalAnd
This commit is contained in:
parent
9180573837
commit
8c0416ef36
1 changed files with 26 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue