deploy: Move the comparison script into its own file

A file of its own reads as a script, says what its output looks like
and is checked by a new `shellcheck` lint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jackos1998andClaude Opus 5.5 committed 2026-11-24 23:38:08 +00:00
1 parent c79bebd20a
commit e622fe7708
5 files changed
+59 -30

No files matched your search

+3 -3
View File
@@ -40,9 +40,9 @@ of devenv's scripts, `devenv test` or the demo's host side.
- `cargo fmt` — the crate is formatted with `rustfmt` (`rustfmt.toml`); run it on code you change.
- `nix build` — the package, which also runs the tests.
- CI ([`.gitea/workflows/ci.yaml`](.gitea/workflows/ci.yaml)) runs `nix flake check` on every push:
the package with its tests, `clippy` (warnings as errors), `fmt` (`cargo fmt --check`) and the VM
test. Keep them passing. `nix flake check --no-build` fails where the VM test's keys haven't been
built, because the test reads them at evaluation.
the package with its tests, `clippy` (warnings as errors), `fmt` (`cargo fmt --check`),
`shellcheck` on `src/**/*.sh` and the VM test. Keep them passing. `nix flake check --no-build`
fails where the VM test's keys haven't been built, because the test reads them at evaluation.
- `vm-test` (or `nix build -L .#checks.x86_64-linux.vm`) — the NixOS VM test of the broker module
(needs KVM).
- The [demo](docs/demo.md): `devenv up -d` starts the host side (the broker from this checkout, its
+3 -2
View File
@@ -133,7 +133,7 @@ What each request runs, and whose code, decides whether it needs an approval fir
| `src/ops/mod.rs` | `plan` (request → `Parsed`: scope, approval detail), `execute`, quoting |
| `src/targets.rs` | SSH targets: the main branch's deploy-rs nodes from the builder, looked up again when stale or when a request names an unknown node |
| `src/detail.rs` | What approvers see of a request (`Detail`: fields, tables, lists, text) and its text rendering |
| `src/ops/ssh.rs`, `src/ops/query.rs`, `src/ops/deploy.rs`, `src/ops/build.rs` | Operations; `deploy.rs` also has the `INSPECT` comparison script and its parser |
| `src/ops/ssh.rs`, `src/ops/query.rs`, `src/ops/deploy.rs`, `src/ops/build.rs` | Operations; `deploy.rs` also parses the comparison script, `src/ops/inspect.sh` |
| `src/ops/secret.rs`, `src/ops/secret/format.rs` | Age secrets: what approvers see, encryption, generated values; env and JSON fields |
| `src/builder.rs` | Both sides of the builder: the worker (forced command) and the broker's client; also reads secrets and deploy nodes on the main branch |
| `src/approve.rs` | Approver connections (many requests each), `slop-approve` client, `approve()` used by every approver |
@@ -266,7 +266,8 @@ sequenceDiagram
4. **Build:** the builder evaluates and builds the targets' profiles
(`BuilderRequest::Build`); its log goes to the requester.
5. **Copy and compare**, on every node at once: `nix copy` the closures (substituting on the
node), then compare them with what the node runs, read-only (the `INSPECT` script).
node), then compare them with what the node runs, read-only
([`inspect.sh`](../src/ops/inspect.sh)).
6. **Detail:** the commits, then the package, unit and file changes per profile. Audited as
`prepared`.
3. **Run.** `ops::deploy::execute` activates every node at once, its profiles in order, as root
+15 -1
View File
@@ -1,4 +1,5 @@
# Checks that the crate is free of clippy warnings and formatted with rustfmt, as CI requires
# Checks that the crate is free of clippy warnings and formatted with rustfmt, and its shell scripts
# pass shellcheck, as CI requires
{ pkgs, slop-broker }:
let
inherit (pkgs.lib.fileset) toSource unions;
@@ -16,6 +17,19 @@ in
'';
});
shellcheck = pkgs.runCommand "slop-broker-shellcheck"
{
nativeBuildInputs = [ pkgs.shellcheck ];
src = toSource {
root = ../.;
fileset = pkgs.lib.fileset.fileFilter (file: file.hasExt "sh") ../src;
};
} ''
cd $src
shellcheck $(find . -name '*.sh')
touch $out
'';
fmt = pkgs.runCommand "slop-broker-fmt"
{
nativeBuildInputs = with pkgs; [ cargo rustfmt ];
+2 -24
View File
@@ -228,30 +228,8 @@ pub(super) fn nix_ssh_options(mut options: Vec<String>, extra: &[String]) -> Vec
}
/// Compares a profile's current and new closures on the node; reads only.
const INSPECT: &str = r#"old=$1 new=$2
if [ -e "$old" ]; then
echo @@packages
nix --extra-experimental-features nix-command store diff-closures "$old" "$new" 2>&1 | head -n 500
echo @@boot
for f in kernel initrd; do
[ -e "$old/$f" ] && [ -e "$new/$f" ] && [ "$(readlink -f "$old/$f")" != "$(readlink -f "$new/$f")" ] && echo "$f"
done
fi
# /etc entries are links into the store, so a link's target changes with its contents. Units are
# one link to a directory of them, so that one is followed.
list() {
[ -d "$1/etc" ] && cd "$1/etc" || return 0
find . -path ./systemd/system -prune -o -type l -printf "%p\t%l\n" -o -type f -printf "%p\t%s\n"
[ -d systemd/system ] || return 0
units=$(find -L systemd/system/ -mindepth 1 -maxdepth 2 -type f | LC_ALL=C sort)
[ -n "$units" ] || return 0
paste <(printf "%s\n" "$units" | sed "s|^|./|") <(printf "%s\n" "$units" | xargs -d "\n" realpath --)
}
echo @@old
[ -e "$old" ] && (list "$old")
echo @@new
(list "$new")
"#;
/// Compares a profile on a node with the new one; see the script for its output.
const INSPECT: &str = include_str!("inspect.sh");
async fn inspect(
ssh: &SshConfig,
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Compares the profile installed on a node with a new one, before approval: read-only, as the SSH
# user. The arguments are the profile path and the new closure. The output comes in sections, each
# started by an `@@<name>` line, which `Changes::parse` in `deploy.rs` reads:
#
# - `@@packages`: `nix store diff-closures` (only if the profile exists)
# - `@@boot`: `kernel` and `initrd`, where they change (only if the profile exists)
# - `@@old`, `@@new`: the `/etc` entries of each, as `<path><TAB><link target or size>`
old=$1 new=$2
if [ -e "$old" ]; then
echo @@packages
nix --extra-experimental-features nix-command store diff-closures "$old" "$new" 2>&1 | head -n 500
echo @@boot
for f in kernel initrd; do
[ -e "$old/$f" ] && [ -e "$new/$f" ] && [ "$(readlink -f "$old/$f")" != "$(readlink -f "$new/$f")" ] && echo "$f"
done
fi
# /etc entries are links into the store, so a link's target changes with its contents. Units are
# one link to a directory of them, so that one is followed.
list() {
[ -d "$1/etc" ] && cd "$1/etc" || return 0
find . -path ./systemd/system -prune -o -type l -printf "%p\t%l\n" -o -type f -printf "%p\t%s\n"
[ -d systemd/system ] || return 0
units=$(find -L systemd/system/ -mindepth 1 -maxdepth 2 -type f | LC_ALL=C sort)
[ -n "$units" ] || return 0
paste <(printf "%s\n" "$units" | sed "s|^|./|") <(printf "%s\n" "$units" | xargs -d "\n" realpath --)
}
echo @@old
[ -e "$old" ] && (list "$old")
echo @@new
(list "$new")