Eliminate the git-clone dependency entirely

hermenix setup/migrate/remote no longer need a local checkout anywhere:

- Host-specific settings (cache signing key, SSH keys) now live at
  /etc/hermenix/local.nix on the host itself, read via an absolute-path
  import in common.nix (--impure, deliberately - reading outside the
  flake's own source tree). No more guest/common.nix patching, no more
  guest/common.nix.bak, no more git-pull conflicts on a locally-edited
  tracked file (see the hermes-vm.service incident on hl-fwdesk).
- `setup` builds directly from the flake's own git+ssh URL by default
  (--flake to override), so it works from any directory on any host -
  dropped the "run this from the hermenix repository root" requirement
  entirely.
- `remote` now just runs `nix run <flake>#hermenix -- ...` on the target
  host directly - dropped the clone-if-missing/--dir/--repo machinery,
  since there's no checkout to manage anymore.

guest/local.nix.example documents the expected shape. Verified the
write-then-read-back round trip (nix-instantiate --eval --json) and the
simplified remote command construction against sandboxed stubs before
pushing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ariandClaude Sonnet 5 committed 2026-09-15 15:10:13 -04:00
1 parent 2078204168
commit 41ea93a28f
5 files changed
+142 -98

No files matched your search

+64 -61
View File
@@ -2,9 +2,17 @@
#
# hermenix — host-side tooling for the Hermes Agent VM.
#
# No local checkout needed for any of this. `hermenix` is a flake package,
# meant to be run straight from its git+ssh URL - `nix run <flake>#hermenix`
# (or install it once with `nix profile install <flake>#hermenix` / the
# nixos-setup overlay, then just `hermenix ...`). Host-specific settings
# (cache signing key, your SSH key) live at /etc/hermenix/local.nix on the
# host itself, not in a repo checkout - see guest/local.nix.example.
#
# Three subcommands:
# hermenix setup guided host-side setup: disks, cache signing
# key, guest/common.nix, build + write the image
# key, /etc/hermenix/local.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
@@ -71,13 +79,16 @@ def main [] {
# ------------------------------------------------------------------ setup ---
# Guided host-side setup: disks, cache signing key, guest/common.nix, build
# and write the bootstrap image. Safe to re-run — every step checks what's
# already done and offers to skip. Never runs nixos-rebuild.
def "main setup" [] {
# Guided host-side setup: disks, cache signing key, /etc/hermenix/local.nix,
# build and write the bootstrap image. Safe to re-run — every step checks
# what's already done and offers to skip. Never runs nixos-rebuild. Works
# from any directory - no local checkout of this repo needed.
def "main setup" [
--flake: string = "git+ssh://gitea@minipc1.lab.internal:22/ari/hermenix.git"
] {
$env.HERMENIX_NEED_SUDO = ((^id -u | str trim) != "0")
let common = "guest/common.nix"
let local_path = "/etc/hermenix/local.nix"
let cache_name = "hermes-cache-1"
let secret_key = "/var/lib/secrets/hermes-cache.secret"
let public_key = "/var/lib/secrets/hermes-cache.pub"
@@ -89,9 +100,6 @@ def "main setup" [] {
note "module snippet into your own configuration at the end."
step 1 "Checking prerequisites"
if not ("flake.nix" | path exists) or not ($common | path exists) {
die "run this from the hermenix repository root"
}
if (which nix | is-empty) { die "nix not found on PATH" }
if (do -i { ^nix flake --help } | complete).exit_code != 0 {
die "flakes are not enabled. Add 'experimental-features = nix-command flakes' to /etc/nix/nix.conf"
@@ -208,24 +216,29 @@ def "main setup" [] {
}
step 4 "SSH access to the guest"
let common_lines = (open $common | lines)
let ak_start = ($common_lines | enumerate | where item == " authorizedKeys = [" | get index | get 0?)
let current_keys = if $ak_start != null {
let ak_end_rel = ($common_lines | skip ($ak_start + 1) | enumerate | where item == " ];" | get index | get 0)
($common_lines | slice ($ak_start + 1)..($ak_start + $ak_end_rel) | where {|l| $l | str trim | str starts-with '"ssh-' } | length)
let existing = if ($local_path | path exists) {
let evaluated = (do -i { ^nix-instantiate --eval --json --strict -E $"import ($local_path)" } | complete)
if $evaluated.exit_code == 0 {
$evaluated.stdout | from json
} else {
warn $"($local_path) exists but failed to evaluate - treating as empty"
{ cachePublicKey: "", authorizedKeys: [] }
}
} else {
0
{ cachePublicKey: "", authorizedKeys: [] }
}
let existing_keys = ($existing.authorizedKeys? | default [])
let replace_keys = if $current_keys > 0 {
ok $"($current_keys) key\(s\) already configured in ($common)"
let replace_keys = if ($existing_keys | length) > 0 {
ok $"($existing_keys | length) key\(s\) already configured in ($local_path)"
confirm "Replace them?"
} else {
true
}
mut selected_keys = []
mut selected_keys = $existing_keys
if $replace_keys {
mut picked = []
let found = (glob $"($env.HOME)/.ssh/*.pub")
if ($found | length) > 0 {
say "Public keys found in ~/.ssh:"
@@ -240,59 +253,50 @@ def "main setup" [] {
if $idx < 0 or $idx >= ($found | length) {
die $"no such option: ($n)"
}
$selected_keys = ($selected_keys | append (open ($found | get $idx) | str trim))
$picked = ($picked | append (open ($found | get $idx) | str trim))
}
}
}
if ($selected_keys | is-empty) {
if ($picked | is-empty) {
let pasted = ask "Paste a public key (blank to skip)"
if $pasted != "" { $selected_keys = [$pasted] }
if $pasted != "" { $picked = [$pasted] }
}
if ($selected_keys | is-empty) {
if ($picked | is-empty) {
warn "no SSH key set — you'll only be able to reach the guest with 'hermes-vm console'"
}
$selected_keys = $picked
}
step 5 $"Writing ($common)"
if not ($"($common).bak" | path exists) {
cp $common $"($common).bak"
note $"original saved as ($common).bak"
}
mut lines = (open $common | lines)
# cachePublicKey
$lines = ($lines | each {|l|
if ($l | str starts-with " cachePublicKey = ") {
$" cachePublicKey = \"($cache_pub)\";"
} else {
$l
}
})
ok "cachePublicKey set"
# authorizedKeys block
if not ($selected_keys | is-empty) {
let start = ($lines | enumerate | where item == " authorizedKeys = [" | get index.0)
let end_rel = ($lines | skip ($start + 1) | enumerate | where item == " ];" | get index.0)
let end = $start + 1 + $end_rel
let new_key_lines = ($selected_keys | each {|k| $" \"($k)\"" })
$lines = (($lines | slice 0..$start) ++ $new_key_lines ++ ($lines | slice $end..(($lines | length) - 1)))
ok $"authorizedKeys set \(($selected_keys | length) key\(s\)\)"
}
$lines | str join "\n" | save -f $common
step 5 $"Writing ($local_path)"
let key_lines = ($selected_keys | each {|k| $" \"($k)\"" } | str join "\n")
let content = $"# Written by `hermenix setup`. Lives on the host, not in a repo checkout -
# see guest/local.nix.example in the hermenix repo for the reference shape.
\{
cachePublicKey = \"($cache_pub)\";
authorizedKeys = [
($key_lines)
];
\}
"
let tmp = (^mktemp | str trim)
$content | save -f $tmp
priv mkdir "-p" (($local_path | path dirname))
priv cp $tmp $local_path
priv chmod 0644 $local_path
rm $tmp
ok $"($local_path) written \(($selected_keys | length) key\(s\)\)"
step 6 "Building the bootstrap image"
note "The extra substituter flags stop you compiling Determinate Nix yourself."
mut built = false
note "--impure is needed to read /etc/hermenix/local.nix at eval time."
if (confirm "Build now? (first run can take a while)") {
^nix build .#hermes-guest-image --option extra-substituters $determinate_sub --option extra-trusted-public-keys $determinate_key
^nix build --impure $"($flake)#hermes-guest-image" --option extra-substituters $determinate_sub --option extra-trusted-public-keys $determinate_key
ok "built"
$built = true
} else {
say "Skipped. Run manually:"
note " nix build .#hermes-guest-image \\"
note $" nix build --impure ($flake)#hermes-guest-image \\"
note $" --option extra-substituters ($determinate_sub) \\"
note $" --option extra-trusted-public-keys ($determinate_key)"
}
@@ -331,7 +335,7 @@ def "main setup" [] {
print $"
(ansi dark_gray)# flake.nix(ansi reset)
inputs.hermenix.url = \"path:(pwd)\";
inputs.hermenix.url = \"($flake)\";
(ansi dark_gray)# then in your modules list(ansi reset)
hermenix.nixosModules.default
@@ -468,22 +472,21 @@ def "main migrate" [
# `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.
# No checkout involved anywhere: runs `nix run <flake>#hermenix -- ...`
# directly on the remote host, fetching straight from Gitea. Requires the
# remote host to have its own SSH access to Gitea already set up (the same
# 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
--dir: string = "hermenix" # checkout path on the remote, relative to $HOME
--repo: string = "ssh://gitea@minipc1.lab.internal:22/ari/hermenix.git"
--flake: string = "git+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)"
let remote_cmd = $"nix run (shquote $flake)#hermenix -- ($quoted_args)"
say $"Running on ($host): ($args | str join ' ')"
^ssh -t -o StrictHostKeyChecking=accept-new $host $remote_cmd