Build over SSH¶
Gradient exposes its cache as an ssh-ng:// store. nix copy moves store paths in and out. CI workers run builds started with nixos-rebuild --build-host.
Requirements:
- A project with a cache subscription and a worker, see First Project
- The
TriggerEvaluationpermission on the project, needed for copying paths in and building, see Members and Roles
1. Enable the SSH Server¶
- Port
2222by default, seesshfor the host key and listen address.
2. Add a Key¶
Paste an OpenSSH public key line into Settings -> SSH Keys -> Add SSH Key.
Generate a key and print the public part:
- Each key has a single owner.
- The SSH user name and the project name share one value. A key can open every project of its user.
3. Add the Client Module¶
The client module registers Gradient as a Nix remote builder over SSH. CI workers then take over builds for every system listed in the configuration.
# flake.nix
nixosConfigurations.laptop = nixpkgs.lib.nixosSystem {
modules = [
./configuration.nix
gradient.nixosModules.client
];
};
# configuration.nix
nix.gradient-ssh = {
enable = true;
host = "ci.example.com";
project = "myproject"; # (1)!
identityFile = "/root/.ssh/gradient"; # (2)!
systems = [ "x86_64-linux" "aarch64-linux" ];
supportedFeatures = [ "big-parallel" "kvm" "nixos-test" ];
};
- The SSH user name matches the project name. Store URLs work without the
myproject@prefix. - The Nix daemon must be able to read the key as
root. Plainnix copyandnixos-rebuilduse the calling user's access to the key instead.
4. Use the Store¶
| Use | Command |
|---|---|
| Substituter | substituters = ssh-ng://myproject@ci.example.com plus the cache's public key |
| Copy out | nix copy --from ssh-ng://myproject@ci.example.com /nix/store/...-hello |
| Copy in | nix copy --to ssh-ng://myproject@ci.example.com ./result |
| Build host | nixos-rebuild switch --build-host ssh-ng://myproject@ci.example.com |
| Remote store | nix build --eval-store auto --store ssh-ng://myproject@ci.example.com .#hello |
| Build log | ssh -p 2222 myproject@ci.example.com nix log /nix/store/...-hello.drv |
- Read requests can be answered from the caches the project subscribed to.
- Copied paths enter the project cache in the same way as build outputs. Only caches with signing enabled in the subscription add signatures to those paths.
- All build requests from a user share one evaluation in the project's Build Requests task, even across several SSH connections.
- Each new request adds its entry points to the evaluation already running for that user.
- Once the evaluation has finished, further requests start a new one.
- Builds continue after a disconnect. Evaluations finish together with their last build.
- The Nix output lists missing systems as long as no connected worker can build them.
- Aborting an evaluation fails every unfinished build with an error, e.g. after 5 minutes without a matching worker.
- Build logs flow back the same way local logs do. Package names lead every log line from
nix build -L. - Stored logs for a derivation or for a derivation output come from
nix log,nix-store --read-logandnix-store -l. Upstream caches provide fallback.
Verify Deployment¶
Expected output: the store URL and Trusted: 0. Build requests appear in the UI under Build Requests.
Limits¶
ssh://has no support in Gradient. Use--build-hostwith thessh-ng://prefix instead.- The Nix client can't run
nix log --store ssh-ng://. Use an SSH command to runnix loginstead. - Content-addressed derivations and dynamic derivations don't work over SSH.
- Pass
--eval-store autotonix build --store. Gradient rejects evaluation writes.
Next Steps¶
- Share a Cache: substituter URL and public key
- Build Before Pushing: building uncommitted changes with
gradient build - Every
sshoption: Configuration - Terminal sessions inside exec jobs: Open a Terminal