Workers¶
A worker is a machine with gradient-worker installed. Workers connect to the server, take jobs from the queues of projects with the worker feature enabled, and return the results to the server. The server holds no Nix. A worker handles every clone, evaluation and build.
flowchart LR
fetch[Fetch] --> eval[Evaluate] --> build[Build]
Capabilities¶
Workers declare their capabilities at the handshake. Capabilities cover the jobs and the access of a worker.
| Capability | Default | Meaning |
|---|---|---|
network |
on | Internet access. Needed to clone the repository, download missing inputs, substitute from upstream caches and run fixed-output builds |
secrets |
on | The server can send the project SSH key and exec job secrets. Needed for an SSH repository URL and for exec secrets from the server |
exec |
off | Start exec jobs on the worker |
eval |
on | Walk the flake and report derivations |
build |
on | Build derivations and upload the outputs |
- A worker with
networkcan perform the fetch step for public repositories. - A worker with
networkandbuildcan run fixed-output builds. - A worker with
networkalone can take substitutes and downloads. No Nix build is involved in either. - Workers without
secretsnever get an SSH key. - An evaluating worker never downloads an input itself. The server can hand each missing input to a worker with
network, plussecretsfor an SSH URL. The evaluation can then pull the input from the cache. - A project or team registration can withhold each capability through
enable_network,enable_secrets,enable_exec,enable_evalandenable_build.
A single machine can hold every capability. A machine with a lot of memory can evaluate while smaller machines build.
Matching Builds¶
Builds only go to workers supporting the derivation's system (e.g. aarch64-linux) and every required system feature (e.g. kvm, big-parallel). Systems come from worker.system.architectures, with the host platform as default. Workers read features from their local Nix store. Experimental features such as recursive-nix add a system feature to that store once enabled. worker.system.features can override the detected features.
The scheduler will score each queued job among the matching workers. The scheduler will also keep heavy builds and evaluations away from workers lacking free memory for the predicted peak. Earlier builds are the source of this prediction. services.gradient.worker.build.metrics can record the per-build measurements behind this prediction.
Zones¶
Workers in a single datacenter can share a zone label, services.gradient.worker.zone. By default, workers carry no label. A cluster job that needs a fast interconnect places all of its members in one zone. Workers without a label together form one unnamed zone.
services.gradient.worker.endpoint specifies the address at which cluster peers can reach a worker. At cluster start, the server hands every member the endpoints of all other members.
Access¶
| Kind | Registered | Serving |
|---|---|---|
| Project worker | Under one project | That project |
| Team worker | Under one team | Every project granting the team's workers |
| Local worker | On the server host, automatically | Projects that grant team server the workers flag, or all new projects when grantLocalWorkerToNewProjects is true |
Workers receive jobs only from projects with a writable cache subscription. The Readiness card on the project page can list the workers that serve that project, the cache subscriptions, and the Git access. Each row can show the changes that its role can grant. Viewers see rows without buttons. The Git access row can show tasks that can't clone the repository on the task's Repository page. Git host connection and deploy keys are on this page.
The server can generate a worker ID for each worker registration through the UI or CLI. The NixOS configuration and the peers line appear in the registration result one time only. See Add a Remote Worker.
Team Workers¶
Each team can have workers. A team worker works with a single token for the entire team. Projects that granted the team get read-only access to these workers.
Manage team workers in the Workers section of the team page.
| Setting | Effect |
|---|---|
| Grant with workers | Team worker active in the project |
new_projects.workers |
Team workers granted to every new project |
enabled |
Global switch for the worker in every granted project |
A worker ID can point to a team worker or to a set of project registrations. Never to both at once.
Exec Secrets¶
Exec workers decrypt their own sops files. Exec jobs fetch the values by name. The server can't see them.
# configuration.nix
services.gradient.worker.exec.sops = {
files = [ { path = "/etc/gradient/worker-secrets.yaml"; projects = "all"; } ];
keyFile = "/etc/ssh/ssh_host_ed25519_key"; # (1)!
};
-
An SSH private key, Ed25519 or RSA. Ed25519 keys yield an age recipient through
ssh-to-age < /etc/ssh/ssh_host_ed25519_key.pub. -
Workers publish names and never values. Jobs that list such a name go only to the worker with that name.
- Set
projectson each sops file entry. Use the string"all"or a list of project UUIDs. Jobs from other projects get the same response as for a secret that doesn't exist. - Run
systemctl reload gradient-workerto decrypt the files again. Failed reloads keep the previous values. - The files need group read for
gradient-worker. They hold ciphertext only.
Worker Stop¶
A worker can stop at any time. That includes a worker with disposable VMs. Jobs survive the stop.
systemctl stopandsystemctl restarttake effect immediately. Drain notices leave the worker for the server. The server won't send new jobs.- Running jobs end at a worker stop. Those jobs go back into the server queue for other workers.
- exec jobs continue inside the guest under
exec.stopGuestsWithWorker = falseand resume after a restart of the worker. - An administrator can also drain one worker from Administration > Workers or
gradient administration worker drain <id>. The worker can keep the connection and receive jobs again after Undrain. - Use Drain All on the same page to drain all workers at once. Undrain All on that page can end all drains that an administrator started.
- A team admin can drain a worker from the team workers page or with
gradient team worker edit <TEAM> <WORKER_ID> --draining true. Use Deactivate instead to abort running jobs immediately.
Related¶
- Quick Start: run a worker locally
- Add a Remote Worker: hook up extra build machines
- Set Up Clusters: zones and endpoints for cluster jobs
- Evaluations and Builds: the work a worker performs