diff --git a/devenv.nix b/devenv.nix index bd4389b..a1ff3a7 100644 --- a/devenv.nix +++ b/devenv.nix @@ -32,17 +32,39 @@ let ]; }; - # The broker's `ssh`: the host `builder` runs the builder from this checkout's build directly, as - # its forced command would; everything else is the real `ssh`. - ssh = pkgs.writeShellScript "slop-demo-ssh" '' - host="" previous="" + # The broker's `ssh`, also `ssh` on the `PATH` of its `nix` (which takes it from the same + # directory): the host `builder` runs the builder from this checkout's build directly, as its + # forced command would, with the remote command in `SSH_ORIGINAL_COMMAND`. Everything else is + # the real `ssh`. + # + # - The broker passes the host after `--`, then the command. + # - Nix passes `builder@builder` and the command after `--`, first checks for a control master, + # and waits for the `LocalCommand` it asks for. + ssh = pkgs.writeShellScriptBin "ssh" '' + builder="" master=0 remote=() after=0 started=0 for arg; do - if [ "$previous" = -- ]; then host=$arg; break; fi - previous=$arg + if [ "$after" = 1 ]; then + remote+=("$arg") + elif [ "$arg" = -- ]; then + after=1 + elif [ "$arg" = builder@builder ]; then + builder=nix + elif [ "$arg" = "-oLocalCommand=echo started" ]; then + started=1 + elif [ "$arg" = -O ]; then + master=1 + fi done + if [ "''${#remote[@]}" -gt 0 ] && [ "''${remote[0]}" = builder ] && [ -z "$builder" ]; then + builder=broker + remote=("''${remote[@]:1}") + fi - if [ "$host" = builder ]; then - exec ${config.devenv.root}/target/debug/slop-broker builder --config ${builderConfig} + if [ -n "$builder" ]; then + # The builder has no control master + [ "$master" = 1 ] && exit 255 + [ "$started" = 1 ] && echo started + SSH_ORIGINAL_COMMAND="''${remote[*]}" exec ${config.devenv.root}/target/debug/slop-broker builder --config ${builderConfig} fi exec ${pkgs.openssh}/bin/ssh "$@" ''; @@ -95,7 +117,7 @@ let audit_log = "${state}/audit.jsonl"; ssh = { - ssh = "${ssh}"; + ssh = "${ssh}/bin/ssh"; key = "${state}/broker-key"; known_hosts = "${state}/known_hosts"; }; diff --git a/docs/demo.md b/docs/demo.md index a35935e..82a0092 100644 --- a/docs/demo.md +++ b/docs/demo.md @@ -121,6 +121,9 @@ slop ssh web -- uptime