Point a host at the box
The consumer module sets a host’s substituters to the box first and the remote cache second, with a low connect timeout. On the LAN the box answers; off it, the connection to the box times out and Nix falls back to the remote cache, with no change to the configuration.
Prerequisites
Section titled “Prerequisites”- A NixOS host configured from a flake.
- A running box with a stable address (see Deploy a box).
- The public key(s) your remote cache’s paths are signed with.
1. Add the flake input
Section titled “1. Add the flake input”{ inputs.kasha.url = "github:Zebradil/kasha";}2. Import the module into one host
Section titled “2. Import the module into one host”Import kasha.nixosModules.consumer in the modules of the host that should use the box, not in a module every host
shares: the box endpoint only makes sense for machines on its network.
nixosConfigurations.workstation = nixpkgs.lib.nixosSystem { modules = [ kasha.nixosModules.consumer ./hosts/workstation.nix ];};3. Configure it
Section titled “3. Configure it”In that host’s configuration:
{ services.kasha-consumer = { enable = true; boxEndpoint = "http://box.lan:5000"; remoteCache = "https://znix.zebradil.dev"; connectTimeout = 2; trustedPublicKeys = [ "znix.zebradil.dev:AAAA..." ]; };}| Option | Default | Meaning |
|---|---|---|
enable |
false |
turn the selection on |
boxEndpoint |
none, required | the box’s LAN HTTP endpoint, queried first |
remoteCache |
https://znix.zebradil.dev |
the off-LAN fallback |
connectTimeout |
2 |
seconds Nix waits to connect to each substituter; bounds the off-LAN delay |
trustedPublicKeys |
[ ] |
keys accepted on substituted paths |
The module then sets:
nix.settings.substitutersto exactly[ boxEndpoint remoteCache ], withmkForce, so no other substituter (including the defaulthttps://cache.nixos.org) is queried ahead of the box. Add further substituters withextra-substitutersif the host needs them.nix.settings.connect-timeouttoconnectTimeout.nix.settings.trusted-public-keystotrustedPublicKeys, appended to Nix’s defaultcache.nixos.org-1key.
An empty trustedPublicKeys fails evaluation with
services.kasha-consumer.trustedPublicKeys must list the remote-cache public key(s): without the key, paths
substituted from the remote cache would fail signature verification.
4. Rebuild
Section titled “4. Rebuild”sudo nixos-rebuild switch --flake .#workstationThe box answers 404 for paths it does not hold, so Nix moves on to the remote cache for those. A box with
pull-through on fetches such a path from its own sources
instead. See Substituter selection for why the fallback is a timeout rather than
discovery.