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 (narHash), not an error.
| Name | nix |
|---|---|
| Predicate type | https: |
| Lifecycle | prematerial |
| Default binary? | No |
| Category | build (primary) |
| Recommended trace | off — no syscall tracing needed |
| Auto-attaches when |
|
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:.
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 -- makeThe attestor lists the closure with the runner's own nix-, found at fixed locations (/nix/var/nix/, then /run/) 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/, owned by root and not writable by group or other. Nix installs one program, nix, and links nix- to it, so the verified target is started under the name nix-. It runs with a minimal environment of its own (PATH is its directory, HOME an empty private directory), so a dev shell's LD_, library paths and NIX_, NIX_ or plugin- overrides do not reach it. It opens the host's store read-only, directly (--store local), not through the daemon: a daemon's allowed- 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
profileandprofiles[]: each profile the attestor resolved, with the profile as named (path), where it came from (source:flagorNIX_) and the store object it resolves to (PROFILES 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.profileslists every profile that resolved, in the order named;profileis the last. No generation number, no home profile, no system default and noPATHsearch is recorded: a profile that is not named is not guessed.missingProfiles: theNIX_entries that do not exist or are not in the store, always present (an empty list when none is missing).PROFILES roots: the store objects the closure was computed from, one per profile that resolved. With--attestor-nix-it is the named profile's object; without it, the profile of eachprofile NIX_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 noPROFILES 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), anderrorwhen 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> <narHashline per closure path in path order. It is left out, with aRecomputed>\n gapsentry, when the closure cannot be taken as whole: any path could not be hashed,nix-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 instore closure.closureCount,narHashMismatchesandnarBytessummarize.flakeLock:path,sha256andsizeof 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-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.flake-lock 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_, defaultCONF_DIR /etc/nix/nix.conf), the user files, every file one of them includes, andNIX_as a pseudo-source. Each has itsCONFIG path,sha256,scope(system, user or env) andsizein bytes.lines[]is one list for all sources, in the order Nix applied them: each entry is a trust-relevant assignment as written with thesourceindex 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, andnameis as written (substituters,extra-,substituters trusted-,substituters trusted-,public-keys extra-,trusted- public-keys require-sigs,trusted-,users store,extra-,store plugin-, and the otherfiles extra-forms) andvalue. 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_(presence only, its text is a source),CONFIG NIX_,REMOTE NIX_,DAEMON_ SOCKET_PATH NIX_andSTORE_DIR NIX_, each with whether it is set and its value (a URL without credentials). A variable set to nothing is set:STATE_DIR NIX_switches user configuration off, and the record says it was set.USER_ CONF_ FILES= redactionslists what was removed from URLs (see below).nixVersionandnixStore(path and sha256 of thenix-that answered),store storeDir(present only whenNIX_declared it or the verifiedSTORE_DIR nix-'s own location established it), andstore gaps.
Subjects: nix:, digested by closureDigest, and nix:, 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- names the profile; without it the attestor reads the NIX_ entries. Nothing else is searched for. --attestor-nix- names the lock, default flake.lock in the working directory.
Why this shape
A store path such as /nix/ 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/ 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 a4edc4a61142d133fa329190d9c2b722. 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: 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.jsonCompare one entry with Nix: nix path- gives the database's narHash in SRI form, and nix hash convert --hash-algo sha256 --to base16 <sri> (nix hash to- 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:against the closure of the host-apply step, andclosure nix:against theflake-lock flake.lockat the commit under build. - Treat a record with
gapsas incomplete: a policy that requires a closure refuses it. A record withnarHashMismatchesabove zero names, per path, which one differs. - To use a closure as evidence of content, require
narHashandnarHashRecomputedto 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-and the claimed hashes fromstore --query --requisites nix-, not from readingstore --query --hash /nix/var/nix/db/db.. 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.sqlite - URLs are not copied verbatim. In
substituters,trusted-,substituters storeand the other URL settings insources[].lines,redirects[].value, and a flake input'surl, 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.redactionsrecords 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_, or theREMOTE storesetting, anything but plainlocal,autoordaemon),nix-would answer about that store while the paths are hashed from this host's disk. The selector is judged as written, before URL cleaning, sostore local(or any parameter such as?root=/alt store=orstate=) is untied too. The attestor then reads no closure, records a gap, and emits nonix:subject.closure - 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 HOMEandXDG_*,NIX_,CONF_DIR NIX_,USER_ CONF_ FILES includeand!include(in a file or inNIX_), theCONFIG flake.lockflag and the entries ofPATH. 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_orSTORE_DIR NIX_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.STATE_DIR - The store directory is the one
NIX_declares, elseSTORE_DIR /nix/, resolved once per attestation as the filesystem has it.store storeDirin 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_; the last assignment wins;CONFIG storeis a single value, soextra-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 plainstore local,daemonorauto, permits the query, so an overriddenstoredoes not withhold the closure and a later one does.= local ?root=/alt NIX_is judged the same way.REMOTE - 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.confis read the way Nix layers it, withincludeand!includefollowed. 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 aNIX_set to nothing, aCONF_DIR NIX_of only whitespace, or anUSER_ CONF_ FILES XDG_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 sayCONFIG_HOME 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
errorand agapsline, andclosureDigestis left out. - A closure query that lists something outside the store directory is not opened or hashed; the entry count is in
gaps. NIX_lists the default profile and the user's. Each one that resolves is a root, so the closure is their union; passPROFILES --attestor-nix-to record one profile alone.profile - A profile named with
--attestor-nix-that is not there is a gap, and the record has noprofile closureDigestornix:subject. The entries ofclosure NIX_are candidates instead. Nix's own shell setup (PROFILES nix-) sets it to the system profile anddaemon.sh $HOME/, and the second is absent on a healthy host, so a missing entry is listed in.nix- profile 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 onPATHare not recorded (nix-fleet.md D-21).
FAQ
Does it need root? No, but the nix- it asks must be root's. It reads the store and runs nix-, which a normal user can do with a running daemon.
Does it check signatures? No. trusted- 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/ 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- 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.