Cache Operations
The Aeroflare CLI provides three core cache-related commands that interface with OCI registries to store, retrieve, and transparently proxy Nix build artifacts. The underlying mechanics of these commands bridge standard POSIX/Nix conventions with our OCI-backed registry storage.
push
The push command (cmd/push.go) handles the serialization and uploading of Nix store paths into the configured OCI registry.
Mechanics & State Changes
- Registry Resolution: Uses
network.GetRegistryAndRepository()to determine the target OCI registry and fetches the associated authentication token. - Configuration Parsing: Passes the CLI arguments,
--store-path,--input, andos.Stdintopush.ParseConfig()to resolve the target paths. - Preflight Evaluation: Executes
push.Preflight(cfg)to calculate a deployment plan. This involves:- Validating paths and checking upstream cache (
--upstream-cache) to determine which paths already exist. - Determining references to prepare if
--prepare-refsis enabled.
- Validating paths and checking upstream cache (
- Execution: If the preflight plan succeeds, it outputs a summary via
push.DisplaySummary(plan)and performs the upload viapush.RunPush(plan).
Flags
--store-path: Explicit Nix store path to prepare and push (e.g.,/nix/store/xxx-yyy).--input: File containing store paths (one per line,#for comments).--compression(default:zstd): Compression algorithm to use (zstd,xz,gzip,none).--upstream-cache(default:https://cache.nixos.org): Upstream binary cache URL. Leaving this empty skips reference checking.--workers(default:50): Number of concurrent workers for uploading blobs.--prepare-refs(default:true): Prepares references that are not present on the upstream cache.--signing-key: Path to the Nix signing private key file to sign the generated.narinfo.--keep(default:false): Keeps generated.narand.narinfofiles locally after the push is completed.--force(default:false): Forces a push even if the files exist in the index or upstream cache.
run
The run command (cmd/run.go) wraps arbitrary shell commands to transparently push Nix store paths generated or referenced during the execution.
Mechanics & State Changes
- Index Directory Resolution: Determines the proxy index directory via
getIndexDir(repository). - Command Execution: Invokes
run.ExecuteCommand()passing the wrapped command, registry, repository, index directory, and token. This executes the target command, potentially injecting the proxy substituting mechanism. - Path Detection:
ExecuteCommandcaptures standard output and identifies generated Nix store paths. - Transparent Push: If target paths are detected,
run.goautomatically triggers thepushmachinery. It constructs apush.PushConfigreusing the same CLI flags as thepushcommand, runspush.Preflight(), and subsequentlypush.RunPush().
Flags
The run command re-uses the flags from push to define cache upload behavior:
--compression,--upstream-cache,--workers,--prepare-refs,--signing-key,--keep,--force.
proxy
The proxy command (cmd/proxy.go) initializes a local HTTP proxy server designed to intercept and serve Nix binary cache requests, querying the OCI registry or falling back to upstream caches.
Mechanics & State Changes
- Environment Configuration: The proxy heavily relies on environment variables for configuration instead of CLI flags.
- Index Directory Setup: Uses
getIndexDir()to define where the proxy stores its local index. It checks environment variables in the following order of precedence:AEROFLARE_INDEX_DIRNIXCACHE_INDEX_DIRCACHE_DIRECTORY- Fallback:
~/.cache/aeroflare-proxy/<repository-slug>(slashes in the repository are replaced with--).
- Server Initialization: Intercepts
SIGINTandSIGTERMto gracefully cancel the context. - Start: Calls
proxy.StartProxy()which binds to the designated address/port and begins serving requests, using the resolved registry token for authentication.
Environment Variables
NIXCACHE_PORT(default:37515): The TCP port the proxy binds to.NIXCACHE_LISTEN(default:127.0.0.1): The interface address to listen on.NIXCACHE_UPSTREAM(default:https://cache.nixos.org): Space-separated list of upstream cache URLs.