35 lines
1.8 KiB
Nu
35 lines
1.8 KiB
Nu
# hermenix remote — run setup or migrate on a remote host over SSH.
|
|
#
|
|
# No checkout involved anywhere: executes `nix run <flake>#hermenix -- ...`
|
|
# directly on the remote, fetching straight from Gitea. The remote host needs
|
|
# its own SSH access to Gitea already set up (same access as a git clone).
|
|
#
|
|
# Depends on: lib/common.nu (shquote, say, die).
|
|
|
|
# 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.
|
|
def "main remote" [
|
|
host: string # SSH target, e.g. fwdesk.lab.internal
|
|
cmd: string # subcommand + its own args, 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"
|
|
] {
|
|
# `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 = $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): ($cmd)"
|
|
^ssh -t -o StrictHostKeyChecking=accept-new $host $remote_cmd
|
|
}
|