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

Locking Closures in Management CI

Management CI resolves a declaration into exact store paths, checks cache coverage and native library compatibility, then publishes the signed vug.lock.

Run the lock command

Use a Linux Nix runner. Set VUG_RUNTIME_PATH to the exact store object containing bin/vug before running this example. That object, the selected package outputs and all their references must have signed narinfo in the permitted caches. Prearrange cache coverage for your vug runtime as well as your packages.

vug record lock \
  --file vug.star \
  --lock vug.lock \
  --signing-key "$VUG_SIGNING_KEY_FILE" \
  --runtime "vug=$VUG_RUNTIME_PATH:bin/vug" \
  --trust ci-trust.toml \
  --host example-host --user example-user
FlagWhat CI supplies
--file, --lockInput declaration and output lock. Defaults are vug.star and a sibling vug.lock.
--signing-keyRequired path to a Nix Ed25519 secret key file in NAME:BASE64 form. The decoded 64 bytes hold a 32-byte signing seed followed by its matching public key. The regular file must belong to the running user and have no group or other permissions. The named public key must appear in [lock_keys].
--runtimeRepeatable ID=STORE_PATH:EXECUTABLE, with the executable path relative to the store object. Include vug and, for a profile with secrets, sops.
--trustCI’s trust configuration, defaulting to the same XDG config path used on the client.
--host, --userTarget values for configure(ctx). They default to the runner’s own host and user.
--registryRepeatable ID=DIR mapping an overlay ID to its checkout. Supply it for every overlay used by a package.

Treat the lock as a generated artifact. vug resolves the attributes with nix eval using the pinned revision and package policy and disables import from derivation, a Nix feature that can require building a value during evaluation. It walks signed narinfo beginning with the selected package outputs and fixed runtime paths. The closure must include all reachable objects and contain no extraneous entries. Lock command, Closure validation.

Verify registry overlays

For each referenced overlay, CI checks that Git HEAD matches registry_rev and that porcelain status is empty, including untracked files. It uses git ls-files to enumerate tracked files, hashes each file with SHA-256, and takes the SHA-256 of the RFC 8785 canonical JSON map from relative filename to hash. That second hash must match the declared digest.

The version record at packages/<shard>/<record>/versions/<version>.star must describe an overlay with matching architecture, Nixpkgs revision, attribute path and outputs. A private record requires a private declaration overlay. The nix-package recipe overrides the previous derivation’s source and appends hashed patches. The unpack-elf recipe unpacks the upstream artifact into out and uses Nixpkgs’ ELF patching hook. Both are evaluated as Nixpkgs overlays. A nested package set with overrideScope is updated through its package scope so siblings can see the changed input. vug uses an attribute merge for plain sets. Overlay evaluation and checkout verification, Record guide.

Substitute and inspect the ABI

After resolving metadata, CI needs the actual store objects for the ABI (application binary interface) check. vug asks nix-store --realise to obtain missing paths with local jobs disabled, no builders, and fallback disabled. At this pinned version, that step works on the CI runner’s /nix/store and passes only daemon-eligible substituter URLs. Objects advertised solely by a private cache need to be present in that store already for the ABI check.

The generated lock is reloaded and validated before the store and ABI checks. It becomes visible at the requested path after those checks succeed.

ELF (Executable and Linkable Format) is the Linux binary format used for native programs and shared libraries. vug models dynamic linking for ELF64 objects:

  1. Discover ELF files recursively under each output’s bin/ and libexec/, visiting a resolved directory once even if several symlinks reach it. Shell scripts are skipped. Files with ELF magic that fail the parser are rejected.
  2. Read PT_INTERP, the program-header segment naming the dynamic loader. The segment must stay within the file, occur at most once and contain a nonempty, NUL-terminated UTF-8 path. The loader must resolve inside the Nix store and parse as ELF when visited.
  3. Resolve each DT_NEEDED entry, which names a shared-library dependency. DT_RUNPATH is the object’s own set of search directories. Its presence, even as an empty value, suppresses DT_RPATH for that object. With no DT_RUNPATH, the model searches the object’s DT_RPATH and inherited RPATH directories. It expands $ORIGIN relative to the resolved object. If the search fails, the model can use a matching loader-chain name or interpreter name already known to it, or search the interpreter’s directory.
  4. Track each SONAME, the name a shared ELF library advertises to the loader, against the file it resolves to. Every SONAME in one modeled process must resolve to one canonical store path, including dependencies crossing output boundaries. Each discovered executable is checked with every declared plugin of that package loaded into the same process. When no ELF executable is found, the plugins are checked together by themselves.
  5. Check the locked FHS library mappings under usr/lib* for multiple files with the same SONAME. The pinned implementation collects these mappings across the declaration’s FHS profiles for this check.

The ABI resolver checks paths in the realised CI store. This is a static inspection of ELF metadata and explicit plugin declarations. ELF parser and resolver, ABI check entry point.

Sign and publish

The generator hashes a canonical JSON form of the lock while omitting lock_digest and lock_signature. It signs the UTF-8 bytes vug.lock/v1\n<lock_digest>, where \n is a literal newline in the message. It serializes the lock as TOML, parses it again, and verifies it with the declaration and trust policy. For the same inputs, including the same cache metadata and key, the result is byte-identical. After substitution and ABI inspection, vug writes a temporary file beside the destination, syncs it, atomically renames it over the lock and syncs the parent directory. Generation and atomic write.

Interpret locking failures

When the JSON error has detail.classification, use it to locate the stage that failed.

ClassificationMeaningCode and exit
evaluation_refusedThe selected package or outputs could not be evaluated under the pin and policy, for example because the package is unfree and disallowed.UNRESOLVED, 254
not_builtThe requested package output has no narinfo in any permitted cache.UNRESOLVED, 254
redistribution_deniedAn output is missing and Nixpkgs license metadata marks the package as non-redistributable.UNRESOLVED, 254
cache_missingA required closure path is absent from every permitted cache, or the later CI substitution step failed.CACHE_MISSING, 254
unavailable_unknownNo cache supplied the metadata and a transport failure prevents a definitive miss.UNRESOLVED, 255

Signature errors, invalid declarations and ABI failures can instead report INVALID_INPUT. Check standard error for their diagnostic text. Classification and resolution, JSON errors.