Files
jackos1998andClaude Opus 5.5 76eb39fb7e demo: Add a binary cache for slop build
The box VM holds the cache's store in a `cache` account, set up by
`services.slop-broker-cache`, and the demo's broker pushes to it, so
`slop build` can be tried by hand. The broker's key is only known at
boot, so the module exposes its forced command for keys it can't list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 13:27:48 +00:00

92 lines
3.2 KiB
Nix

# The box the demo's SSH targets reach, over `sshd` on a port forwarded to the host's loopback:
#
# - `box`, for the broker's key, which may use `sudo` and copy store paths, so the broker can
# deploy to it;
# - `cache`, holding the binary cache's store, which `slop build` pushes to.
#
# `devenv up` runs it with `SHARED_DIR` holding the broker's public key and the box's host key,
# which it keeps between runs so the broker's `known_hosts` stays valid.
{ pkgs }:
let
inherit (pkgs) lib;
settings = import ./settings.nix;
hostKey = "/etc/ssh/ssh_host_ed25519_key";
cacheStore = "/var/lib/slop-cache";
cacheHome = "/var/lib/slop-cache-home";
in
(pkgs.nixos ({ config, modulesPath, ... }: {
imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ../modules/nixos/cache.nix ];
system.stateVersion = lib.trivial.release;
networking.hostName = "slop-demo-box";
virtualisation = {
graphics = false;
diskImage = null;
# Copied closures live in memory, the cache's too
memorySize = 1024;
restrictNetwork = true;
forwardPorts = [{
from = "host";
host = { port = settings.ports.boxSsh; address = "127.0.0.1"; };
guest.port = 22;
}];
};
# Deploys: activation as root, and closures copied in unsigned (the store is the VM runner's
# writable overlay). Nothing is substituted, since the VM has no network.
users.users.box.isNormalUser = true;
security.sudo.extraRules = [{
users = [ "box" ];
commands = [{ command = "ALL"; options = [ "NOPASSWD" ]; }];
}];
nix.settings = {
trusted-users = [ "root" "box" ];
substituters = lib.mkForce [ ];
};
# The binary cache: a store of its own, owned by `cache`. Nothing serves it to other boxes; it's
# for seeing what `slop build` pushes. The broker's key is authorized at boot, below.
users.users.cache = {
isNormalUser = true;
home = cacheHome;
createHome = true;
};
systemd.tmpfiles.rules = [ "d ${cacheStore} 0755 cache users -" ];
services.slop-broker-cache = {
enable = true;
user = "cache";
store = cacheStore;
home = cacheHome;
};
services.openssh = {
enable = true;
hostKeys = [{ path = hostKey; type = "ed25519"; }];
};
# The keys from the shared directory, which is mounted at `/tmp/shared`, before `sshd` starts
systemd.services.slop-demo-keys = {
wantedBy = [ "multi-user.target" ];
before = [ "sshd.service" "sshd-keygen.service" ];
requiredBy = [ "sshd.service" ];
unitConfig.RequiresMountsFor = "/tmp/shared";
serviceConfig = { Type = "oneshot"; RemainAfterExit = true; };
script = ''
install -m 600 /tmp/shared/host-key ${hostKey}
# The broker logs in as `box` with its key, for anything
box=${config.users.users.box.home}/.ssh
install -d -m 700 -o box -g users $box
install -m 600 -o box -g users /tmp/shared/broker.pub $box/authorized_keys
# and as `cache`, only through the cache's forced command
cache=${cacheHome}/.ssh
install -d -m 700 -o cache -g users $cache
echo "restrict,command=\"${config.services.slop-broker-cache.forcedCommand}\" $(cat /tmp/shared/broker.pub)" |
install -m 600 -o cache -g users /dev/stdin $cache/authorized_keys
'';
};
})).vm