Transfer¶
Worker and server exchange four kinds of data: NARs, logs, build progress and credentials.
Workers always compress NARs with zstd. The server never re-compresses them.
Upload¶
sequenceDiagram
participant W as Worker
participant S as Server
W->>S: CacheQuery { mode: Push }
S->>W: CacheStatus (cached or not)
W->>S: UploadRequest { request_id, object, size }
S->>W: UploadGrant { Skip / Passthrough / Put / Multipart }
W->>S: UploadChunk ... (Passthrough only)
W->>S: UploadFinished { metadata }
S->>W: UploadCommitted { Ok / Retry / Rejected }
| Grant | When | Transfer |
|---|---|---|
Skip |
The path is already stored, or the project has no writable cache for an evaluation cache segment | Nothing |
Passthrough { resume_offset } |
Local NAR storage | UploadChunk frames of worker.nar.chunkBytes into <baseDir>/nar-partial, resuming after a break |
Put { url } |
S3, NAR up to 256 MiB | A single signed PUT to a temporary object under nar-uploads/. The URL and lease duration are 1 hour plus transfer time at 256 KiB/s. |
Multipart |
S3, NAR over 256 MiB | Presigned parts of at least 64 MiB |
- Admission applies server-wide and treats all sessions fairly.
- The limits are
upload.concurrency(8) large uploads andupload.bytesBudget(8 GiB) at once. - Small uploads of at most 1 MiB of NAR (
SMALL_UPLOAD_BYTES) get a window of their own,SMALL_UPLOADS_IN_FLIGHT(128). - Each
EvalResultbatch of an evaluation must wait for the push of its own.drvfiles, so a small upload cost two round trips. - Small uploads go ahead of larger ones within their session. Sessions with a waiting small upload get served first.
- Count and bytes of a permit come back after the object landed in storage, ahead of the graph record.
- Requests for a path coalesce across workers, REST and SSH. Followers get
Skiponce the graph recorded the first upload. - After a failed first upload, followers take over the path.
- The limits are
- Worker Side:
worker.nar.maxConcurrentUploads(16) slots for large uploads and 128 for small ones.- One job can hold at most half of the large slots.
- A slot is busy from the request until the worker sent
UploadFinished. The commit does not count. - Commits reach the graph writer in bursts, and it batch them.
- The worker can retry a
Retryup to 3 times. ARejectedanswer made the upload fail. - Both rules also hold for an answer arriving before the grant.
- A failed transfer or an abandoned request led to an
UploadCancelmessage.
- Commit: The server does the calculation of the NAR hash, NAR size, file hash, and file size for all transfer types. It compares those values with the declared values from the worker. A mismatch makes the server reject the upload. The server inspects passthrough uploads inside the staged file, then moves them to the NAR store.
- Presigned PUT requests and multipart uploads store data at a temporary object key. Commits read the object back. They decode it and run the same checks. Reads abort once the number of bytes read is above the declared size. Commits move the object to the NAR store key only when no other content is present at that path. Commits delete the object otherwise. S3 can copy only up to 5 GiB per request, so objects over 5 GiB on S3 stream to the final key. Deep garbage collection can remove remnants older than 14 days. 14 days is twice the longest upload lease.
- Leases: A passthrough upload expired after
upload.leaseIdleSecs(300 s) without progress. A failed job or closed session released its uploads. - Evaluation cache segments reuse the same handshake, with
UploadObject::EvalCacheSegmentandUploadMetadata::EvalCacheas the payload types.- A request over 8 MiB (
SEGMENT_MAX_BYTES) gotRejected. - Every grant carried a fresh object key
eval-cache-segments/<cache>/<fp>/<uuidv7>. The commit wrote to that key. - A commit can produce an
eval_cache_storerow. A delayed compaction for the cache in the key can follow, see Shared Eval Cache.
- A request over 8 MiB (
Download for a Build¶
Before any build work starts, workers fetch all inputs that the local store does not have yet.
- Query missing paths with
CacheQuery { mode: Pull }. A path without a cache entry aborts the build with failure kindInputsUnavailable. - Download paths with a presigned
urldirectly: 8 downloads in parallel, 4 attempts each. The timeout applies to the time without a byte (30 s), not to total length. - Fetch all other paths through
NarRequest. The server answers each path withNarStreamHeaderfollowed byNarPushframes ofnar.chunkBytes, or with aNarUnavailable/NarAbortmessage. - Recover a broken stream with
NarRequestResume { received_bytes, stream_token }, based on the partial data in<baseDir>/nar-partial. -
Import the NARs into the Nix store in dependency order.
-
Presigned downloads and
NarPushstreams both stage the compressed NAR under<baseDir>/nar-partial. - Jobs on the same worker share the transfer of a path, presigned or streamed. Later jobs read the same staged file.
- The staged file disappears with its last job, including failed or aborted jobs.
- Jobs waiting on a failed transfer fail with it.
- A NAR that does not pass the size and hash check leaves the shared transfers. The next job downloads it again.
- Workers decompress each NAR from its staged file as a stream, first for the size and hash check, then into the Nix daemon.
- Workers skip the import of a path that another job imported in the meantime.
| Condition | Delivered As |
|---|---|
S3 store, NAR over nar.smallBytes (1 MiB) |
Presigned GET URL |
| Anything else | Stream over /proto, at most nar.maxConcurrentServes (8) paths per connection and nar.maxConcurrentDownloads (16) across all connections |
- Small NARs come from an in-memory hot cache,
nar.hotCacheBytes(512 MiB). - A
NarUnavailableanswer also removes the stale cache row on the server. - A storage error or timeout answers with
NarAbortand leaves the row and object in place. - A substitute build can obtain an upstream URL through a single-path
Pullquery withexternalset.
Logs¶
- Workers stream build output over the bulk lane as
LogChunk { job_id, data }messages with no acknowledgement. - The server can append every chunk to the open attempt of the job's build.
- Chunks for evaluations or finished attempts get dropped by the server.
- Workers cap each build's log at
worker.log.burstBytesPerMin(32 MiB) andworker.log.sustainedBytesPerHour(512 MiB). - The worker can pause forwarding and add a pause note past either limit. The worker can resume after both limits have headroom again and add a note with the number of skipped lines.
- A build already in the store can forward its stored Nix log with
worker.log.fetchFromStore(on by default). - The log ends up as zstd chunks of
log.chunkBytes(256 KiB), each carrying a chunk index after the build.
Build Progress¶
- One
BuildProgressmessage can report the transfers of a single build. It splits them into three phases, and each phase reports bytes and paths done and total.
| Phase | Transfer | Bytes |
|---|---|---|
Prefetch |
Missing inputs pulled from the Gradient cache before the build | Compressed NAR files, totals growing with each closure round |
Download |
A substitute or builtin:fetchurl download |
Compressed NAR file or the downloaded file |
Upload |
Uncached outputs of the build, sent at the end of the job | NAR bytes read from the store |
- Workers report on a change at most once per second, plus one final report at the end of each phase.
bytes_totalcan beNonewhen a size is unknown.paths_totalcan beNoneduring prefetch, while path discovery is still in progress. The final report of a phase always includes the total.- A retried or failed transfer count only once.
- The server keeps the latest value per build in memory for 15 s.
- The build response shows the value only while the build has the
Buildingstatus. - A build stays
Buildinguntil its job has finished the upload. - The server also sends
BuildProgressevents to the live endpoints. - Eval workers report fetch rows or live thunks through
EvalProgress, at most once per second on a change. - After 30 s without a change, the worker repeats the unchanged value.
- The server keeps
EvalProgressvalues the same way for 60 s. They appear only during the fetch and evaluation steps. - The server sends
EvalProgressasevaluation.activityevents to the evaluation and task live endpoints.
Credentials¶
- Git credentials for a job consist of the project SSH key, saved SSH host keys, and saved login credentials for HTTPS Git.
- These credentials appear only inside the
AssignJobmessage, never in a separate message. - Workers with
secretsget Git credentials only for a flake job with a fetch step or for an exec job. - Jobs for pull requests from forks without maintainer approval receive none of these.
- Workers hold the key in locked memory and zero it on drop.
- At job completion, workers clear the key.
Memory¶
- Uploads of
Put(NAR up to 256 MiB) or signed downloads load the whole compressed NAR into memory at once. - Passthrough and multipart uploads from a store path pass data through a packer in chunks, so the whole NAR never has to fit in memory.