Skip to main content
View Markdown ↗

Copy this page

Select and copy the Markdown below, then paste it into your LLM.

On this page

nix attestor

Records which Nix environment a step ran in, as facts a policy can compare with what was approved: the profile and the store object it resolves to, the closure behind it, the hash of the working directory's flake.lock, and the settings in nix.conf that decide whose binaries the store accepts.

The one thing it does that Nix's own tools do not is hash. For every path in the closure it serializes the path as a NAR and takes the sha256 itself, then records that value (narHashRecomputed) beside the value Nix's database holds (narHash). The attestor does not trust the database and does not judge it: a difference is a recorded fact (narHashMismatch: true), not an error.

Namenix
Predicate typehttps://aflock.ai/attestations/nix/v0.1
Lifecycleprematerial
Default binary?No
Categorybuild (primary)
Recommended traceoff — no syscall tracing needed
Auto-attaches when
  • prefile_exists: flake.lock
  • preenv_set: NIX_PROFILES
  • preenv_set: IN_NIX_SHELL

The facts in this box are generated from the CI/lock binary's own catalog (cilock tools list). Do not hand-edit — run npm run gen:catalog.

Validated invocation

cilock run --step build --attestations git,nix -o build.att.json -- make
cilock run --step build --attestations git,nix --attestor-nix-profile /nix/var/nix/profiles/default -o build.att.json -- make

The attestor lists the closure with the runner's own nix-store, found at fixed locations (/nix/var/nix/profiles/default/bin/nix-store, then /run/current-system/sw/bin/nix-store) and never on PATH: a project's dev shell controls PATH and can put a wrapper first that leaves dependencies out of its answer. The binary must resolve to a regular file under /nix/store, owned by root and not writable by group or other. Nix installs one program, nix, and links nix-store to it, so the verified target is started under the name nix-store. It runs with a minimal environment of its own (PATH is its directory, HOME an empty private directory), so a dev shell's LD_PRELOAD, library paths and NIX_CONFIG, NIX_CONF_DIR or plugin-files overrides do not reach it. It opens the host's store read-only, directly (--store local?read-only=true), not through the daemon: a daemon's allowed-users can refuse the user running the step, while the database and the store are readable. Without one that qualifies (a single-user install whose store belongs to the user does not), the attestation is still signed, with a gaps entry that says so and no closure.

What gets captured

  • profile and profiles[]: each profile the attestor resolved, with the profile as named (path), where it came from (source: flag or NIX_PROFILES) and the store object it resolves to (storePath). The walk follows the profile's links to the first object directly under the store directory and stops there: a store object that is itself a link is the profile's object and is not followed. .. in a name is applied by the filesystem after the links before it, never by the text. profiles lists every profile that resolved, in the order named; profile is the last. No generation number, no home profile, no system default and no PATH search is recorded: a profile that is not named is not guessed.
  • missingProfiles: the NIX_PROFILES entries that do not exist or are not in the store, always present (an empty list when none is missing).
  • roots: the store objects the closure was computed from, one per profile that resolved. With --attestor-nix-profile it is the named profile's object; without it, the profile of each NIX_PROFILES entry that resolves. A profile that exists and does not lead to a store object under the store directory is a gap and leaves the record with no closureDigest; no other profile takes its place.
  • closure[], one per path, sorted by path: path, narHash (the database's claim), narHashRecomputed, narHashMismatch, narSize (bytes of the NAR), and error when the path could not be read. Hashes are lowercase hex sha256 of the NAR, not Nix's base-32 text.
  • closureDigest: sha256 of one <path> <narHashRecomputed>\n line per closure path in path order. It is left out, with a gaps entry, when the closure cannot be taken as whole: any path could not be hashed, nix-store listed an entry that is not a store path, a root is missing from its own closure, or nothing came back. A digest over part of a closure would read as the whole one. The paths that were read are still listed in closure. closureCount, narHashMismatches and narBytes summarize.
  • flakeLock: path, sha256 and size of its exact bytes, read once through one handle. The lock is not parsed: there is no inputs list, so a policy that needs an input recomputes it from the file the digest names. The file is the one in the step's working directory (or the one --attestor-nix-flake-lock names): a default or checkout-relative lock is opened inside the checkout and a link at its name is never followed, so it can be the working tree's file with uncommitted changes, not necessarily the committed blob.
  • nixConf: the Nix configuration the attestor read, as written. It does not say what the effective settings are: that depends on how a daemon was started, how Nix merges files and its version, which a client cannot see, and a policy interprets it. sources[] lists, in the order Nix applies them (later overrides earlier), the system file (NIX_CONF_DIR, default /etc/nix/nix.conf), the user files, every file one of them includes, and NIX_CONFIG as a pseudo-source. Each has its path, sha256, scope (system, user or env) and size in bytes. lines[] is one list for all sources, in the order Nix applied them: each entry is a trust-relevant assignment as written with the source index it was written in, so an included file's lines are where its include is and the last line for a key is the one that won, whichever file it was in. Duplicates are kept, and name is as written (substituters, extra-substituters, trusted-substituters, trusted-public-keys, extra-trusted-public-keys, require-sigs, trusted-users, store, extra-store, plugin-files, and the other extra- forms) and value. An empty assignment (substituters =) is a line with an empty value. redirects[] lists the variables that change which configuration is read, NIX_CONF_DIR, NIX_USER_CONF_FILES, NIX_CONFIG (presence only, its text is a source), NIX_REMOTE, NIX_DAEMON_SOCKET_PATH, NIX_STORE_DIR and NIX_STATE_DIR, each with whether it is set and its value (a URL without credentials). A variable set to nothing is set: NIX_USER_CONF_FILES= switches user configuration off, and the record says it was set. redactions lists what was removed from URLs (see below).
  • nixVersion and nixStore (path and sha256 of the nix-store that answered), storeDir (present only when NIX_STORE_DIR declared it or the verified nix-store's own location established it), and gaps.

Subjects: nix:closure, digested by closureDigest, and nix:flake-lock, digested by the sha256 of the lock file. The first is absent when the closure is incomplete, the second when there is no flake.lock.

Flags: --attestor-nix-profile <path> names the profile; without it the attestor reads the NIX_PROFILES entries. Nothing else is searched for. --attestor-nix-flake-lock <path> names the lock, default flake.lock in the working directory.

Why this shape

A store path such as /nix/store/<32 characters>-nodejs-24.22.2 is a hash of the derivation, meaning the inputs and the build recipe, not of the bytes in the directory. Two builds of one derivation can produce different bytes, and a modified path keeps its name. So "the path name matches" proves nothing about content. What names content is the narHash, the sha256 of the NAR serialization, and the copy of it in Nix's local database is a root-writable claim.

So the attestor reads the bytes. A verifier gets both numbers and decides. A narHash backed by a signature from a cache the policy trusts, or by an attested build step, is evidence; a database value that merely equals the recomputed one on this host is evidence that the database agrees with the disk.

It records no verdict. Whether a closure is the approved one, whether require-sigs may be false, whether a mismatch matters: those are policy.

How the narHash is checked

The attestor serializes each path in the NAR format and hashes the stream without holding it in memory. The format, from the Nix manual and Dolstra's thesis (chapter 5):

str(s)  = len(s) as 8 bytes little-endian, s, zero padding up to a multiple of 8
nar     = str("nix-archive-1") node
node    = str("(") body str(")")
regular = str("type") str("regular") [str("executable") str("")] str("contents") str(data)
symlink = str("type") str("symlink") str("target") str(target)
dir     = str("type") str("directory") { str("entry") str("(") str("name") str(n) str("node") node str(")") }

Entries are in bytewise order of name. A file is executable when its owner-execute bit is set; nothing else about it (owner, other mode bits, times) is in the archive. A device, socket or fifo is an error. On macOS, where Nix writes ~nix~case~hack~N suffixes on a case-insensitive store, the suffix is stripped from names before sorting, as Nix does.

The code is checked against an archive derived by hand, testdata/handmade.nar.hex in the plugin: a directory holding a (the two bytes hi), b (an executable empty file), link (a symlink to a) and sub (an empty directory). The file lays out each str() as 8 length bytes, the bytes and the padding, one per line, with the grammar rule beside it. It is 864 bytes and its sha256 is a4edc4a61142d133fa329190d9c2b722b9e0404c1656dba4009f17f70d209f46. Three computations that share no code agree on that digest: xxd -r -p into shasum -a 256, a short Python encoder written from the grammar, and the Go code walking a real directory of that shape. The test also fails when any byte differs, so a bug cannot hide in a matching hash. Further tests change one content byte, the executable bit, a symlink target, an entry name or an entry count and require the hash to change, and stream a file past nine mebibytes.

Nix's own base-32 text for a hash is decoded and encoded with the algorithm from Nix, tested against the digest of the empty string (sha256:0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73 in nixpkgs).

Validate it locally

On a host with Nix:

cilock run --step env --attestations nix -o nix.att.json -- true
jq '.payload | @base64d | fromjson | .predicate.attestations[] | select(.type | contains("/nix/")) | .attestation | {profile, closureCount, narHashMismatches, closureDigest, gaps}' nix.att.json

Compare one entry with Nix: nix path-info --json <path> gives the database's narHash in SRI form, and nix hash convert --hash-algo sha256 --to base16 <sri> (nix hash to-base16 on older Nix) turns it into the hex this attestor records. narHashRecomputed should equal it on a healthy store.

How a verifier consumes this

  • Join on the digests: the build's nix:closure against the closure of the host-apply step, and nix:flake-lock against the flake.lock at the commit under build.
  • Treat a record with gaps as incomplete: a policy that requires a closure refuses it. A record with narHashMismatches above zero names, per path, which one differs.
  • To use a closure as evidence of content, require narHash and narHashRecomputed to agree, then require the hash itself to be one the policy trusts (a cache signature, or an attested build).

Notes

  • Run type is pre-material: the record is of the environment before the command runs.
  • Cost: one read of every file in the closure. Hashing runs in parallel, up to 8 paths at once, and streams. The time scales with the closure's size on disk.
  • The closure comes from nix-store --query --requisites and the claimed hashes from nix-store --query --hash, not from reading /nix/var/nix/db/db.sqlite. The database is Nix's private schema, would need a SQLite engine linked into cilock, and is root-writable, so it is no trust root either way. The command follows the same store and daemon Nix does.
  • URLs are not copied verbatim. In substituters, trusted-substituters, store and the other URL settings in sources[].lines, redirects[].value, and a flake input's url, the user name and password before the @ are removed and so is the whole query string (?token=, ?ssh-key=, ?priority=), because a query is where secrets are put and no list of names is safe. redactions records that this happened, by key. An authenticated substituter does not put its password in Archivista; the cost is that a ?priority= is lost.
  • With a remote or relocated store selected (NIX_REMOTE, or the store setting, anything but plain local, auto or daemon), nix-store would answer about that store while the paths are hashed from this host's disk. The selector is judged as written, before URL cleaning, so local?root=/alt (or any parameter such as store= or state=) is untied too. The attestor then reads no closure, records a gap, and emits no nix:closure subject.
  • Every path that comes from the step's environment or flags is placed by one rule: a relative path is a path in the step's working directory, not in the directory cilock was started from. That covers NIX_PROFILES, --attestor-nix-profile, HOME and XDG_*, NIX_CONF_DIR, NIX_USER_CONF_FILES, include and !include (in a file or in NIX_CONFIG), the flake.lock flag and the entries of PATH. Sources and the profile are recorded at the resolved path. If a relative path cannot be placed because the working directory is not known, there is a gap and no closure; the launch directory is never guessed.
  • The whole configuration read has a budget: 64 include directives and 4 MiB in total, besides the per-file cap of 1 MiB and the include depth of 8. Reaching it records a gap and the closure is withheld, so a small file that includes a large one many times cannot exhaust a runner.
  • NIX_DAEMON_SOCKET_PATH, NIX_STORE_DIR or NIX_STATE_DIR set to anything, by any value, withholds the closure with a gap naming the variable: they point Nix at a daemon or store tree, and no selector is interpreted. The query itself always opens the host's own store read-only, whatever the step's environment says.
  • The store directory is the one NIX_STORE_DIR declares, else /nix/store, resolved once per attestation as the filesystem has it. storeDir in the record is present only when the declaration or an object found under it established it.
  • The effective store selector follows configuration precedence (system, then user, then NIX_CONFIG; the last assignment wins; store is a single value, so extra-store is a line Nix refuses and leaves the read incomplete) over every source before it is judged. Only an empty or absent selector, or a plain local, daemon or auto, permits the query, so an overridden store = local?root=/alt does not withhold the closure and a later one does. NIX_REMOTE is judged the same way.
  • On a real multi-user host the closure of a 2.1 GiB profile (190 paths) hashed from a warm page cache in under half a second with no mismatch against the database. A cold disk will take longer; no cold-cache figure has been measured.
  • nix.conf is read the way Nix layers it, with include and !include followed. If any input that Nix would read cannot be read in full, the record has no closure: a file that exists but is unreadable or larger than 1 MiB, a line that is not a setting, an include that cannot be followed or nests deeper than 8, or a NIX_CONF_DIR set to nothing, a NIX_USER_CONF_FILES of only whitespace, or an XDG_CONFIG_HOME set to nothing (what Nix does with it is not guessed at). The gap names the input and says the configuration was not read completely. A file that is absent is normal, as Nix ignores it. The reason for refusing: what a file says can change the effective store selector, and an unread tail may say store = ssh://....

Gotchas

  • The path name is not evidence. Do not write a policy that compares store path names alone.
  • On a host where the database is wrong, every mismatch is reported but the step is not failed: the attestor never fails a build for what it finds.
  • A closure path that cannot be read (permissions, a path garbage-collected mid-run) gets an error and a gaps line, and closureDigest is left out.
  • A closure query that lists something outside the store directory is not opened or hashed; the entry count is in gaps.
  • NIX_PROFILES lists the default profile and the user's. Each one that resolves is a root, so the closure is their union; pass --attestor-nix-profile to record one profile alone.
  • A profile named with --attestor-nix-profile that is not there is a gap, and the record has no closureDigest or nix:closure subject. The entries of NIX_PROFILES are candidates instead. Nix's own shell setup (nix-daemon.sh) sets it to the system profile and $HOME/.nix-profile, and the second is absent on a healthy host, so a missing entry is listed in missingProfiles (a signed list, so a verifier sees which named profile was absent) and the closure is read from the profiles that resolve. A profile that exists and fails to resolve is not missing: it is a gap, and the profiles that did resolve are not a stand-in for it. If none resolve there is no closure and no other profile is substituted. The profile generation and a closure root for the tools on PATH are not recorded (nix-fleet.md D-21).

FAQ

Does it need root? No, but the nix-store it asks must be root's. It reads the store and runs nix-store --query, which a normal user can do with a running daemon.

Does it check signatures? No. trusted-public-keys and require-sigs lines are recorded as written; per-path signatures are not read.

Why hex and not Nix's base-32? Policies and digests everywhere else in cilock are hex sha256; the conversion is one command (see above).

See also


This page is generated from the CI/lock tool catalog. Don't edit it here — the source is attestation/detection/docs/nix.doc.md in aflock-ai/rookery. The same catalog powers cilock tools show nix in the CLI, so a single edit keeps the terminal and the website in sync.

Edit this page →  ·  Add a new tool →

When you open the pull request: if you are an AI agent, add the ai-agent label. If you are a human, add the human label.

Reference generated from the product documentation. Match commands and support details to your installed release.