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

112 lines
4.6 KiB
Nix

# The demo's agents' VM: an `agent` user with `slop`, which reaches the broker on the host over
# vsock, like a real agents' VM, and a clone of the demo repository, which it reaches through a
# QEMU forward to `git daemon` on the host. `devenv up` runs the broker; `demo` boots this VM on the
# terminal and sets up the forward.
{ pkgs, slop-broker }:
let
inherit (pkgs) lib;
settings = import ./settings.nix;
# Only the guest sees this address; the `demo` script forwards it to the host
repository = "git://10.0.2.100/repo.git";
help = pkgs.writeShellScriptBin "demo-help" ''
cat <<'EOF'
slop-broker demo. You're `agent` on the agents' VM; the broker runs on the host, and the
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
slop ssh web -- uptime asks an approver; leases of 5m or 1h are offered
slop ssh router -- uptime asks too, and approving needs a passkey in the web app
slop ssh vault -- true denied by policy
slop requests your pending requests and leases
slop guide the guide agents get
Secrets, in ~/repo (a clone of the demo repository; master only moves with `demo-merge` on
the host):
slop secret keys secrets/app.env.age runs without asking
echo hunter2 | slop secret set secrets/app.env.age DB_PASSWORD
slop secret generate secrets/wg.key.age --kind wireguard
cp secrets/app.env.age secrets/notes.age
slop secret read secrets/notes.age the approval says it's secrets/app.env.age
git switch -c secrets && git commit -am "Rotate secrets" && git push origin secrets
Deploys, of the profile `demo` in flake.nix to the box VM (`demo-box cat /run/demo/version`
on the host shows what's active):
sed -i 's/version = "1.0"/version = "1.1"/' flake.nix
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).
A request blocks until it's answered. To keep this shell, run it in the background with stdin
closed (`slop ssh` forwards stdin): `slop ssh web -- uptime </dev/null &`. `poweroff` (or
Ctrl-A X) stops the VM; nothing in it is kept.
EOF
'';
in
(pkgs.nixos ({ modulesPath, ... }: {
imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ];
system.stateVersion = lib.trivial.release;
networking.hostName = "slop-demo-agent";
virtualisation = {
graphics = false;
diskImage = null;
memorySize = 1024;
# Only vsock reaches the host
restrictNetwork = true;
qemu.options = [ "-device vhost-vsock-pci,guest-cid=${toString settings.agentCid}" ];
};
# `agent`, signed in on the serial console, the only one `demo` shows. A second autologin on
# `tty1` would also run the login script below, and its clone would race this one's.
users.users.agent.isNormalUser = true;
services.getty.autologinUser = "agent";
systemd.services."autovt@tty1".enable = false;
# So `poweroff` works from the serial console
security.polkit = {
enable = true;
extraConfig = ''
polkit.addRule(function(action, subject) {
if (action.id.indexOf("org.freedesktop.login1.power-off") == 0 && subject.user == "agent") {
return polkit.Result.YES;
}
});
'';
};
# `slop`, and Git and Nix for working in the repository. `slop secret` evaluates `secrets.nix`.
environment.systemPackages = [ slop-broker help pkgs.git ];
nix.settings.experimental-features = [ "nix-command" "flakes" ];
environment.etc.gitconfig.text = ''
[user]
name = agent
email = agent@example.org
'';
# At login: the clone, once, then the help
programs.bash.loginShellInit = ''
if [ "$USER" = agent ]; then
if [ ! -d ~/repo ] && ! git clone -q ${repository} ~/repo; then
echo "Cloning ${repository} failed; start the VM with \`demo\` on the host, which forwards it." >&2
fi
cd ~/repo 2>/dev/null || true
demo-help
fi
'';
})).vm