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

Constant (Atom Wrapper)

Definition

Constant Atom

Fields

FieldTypeDescription
contentsAtomThe atomic value (Int, Float, Bool, Null, Uri)

Description

Constant wraps an Atom to make it a valid expression node. All literal values in Nix (integers, booleans, null, URIs) are represented as Constant containing an Atom.

Nix Source ↔ AST

# Nix
42

# AST
{
  "tag": "Constant",
  "contents": { "tag": "Int", "contents": 42 }
}
# Nix
true

# AST
{
  "tag": "Constant",
  "contents": { "tag": "Bool", "contents": true }
}
# Nix
null

# AST
{
  "tag": "Constant",
  "contents": { "tag": "Null" }
}
  • Atom: the wrapped atomic types (Int, Float, Bool, Null, Uri)
  • See Atoms for atom constructors

Nix Library Access

syntax.mkConstant (syntax.mkInt 42)
syntax.mkConstant (syntax.mkBool true)
syntax.mkConstant syntax.mkNull