demo: Build the app from slower, bigger parts

The demo's app built and copied in moments, which left nothing for the
progress in `slop` and the web app to show. It now has twelve parts in
three layers, each layer built once the one below it is, so a build
takes about a minute and a half; each part adds a few MiB to copy, and
the box VM has room for them. `demo-help` shows `--logs` too.

The parts follow from the version alone, so a version built before is
already in the builder's store and only evaluates, and a new one
rebuilds them all. `demo-bump` in the agents' VM sets a new version
and pushes it on a branch of its own, and a check runs it against a
bare copy of the repository, including from a fresh clone, as after
the VM restarts.

Refs #21

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jackos1998andClaude Opus 5.5 committed 2026-11-30 00:06:53 +00:00
1 parent 82bc5cb74e
commit ee6596d86c
8 files changed
+113 -13

No files matched your search

+16 -5
View File
@@ -151,13 +151,24 @@ rage -d -i .devenv/state/slop-demo/dev-age.key <(git -C .devenv/state/slop-demo/
### Deploys
The repository's `flake.nix` has a deploy-rs node, `box`, with one profile, `demo`, deployed as
root: a small app whose activation writes its version to `/run/demo/version`. Its `nixpkgs` is
locked to this repository's, so the builder has it already, and it uses nixpkgs' build of
deploy-rs, so a build takes moments. In `~/repo` on the agents' VM:
root: an app whose activation writes its version to `/run/demo/version`.
- **Its `nixpkgs`** is locked to this repository's, so the builder has it already, and it uses
nixpkgs' build of deploy-rs, so nothing big needs building.
- **Its parts** stand in for a bigger build, so the progress in `slop` and the web app has
something to show. There are `layers` of `width` parts, and each layer builds once the one
below it has, so a build takes about a minute and a half. Each part takes 15 to 30 seconds and
adds a few MiB to copy.
- **Their contents** follow from `version` alone, and the builder keeps what it built in the
host's store. So a version that's been built before only evaluates, and copies what the box VM
doesn't have. A version that hasn't been built yet rebuilds every part, so `demo-bump` (in
[`bump.nix`](../nix/demo/bump.nix)) sets a new one each time, from the time unless you give
one, and pushes it on a branch of its own.
In `~/repo` on the agents' VM:
```sh
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
demo-bump
slop deploy box </dev/null &
```
+1
View File
@@ -51,6 +51,7 @@
checks = forSystems (pkgs: {
package = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
vm = pkgs.callPackage ./nix/vm-test.nix { slop-broker = self.packages.${pkgs.stdenv.hostPlatform.system}.default; };
demo-bump = import ./nix/demo/bump-test.nix { inherit pkgs; };
} // import ./nix/lints.nix { inherit pkgs; slop-broker = self.packages.${pkgs.stdenv.hostPlatform.system}.default; });
# A plain alternative to the devenv shell, for `nix develop`: the toolchain and the build's
+6 -4
View File
@@ -8,6 +8,7 @@ let
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";
bump = import ./bump.nix { inherit pkgs; };
help = pkgs.writeShellScriptBin "demo-help" ''
cat <<'EOF'
@@ -34,11 +35,12 @@ let
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):
on the host shows what's active). Only a version that hasn't been built before rebuilds the
app's parts, so `demo-bump` sets a new one each time and pushes it on a branch of its own:
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
demo-bump or `demo-bump 1.1` for a version of your own
slop deploy box </dev/null & asks to use the builder, builds, then asks again
slop deploy box --logs </dev/null & the same, with the build's log as well as its progress
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):
@@ -90,7 +92,7 @@ in
};
# `slop`, and Git and Nix for working in the repository. `slop secret` evaluates `secrets.nix`.
environment.systemPackages = [ slop-broker help pkgs.git ];
environment.systemPackages = [ slop-broker help bump pkgs.git ];
nix.settings.experimental-features = [ "nix-command" "flakes" ];
environment.etc.gitconfig.text = ''
[user]
+1 -1
View File
@@ -25,7 +25,7 @@ in
graphics = false;
diskImage = null;
# Copied closures live in memory, the cache's too
memorySize = 1024;
memorySize = 2048;
restrictNetwork = true;
forwardPorts = [{
from = "host";
+32
View File
@@ -0,0 +1,32 @@
# Checks `demo-bump` against a bare copy of the demo repository: twice in one clone, then again in a
# fresh clone, as after the agents' VM restarts, when earlier branches are already on the remote.
{ pkgs }:
let
bump = import ./bump.nix { inherit pkgs; };
in
pkgs.runCommand "slop-broker-demo-bump" { nativeBuildInputs = [ bump pkgs.git ]; } ''
export HOME=$TMPDIR
git config --global user.name Agent
git config --global user.email agent@example.org
git config --global init.defaultBranch master
git init --quiet --bare origin.git
git clone --quiet origin.git seed
cp ${./repo/flake.nix} seed/flake.nix
git -C seed add flake.nix
git -C seed commit --quiet -m "Start the demo repository"
git -C seed push --quiet origin master
git clone --quiet origin.git one
(cd one && demo-bump 1.1 && demo-bump 1.2)
git clone --quiet origin.git two
(cd two && demo-bump)
# Each version on its own branch, and only the version changed
for version in 1.1 1.2; do
git -C origin.git show "bump-$version:flake.nix" | grep -q "version = \"$version\";"
done
test "$(git -C origin.git branch --list 'bump-*' | wc -l)" = 3
git -C origin.git diff --stat master bump-1.1 | grep -q "1 file changed, 1 insertion(+), 1 deletion(-)"
touch $out
''
+20
View File
@@ -0,0 +1,20 @@
# `demo-bump` on the agents' VM: sets a new version of the demo app in the repository it's run in,
# commits it on a branch of its own and pushes that, ready for `slop deploy box`. Only a version
# that hasn't been built before rebuilds the app's parts, so it defaults to one from the time.
{ pkgs }:
pkgs.writeShellApplication {
name = "demo-bump";
runtimeInputs = with pkgs; [ coreutils git gnugrep gnused ];
text = ''
version=''${1:-1.$(date +%s)}
branch=bump-$version
sed -i "s/version = \".*\";/version = \"$version\";/" flake.nix
grep -q "version = \"$version\";" flake.nix
git switch --quiet -c "$branch"
git commit --quiet -am "Bump the app to $version"
git push --quiet origin "$branch"
echo "Pushed $branch, with the app at $version; deploy it with \`slop deploy box\`."
'';
}
+4 -2
View File
@@ -8,8 +8,10 @@ only `demo-merge <branch>` on the host moves it, standing in for a person mergin
- `secrets/app.env.age` holds `DB_USER` and `DB_PASSWORD`; `secrets/wg.key.age` is a WireGuard
private key, as a whole file.
`flake.nix` has a deploy-rs node, `box`, with one profile, `demo`: a small app whose activation
writes its version to `/run/demo/version`.
`flake.nix` has a deploy-rs node, `box`, with one profile, `demo`: an app whose activation writes
its version to `/run/demo/version`. Its parts take a while to build and add a few MiB each, so
builds and copies show their progress. They follow from the version, so only a version that
hasn't been built before rebuilds them.
Change secrets with `slop secret` (`slop guide` explains it), commit, and push a branch. Deploy a
pushed commit with `slop deploy box`.
+33 -1
View File
@@ -13,13 +13,45 @@
# Change this, push a branch and `slop deploy box`: the approval shows the version change
version = "1.0";
# Stand-ins for a bigger build, so its progress and the copy's have something to show:
# `layers` of `width` parts, each layer built once the one before it is, like a chain of
# dependencies. Each part takes 15 to 30 seconds and adds a few MiB to copy. Their contents
# follow from the version alone, so a version that's been built before is already in the
# builder's store, and only a new one rebuilds them all.
layers = 3;
width = 4;
partCount = layers * width;
# Layer `n`, whose parts each depend on all of the layer below
layer = n: below: builtins.genList
(i:
let
index = n * width + i;
name = "demo-part-${toString index}-${version}";
size = 2 + pkgs.lib.mod index 6;
in
pkgs.runCommand name { inherit below; } ''
for step in 1 2 3 4 5 6; do
echo "part ${toString index}: step $step"
sleep ${toString (3 + pkgs.lib.mod index 3)}
done
head -c ${toString size}M < <(yes "demo app ${version}, part ${toString index}") > $out
'')
width;
layered = builtins.foldl'
(built: n: let next = layer n built.last; in { all = built.all ++ next; last = next; })
{ all = [ ]; last = [ ]; }
(builtins.genList (n: n) layers);
parts = layered.all;
app = pkgs.writeTextFile {
name = "demo-app-${version}";
destination = "/bin/demo-app";
executable = true;
text = ''
#!${pkgs.runtimeShell}
echo "demo app ${version}"
# Its parts: ${toString parts}
echo "demo app ${version}, in ${toString partCount} parts"
'';
};