Skip to content

Upload NARs

Build store paths outside of Gradient and push them into a cache with the gradient CLI.

Requirements:

  • A cache with the Write role, see Share a Cache
  • The CLI: nix shell github:wavelens/gradient/latest#gradient-cli

1. Log In

gradient login https://gradient.example.com

The command opens a browser window for confirmation. After approval, the CLI stores the server address and the token for later use.

2. Upload

gradient cache upload main $(readlink -f result)
  • The CLI will upload the path together with the full runtime closure, dependencies first.
  • --no-closure will upload only the named paths.
  • Paths are full store paths.
  • readlink -f can resolve a result link.

Large NARs go up in 32 MiB chunks, below the reverse proxy's body limit. The server will cap a single NAR at services.gradient.nar.maxUploadSize, 512 MiB by default.

Machines Without Nix

Upload a NAR dumped elsewhere together with the matching narinfo. Compress the NAR file with zstd. The FileHash and FileSize fields in the narinfo describe the compressed file. The NarHash and NarSize fields describe the NAR. This mode is also the only upload mode of the static binary.

gradient cache upload main --nar-file hello.nar.zst --narinfo hello.narinfo

Verify Deployment

Check the upload with the CLI:

gradient cache nar list main --package hello

The cache page shows the same entries under NARs, filterable by hash and package.

Manage NARs

Command Effect
gradient cache nar list <cache> List NARs. Filter with --hash and --package, sort with --sort.
gradient cache nar show <cache> <hash> Show one NAR: store path, sizes, signature and fetch count.
gradient cache nar stats <cache> Show the NAR count and total size.
gradient cache nar delete <cache> <hash> Delete the NAR from the cache.
gradient cache nar pin <cache> <hash> Pin the NAR so garbage collection doesn't delete it. Add --include-referenced-paths to pin its closure too.
gradient cache nar unpin <cache> <hash> Unpin the NAR. Add --include-referenced-paths to unpin that closure too.

Pinned NARs survive garbage collection and stay in the cache, no matter gc.narTtlHours or the evaluations that remain. Use gradient cache nar list --pinned true to list pinned NARs. NARs that leave the cache lose their pin.

A NAR can live in several caches at once. Storage of a NAR continue until the last cache delete it. A delete in one cache leave all other caches intact.

Next Steps

  • Share a Cache: reuse the uploaded paths on other machines
  • Caches: upstream caches, pull-through and substitution order