From 6d7ff4eace333aadf5b66f6a03d1d639c1d3162a Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Wed, 16 Sep 2026 10:47:34 -0400 Subject: [PATCH] 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 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 --- README.md | 9 ++++++++- nu/hermenix.nu | 25 +++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c467eb8..46d4bbd 100644 --- a/README.md +++ b/README.md @@ -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 #hermenix -- ` 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). diff --git a/nu/hermenix.nu b/nu/hermenix.nu index b113d31..96e6f6b 100644 --- a/nu/hermenix.nu +++ b/nu/hermenix.nu @@ -16,8 +16,10 @@ # hermenix migrate carry an existing flat HERMES_HOME (e.g. from # a prior Docker deployment) into a running # guest, unchanged -# hermenix remote ... run either of the above ON a remote host over -# SSH, instead of having to SSH in yourself first +# hermenix remote "" run either of the above ON a remote host +# over SSH (quote 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 carry an existing flat HERMES_HOME into the guest" - print " hermenix remote ... run setup/migrate on a remote host over SSH" + print " hermenix remote \"\" run setup/migrate on a remote host over SSH" print "" print "run `hermenix --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 [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 " [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 }