Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

HasAttr (Has Attribute)

Definition

HasAttr { expr :: Expr, attrPath :: AttrPath }

Fields

FieldTypeDescription
exprExprThe expression to check (typically a set)
attrPathAttrPathThe attribute path to check for

Description

HasAttr represents the ? operator in Nix, which checks whether an attribute exists in a set. Returns a boolean.

Nix Source ↔ AST

# Nix
set ? attr

# AST
{
  "tag": "HasAttr",
  "expr": { "tag": "Sym", "contents": "set" },
  "attrPath": [
    { "tag": "StaticKey", "contents": "attr" }
  ]
}
# Nix
set ? a.b.c

# AST
{
  "tag": "HasAttr",
  "expr": { "tag": "Sym", "contents": "set" },
  "attrPath": [
    { "tag": "StaticKey", "contents": "a" },
    { "tag": "StaticKey", "contents": "b" },
    { "tag": "StaticKey", "contents": "c" }
  ]
}
  • AttrPath: attribute path structure
  • Select: attribute selection (with default)

Nix Library Access

syntax.mkHasAttr (syntax.mkSym "set") [syntax.mkStaticKey "attr"]