Add hermenix remote for driving setup/migrate over SSH

hermenix remote <host> <setup|migrate> [args...] SSHes to the target
host with a pty, clones this repo there only if it isn't already
checked out (never touches an existing checkout beyond running the
command), then runs `nix run .#hermenix -- ...` in it. Lets setup/
migrate be triggered from wherever hermenix is installed, without
manually SSHing into the target host first.

Verified with a sandboxed dry run (local ssh/git/nix stubs): fresh
clone, existing-checkout skip-clone, custom --dir/--repo, and the
no-args usage guard.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ariandClaude Sonnet 5 committed 2026-09-15 13:59:30 -04:00
1 parent 2b33b98bae
commit de2649f6e0
2 files changed
+64 -3

No files matched your search

+24
View File
@@ -183,6 +183,30 @@ the machine. Neither needs anything from you.
---
## Running it on a remote host
`setup` and `migrate` both act on whatever machine they run on — local
disks, local sudo, vsock into the local guest. There's no way around SSHing
into the target host first. `hermenix remote` does that SSH step for you:
```bash
hermenix remote fwdesk.lab.internal setup
hermenix remote fwdesk.lab.internal migrate /var/lib/hermes
```
It clones this repo to `~/hermenix` on the remote host **only if that
directory doesn't already exist there**, then `cd`s into it and runs
`nix run .#hermenix -- <the rest of the command>`. An existing checkout is
never touched beyond running the command — it won't overwrite a host's own
`guest/common.nix` (cache key, authorized keys) or anything else it's
accumulated. Override the checkout path or repo URL with `--dir`/`--repo` if
you need to.
It connects with `ssh -t`, which allocates a real pty — required for the
interactive prompts in `setup`/`migrate` to work at all over the connection.
---
## SSH into the guest
```bash
+40 -3
View File
@@ -2,14 +2,17 @@
#
# hermenix — host-side tooling for the Hermes Agent VM.
#
# Two subcommands:
# Three subcommands:
# hermenix setup guided host-side setup: disks, cache signing
# key, guest/common.nix, build + write the image
# hermenix migrate <source> carry an existing flat HERMES_HOME (e.g. from
# a prior Docker deployment) into a running
# guest, unchanged
# hermenix remote <host> ... run either of the above ON a remote host over
# SSH, instead of having to SSH in yourself first
#
# Neither runs `nixos-rebuild` — that stays yours to run, watching it happen.
# None of these run `nixos-rebuild` — that stays yours to run, watching it
# happen.
# ---------------------------------------------------------------- output ---
@@ -35,6 +38,11 @@ def confirm-word [word: string, prompt: string] {
(input $" ($prompt) ") == $word
}
# Single-quote a string for safe embedding in a remote shell command line.
def shquote [s: string] {
"'" + ($s | str replace --all "'" "'\\''") + "'"
}
# Run a command, sudo-prefixed unless already root (set once via
# $env.HERMENIX_NEED_SUDO at the top of `main setup`). Fails loudly, like any
# other external command, if the command fails.
@@ -56,8 +64,9 @@ def main [] {
print ""
print " hermenix setup guided host-side setup"
print " hermenix migrate <source> carry an existing flat HERMES_HOME into the guest"
print " hermenix remote <host> ... run setup/migrate on a remote host over SSH"
print ""
print "run `hermenix <subcommand> --help` for details on either."
print "run `hermenix <subcommand> --help` for details on any of these."
}
# ------------------------------------------------------------------ setup ---
@@ -451,3 +460,31 @@ def "main migrate" [
say "deployment retired. Decrypt secrets/hermes-env.age yourself and fold"
say $"anything relevant into ($dest)/.env \(hermes-ctl secrets edit\)."
}
# ----------------------------------------------------------------- remote ---
# Run `hermenix setup` or `hermenix migrate` on a remote host over SSH,
# instead of having to SSH in and run it locally yourself. `setup` and
# `migrate` both act on whatever machine they run on (local disks, local
# sudo, vsock into the local guest) - this just saves the manual SSH step.
#
# Clones `--repo` to `--dir` on the remote ONLY if `--dir` doesn't already
# exist there - an existing checkout is never touched beyond running the
# command, so a host's own guest/common.nix edits (cache key, authorized
# keys) or in-progress disk state are never at risk of being overwritten.
def "main remote" [
host: string # SSH target, e.g. fwdesk.lab.internal
...args: string # forwarded to the remote `hermenix` invocation
--dir: string = "hermenix" # checkout path on the remote, relative to $HOME
--repo: string = "ssh://gitea@minipc1.lab.internal:22/ari/hermenix.git"
] {
if ($args | is-empty) {
die "usage: hermenix remote <host> <setup|migrate> [args...]"
}
let quoted_args = ($args | each {|a| shquote $a } | str join " ")
let remote_cmd = $"if [ ! -d (shquote $dir) ]; then git clone (shquote $repo) (shquote $dir); fi && cd (shquote $dir) && nix run .#hermenix -- ($quoted_args)"
say $"Running on ($host): ($args | str join ' ')"
^ssh -t -o StrictHostKeyChecking=accept-new $host $remote_cmd
}