query
On this page

matchAttrs

lib.attrsets.matchAttrs

Docs pulled from | This Revision | about 2 hours ago


Recurse into every attribute set of the first argument and check that:

  • Each attribute path also exists in the second argument.
  • If the attribute's value is not a nested attribute set, it must have the same value in the right argument.

Inputs

pattern

Attribute set structure to match

attrs

Attribute set to check

Type

matchAttrs :: AttrSet -> AttrSet -> Bool

Examples

lib.attrsets.matchAttrs usage example

matchAttrs { cpu = {}; } { cpu = { bits = 64; }; }
=> true

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

matchAttrs =
    pattern:
    attrs:
    assert isAttrs pattern;
    all
    ( # Compare equality between `pattern` & `attrs`.
      attr:
      # Missing attr, not equal.
      attrs ? ${attr} && (
        let
          lhs = pattern.${attr};
          rhs = attrs.${attr};
        in
        # If attrset check recursively
        if isAttrs lhs then isAttrs rhs && matchAttrs lhs rhs
        else lhs == rhs
      )
    )
    (attrNames pattern);