Commit 8f67c0b96972
Changed files (2)
home
common
shell
pkgs
my
scripts
bin
home/common/shell/openssh.nix
@@ -180,11 +180,12 @@ in
};
};
}
- # Generated microvm SSH aliases
- // (lib.mapAttrs (_name: vm: {
+ # Generated microvm SSH aliases (with on-demand VM startup)
+ // (lib.mapAttrs (name: vm: {
hostname = vm.ip;
user = "vincent";
- proxyJump = globals.microvms.host;
+ # Use ProxyCommand for on-demand VM startup instead of ProxyJump
+ proxyCommand = "microvm-ssh ${name} ${vm.ip} %p";
identitiesOnly = true;
identityFile = lib.mkIf hasFido2Keys "~/.ssh/id_homelab_sk";
extraOptions = {
pkgs/my/scripts/bin/microvm-ssh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+# Start microvm on demand and connect via SSH
+# Usage: microvm-ssh <vm-name> <host> <port>
+#
+# This script is used as SSH ProxyCommand to:
+# 1. Start the microvm if not running (via aomi)
+# 2. Wait for SSH to become available
+# 3. Connect using nc/socat
+
+set -euo pipefail
+
+VM_NAME="${1:-}"
+HOST="${2:-}"
+PORT="${3:-22}"
+JUMP_HOST="${MICROVM_JUMP_HOST:-aomi.sbr.pm}"
+
+if [[ -z "$VM_NAME" ]] || [[ -z "$HOST" ]]; then
+ echo "Usage: microvm-ssh <vm-name> <host> [port]" >&2
+ exit 1
+fi
+
+# Check if VM is running, start if not
+# This runs on the jump host (aomi)
+ssh -q "$JUMP_HOST" "
+ if ! systemctl is-active --quiet microvm@${VM_NAME}; then
+ echo 'Starting microvm@${VM_NAME}...' >&2
+ sudo systemctl start microvm@${VM_NAME}
+ # Wait for VM to boot and SSH to be available
+ for i in {1..30}; do
+ if nc -z ${HOST} ${PORT} 2>/dev/null; then
+ break
+ fi
+ sleep 1
+ done
+ fi
+"
+
+# Connect through the jump host
+exec ssh -q -W "${HOST}:${PORT}" "$JUMP_HOST"