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 }