Fix: hermenix remote host setup --clean failed to parse at all

nu's own CLI dispatch treats any bare --flag-shaped token as an
attempt to match a flag on the CURRENT command, even when it's meant
for a rest parameter, and even with a `--` separator (confirmed
neither `...args: string` nor `-- ` sidesteps it - both still error
before ever reaching the function body). This broke `hermenix remote
<host> setup --clean` outright, both locally and thus for anyone
running it - confirmed live on hl-fwdesk right after landing --clean.

Changed `main remote`'s second parameter from a rest param to a single
`cmd: string` - the caller now quotes the subcommand and its flags as
one string ("setup --clean", "migrate /var/lib/hermes"). Since it's a
single value bound to a plain string parameter, nu never inspects its
contents for flags. Inside main remote, cmd is split back into words
and each one re-quoted for the actual remote invocation, so the
semantics on the wire are unchanged - just the calling convention.

Verified: the exact previously-failing invocation now parses and
constructs the correct `'setup' '--clean'` remote command (checked
directly, not just parse-checked).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ariandClaude Sonnet 5 committed 2026-09-16 10:47:34 -04:00
1 parent 3c491b1624
commit 6d7ff4eace
2 files changed
+25 -9

No files matched your search

+8 -1
View File
@@ -215,9 +215,16 @@ 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
hermenix remote fwdesk.lab.internal "setup --clean"
hermenix remote fwdesk.lab.internal "migrate /var/lib/hermes"
```
Quote the subcommand and its own flags/args as **one string** whenever
there's more than just the bare subcommand name — nu's own argument parser
treats any bare `--flag`-shaped word as an attempt to match a flag on
`remote` itself, so `hermenix remote host setup --clean` (unquoted) fails
before it ever reaches the SSH step.
It runs `nix run <flake>#hermenix -- <the rest of the command>` directly on
the remote host — no checkout involved, on either end. The remote host does
need its own SSH access to Gitea (the same access a `git clone` would need).
+17 -8
View File
@@ -16,8 +16,10 @@
# 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
# hermenix remote <host> "<cmd>" run either of the above ON a remote host
# over SSH (quote <cmd> as one string, e.g.
# "setup --clean"), instead of having to SSH
# in yourself first
#
# None of these run `nixos-rebuild` — that stays yours to run, watching it
# happen.
@@ -85,7 +87,7 @@ 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 " hermenix remote <host> \"<cmd>\" run setup/migrate on a remote host over SSH"
print ""
print "run `hermenix <subcommand> --help` for details on any of these."
}
@@ -510,16 +512,23 @@ def "main migrate" [
# access it would need for a git clone, so nothing new).
def "main remote" [
host: string # SSH target, e.g. fwdesk.lab.internal
...args: string # forwarded to the remote `hermenix` invocation
cmd: string # the subcommand plus its own args/flags, quoted as ONE string - e.g. "setup --clean" or "migrate /var/lib/hermes"
--flake: string = "git+ssh://gitea@minipc1.lab.internal:22/ari/hermenix.git"
] {
if ($args | is-empty) {
die "usage: hermenix remote <host> <setup|migrate> [args...]"
# `cmd` has to be a single string, not a rest param: nu's own CLI parser
# treats any bare --flag-shaped token as an attempt to match a flag on
# THIS command (main remote), even inside a rest parameter and even with
# a `--` separator - so `hermenix remote host setup --clean` fails before
# ever reaching this function. Splitting cmd back into words here (and
# re-quoting each one) sidesteps that entirely.
let words = ($cmd | split row " " | where {|w| $w != "" })
if ($words | is-empty) {
die $'usage: hermenix remote <host> "<setup|migrate> [args...]"'
}
let quoted_args = ($args | each {|a| shquote $a } | str join " ")
let quoted_args = ($words | each {|a| shquote $a } | str join " ")
let remote_cmd = $"nix run --no-write-lock-file --refresh (shquote $flake)#hermenix -- ($quoted_args)"
say $"Running on ($host): ($args | str join ' ')"
say $"Running on ($host): ($cmd)"
^ssh -t -o StrictHostKeyChecking=accept-new $host $remote_cmd
}