Lex
Menu
On this page

Declarations & Metadata

In declaration mode, a .lex file evaluates to one deterministic canonical value without performing I/O, touching the network, or running effects.

Declaration primitives

PrimitiveMeaning
lexicon { ... }Tagged lexicon record holding metadata, source, inputs, outputs, and optional development.
plan { ... }Tagged system or session plan record.
described(value, meta)Attaches metadata to value transparently without changing recipe or tree hashes.
module(blake3:...)Typed content-addressed module object reference (Module_Ref).
here()Typed Tree_Ref of the source tree that holds the current declaration file.
import("path.lex")Evaluates a relative .lex file inside the same tree; refuses .., leading /, and non-.lex paths.
declaration(blake3:...)Lazy reference to the lexicon of a content-addressed tree; its value is its outputs.
recipe(builder, args)Lazy build specification identified by its domain-separated BLAKE3 recipe_hash.
store(name, rights)Store access grant using a flag set such as .Read | .Write.
github(...), git(...), archive(...), github_release(...)Typed input source records resolved through pins.lex; never touch the network during evaluation.

Attaching metadata with described

described(value, description) is transparent to every consumer of value: field access, calls, and recipe inputs see the inner value directly. Canonical recipe hashing strips descriptions so fixing a sentence triggers zero rebuilds.

let
  item = described({ value = described(40, { about = "Base value." }) }, { about = "Container." }),
  add  = described((x) => x + 2, { about = "Adds two." })
in
  add(item.value)
=>42

Lexicon metadata and SPDX validation

The freestanding lex:metadata package validates lexicon and output metadata against strict offline rules:

Canonical pins (pins.lex)

pins.lex lives beside lexicon.lex and records every pinned input in one canonical form: inputs sorted by UTF-8 byte order, one field per line in byte order. lex:pins reads only canonical evaluator output, never raw text.

{
  gt = {
    address = "https://github.com/sachahjkl/gui_toolkit",
    commit = "a2fced8cfaca4c44b980fabed8702575b2a9558e",
    tree = blake3:1111111111111111111111111111111111111111111111111111111111111111,
  },
}
=>{ gt = { address = "https://github.com/sachahjkl/gui_toolkit", commit = "a2fced8cfaca4c44b980fabed8702575b2a9558e", tree = blake3:1111111111111111111111111111111111111111111111111111111111111111 } }

A lexicon with no external inputs keeps an empty pin record {} so readers know nothing was omitted. Required pin fields are address, commit, and tree; optional fields are branch, version, signature, nix_archive_hash, and nested inputs.