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>
This commit is contained in:
jackos1998andClaude Opus 5.5 committed 2026-11-29 13:27:48 +00:00
1 parent 3f024cd115
commit 76eb39fb7e
5 files changed
+80 -11

No files matched your search

+24 -3
View File
@@ -40,6 +40,7 @@ flowchart TB
subgraph boxvm["Box VM"]
sshd["sshd, as box<br>(nodes web, router, vault, box)"]
cache["sshd, as cache<br>(the binary cache's store)"]
end
slop -- "vsock" --> broker
@@ -50,6 +51,7 @@ flowchart TB
shell -- "moves master" --> repo
broker -- "SSH, through a wrapper" --> builder -- "fetches" --> repo
broker -- "SSH, localhost:2222" --> sshd
broker -- "SSH, localhost:2222" --> cache
```
| Part | Where | Runs |
@@ -57,7 +59,7 @@ flowchart TB
| Broker, from this checkout (`cargo run`) | Host | `devenv up` (process `slop-broker`) |
| Web app | <http://localhost:8095> | Part of the broker |
| [Pocket ID](https://pocket-id.org), for approvers to sign in | <http://localhost:1411> | `devenv up` (process `pocket-id`) |
| Box VM ([`box.nix`](../nix/demo/box.nix)): `sshd` for the targets, and the deploy target | `localhost:2222`, as `box` | `devenv up` (process `box`) |
| Box VM ([`box.nix`](../nix/demo/box.nix)): `sshd` for the targets, the deploy target and the binary cache | `localhost:2222`, as `box`, and as `cache` for the cache | `devenv up` (process `box`) |
| Agents' VM ([`agent.nix`](../nix/demo/agent.nix)), signed in as `agent` | Your terminal | `demo` |
| The repository, seeded from [`repo/`](../nix/demo/repo) | `.devenv/state/slop-demo/git/repo.git` | `git daemon`, one per connection from the agents' VM |
| The builder (`slop-broker builder`, from this checkout) | Host | The broker, through its `ssh` |
@@ -81,8 +83,8 @@ CID are in [`settings.nix`](../nix/demo/settings.nix). The broker's configuratio
- `slop ssh vault` is denied.
- `slop secret keys` runs without asking; the other secret requests ask, with a 5-minute
lease, except reading, which asks every time.
- Using the builder asks, with leases, except for commits already on `master`; deploys ask.
There's no binary cache, so `slop build` says it isn't configured.
- Using the builder asks, with leases, except for commits already on `master`; deploys and
builds into the binary cache ask, with a 5-minute lease.
## Approving
@@ -167,6 +169,25 @@ profile). `demo-box cat /run/demo/version` on the host shows what's active.
The box VM lets `box` use `sudo` without a password and copy unsigned paths into its store, which
lives in memory, like everything else in the VMs.
### The binary cache
The box VM holds the binary cache's store, at `/var/lib/slop-cache`, owned by its `cache`
account, as [`services.slop-broker-cache`](../nix/modules/nixos/cache.nix) sets it up: the
broker's key may only run `nix-daemon --stdio` on that store and add GC roots. Nothing serves it
to other boxes; it's for seeing what `slop build` pushes. In `~/repo` on the agents' VM:
```sh
slop build packages.x86_64-linux.default </dev/null &
```
As with a deploy, the builder's use is approved first (or covered by a lease), then the build
request shows the outputs and their closure sizes, and once approved the broker pushes them and
prints their paths. To see them on the host:
```sh
demo-box ls /var/lib/slop-cache/nix/var/nix/gcroots/slop-broker
```
## The box VM
`demo-box` in the devenv shell logs in to the box VM as `box`, with the broker's key, to see what
+7 -1
View File
@@ -13,7 +13,7 @@ let
cat <<'EOF'
slop-broker demo. You're `agent` on the agents' VM; the broker runs on the host, and the
targets `web`, `router` and `vault` are all the box VM.
targets `web`, `router`, `vault` and `box` are all the box VM.
slop status web sshd.service runs without asking (policy: auto)
slop logs web sshd.service -n 20
@@ -40,6 +40,12 @@ let
git switch -c bump && git commit -am "Bump the app" && git push origin bump
slop deploy box </dev/null & asks to use the builder, builds, then asks again
Builds into the binary cache, which is on the box VM (its GC roots, under
/var/lib/slop-cache/nix/var/nix/gcroots/slop-broker, show what's been pushed):
slop build packages.x86_64-linux.default </dev/null &
asks to use the builder, builds, then asks to push
Approve on the host: `slop-approve` in the devenv shell, or the web app at
http://localhost:${toString settings.ports.web} (`demo-sign-in` prints a sign-in link).
+31 -6
View File
@@ -1,6 +1,8 @@
# The box the demo's SSH targets reach, over `sshd` on a port forwarded to the host's loopback,
# with a `box` account for the broker's key, which may use `sudo` and copy store paths, so the
# broker can deploy to it.
# 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.
@@ -10,9 +12,11 @@ let
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" ];
imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ../modules/nixos/cache.nix ];
system.stateVersion = lib.trivial.release;
networking.hostName = "slop-demo-box";
@@ -20,7 +24,7 @@ in
virtualisation = {
graphics = false;
diskImage = null;
# Copied closures live in memory
# Copied closures live in memory, the cache's too
memorySize = 1024;
restrictNetwork = true;
forwardPorts = [{
@@ -42,6 +46,21 @@ in
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"; }];
@@ -57,10 +76,16 @@ in
script = ''
install -m 600 /tmp/shared/host-key ${hostKey}
# The broker logs in as `box` with its key
# 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
+11
View File
@@ -105,6 +105,10 @@ let
action = "ask";
leases = [ "5m" ];
};
build = {
action = "ask";
leases = [ "5m" ];
};
# Approvals show whether the file and its recipients match `master`; reading always asks
secret = {
@@ -130,6 +134,13 @@ let
nix = "${pkgs.nix}/bin/nix";
cache = "${state}/nix-cache";
};
# The box VM's `cache` account, which holds the binary cache's store
cache = {
hostname = "localhost";
user = "cache";
ssh_opts = [ "-p" (toString settings.ports.boxSsh) ];
key = "${state}/broker-key";
};
secrets = {
identity = "${state}/broker-age.key";
+7 -1
View File
@@ -51,6 +51,12 @@ in
home = mkOpt' str null "`HOME` for the store's commands; a directory `user` can write to.";
keepDays = mkOpt' ints.positive 14 "Days a pushed path stays rooted after its last push.";
brokerKeys = mkOpt' (listOf str) [ ] "SSH public keys of brokers that may push.";
forcedCommand = lib.mkOption {
type = path;
default = forcedCommand;
readOnly = true;
description = "The forced command for brokers' keys, for keys `brokerKeys` can't list, such as ones made at boot.";
};
};
config = mkIf cfg.enable {
@@ -62,7 +68,7 @@ in
];
users.users.${cfg.user}.openssh.authorizedKeys.keys =
map (k: ''restrict,command="${forcedCommand}" ${k}'') cfg.brokerKeys;
map (k: ''restrict,command="${cfg.forcedCommand}" ${k}'') cfg.brokerKeys;
# Expired roots go daily; the store's own garbage collection then takes their paths
systemd = {