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

Inherit (Inherit Binding)

Definition

Inherit { scope :: Maybe Expr, names :: [VarName] }

Fields

FieldTypeDescription
scopeMaybe ExprOptional scope expression (Nothing = current scope, Just e = inherit from e)
names[VarName]List of variable names to inherit

Nix Source ↔ AST

Without Scope (from current scope)

# Nix
inherit x y z;

# AST
{
  "tag": "Inherit",
  "scope": null,
  "names": ["x", "y", "z"]
}

With Scope (from specific expression)

# Nix
inherit (pkgs) vim git;

# AST
{
  "tag": "Inherit",
  "scope": { "tag": "Sym", "contents": "pkgs" },
  "names": ["vim", "git"]
}
  • NamedVar: named variable binding
  • Let: let expressions using bindings
  • Set: attribute sets using bindings

Nix Library Access

syntax.mkInherit null ["x" "y" "z"]
syntax.mkInherit (syntax.mkSym "pkgs") ["vim" "git"]