deploy: automate a full local reinstall, self-elevating and interactive-safe
./scripts/deploy install <config> localhost now branches on is_live_installer() (checks uname -n): outside a live installer it builds installer-iso, stages its kernel/initrd on the ESP and the iso file on a disk the caller picks (never auto-picked — the wrong disk here is destroyed mid-install), writes a systemd-boot one-shot findiso= entry with homelab.install=<config> on the kernel cmdline, and does a real systemctl reboot (not kexec — terra's kexec-local hang is specifically in kexec's device-shutdown pass, a real ACPI reboot never runs that code at all). installer-iso gains homelab-auto-install.service: once homelab-checkout.service clones the repo, it reads homelab.install= back off /proc/cmdline and re-runs the identical deploy command itself, now genuinely inside the installer, so it takes the disko+nixos-install branch instead of preparing again. The whole reinstall is one command and unattended after the first reboot. Also: every root-requiring path (kexec-local, the new prepare-and-reboot branch, the disko+nixos-install branch) self-elevates via a require_root() helper that re-execs the original invocation under sudo -E, instead of dying and asking the caller to prefix sudo themselves. Uses an absolute script path captured before the script's own cd, so the re-exec is correct regardless of how it was invoked. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -205,6 +205,33 @@
|
||||
git clone --depth 1 https://git.mgaction.town/darman/homelab.git /root/homelab
|
||||
'';
|
||||
};
|
||||
|
||||
# Finishes a local_install_prepare_and_reboot() run (scripts/deploy)
|
||||
# unattended: that function stages this ISO, points a systemd-boot
|
||||
# one-shot entry at it with `homelab.install=<config>` on the kernel
|
||||
# cmdline, and reboots. Once booted here, this re-runs the exact same
|
||||
# `./scripts/deploy install <config> localhost` command — now genuinely
|
||||
# inside the installer (hostname homelab-installer), so is_live_installer
|
||||
# takes the disko+nixos-install branch instead of preparing again.
|
||||
# A manual boot of this ISO with no such cmdline param is a no-op.
|
||||
systemd.services.homelab-auto-install = {
|
||||
description = "Auto-run the homelab install if homelab.install= was passed on the kernel cmdline";
|
||||
after = [ "homelab-checkout.service" ];
|
||||
requires = [ "homelab-checkout.service" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
path = [ pkgs.gnugrep ];
|
||||
serviceConfig.Type = "oneshot";
|
||||
script = ''
|
||||
cfg=$(grep -o 'homelab\.install=[^ ]*' /proc/cmdline | cut -d= -f2 || true)
|
||||
if [ -z "$cfg" ]; then
|
||||
echo "no homelab.install= on the kernel cmdline — nothing to auto-install"
|
||||
exit 0
|
||||
fi
|
||||
echo "auto-installing $cfg (homelab.install= on the kernel cmdline)"
|
||||
cd /root/homelab
|
||||
exec ./scripts/deploy install "$cfg" localhost
|
||||
'';
|
||||
};
|
||||
})
|
||||
];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user