rebuild-host: rebuild the hypervisor from DEPLOY_FLAKE, not the working directory #59
Labels
No labels
blocked
bug
decision
duplicate
enhancement
help wanted
invalid
landed?
question
ready-to-merge
stale
wontfix
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
allod/nexus#59
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Give the hypervisor a
rebuild-hostscript that rebuilds the host itself fromDEPLOY_FLAKE, so the operator's working directory can no longer select which flake the host is built from.Primary goals:
rebuild-hostrunsnixos-rebuild switch --flake "$DEPLOY_FLAKE#$(hostname)", reading the same pointernexus.provisioning.deployFlakealready renders into the operator session for the VM scripts (nix/configuration.nix:22-34).DEPLOY_FLAKEis a refusal with a message naming the option, not a fallback to$HOME/work/allod/deploy. For the VM scripts that fallback is the public template's convenience; for the host it is exactly the failure this issue exists to stop.system.build.toplevelout path before switching, so an operator can compare it againstnix eval "$DEPLOY_FLAKE#nixosConfigurations.<host>.config.system.build.toplevel.outPath"and a rebuild that changes hundreds of packages on a lock bump that moved one input is visible before it lands.rebuild-vm-from-host—set -euo pipefail,die, aNIXOS_REBUILDoverride so the test suite can substitute a recorder, packaged unwrapped bynix/provisioning-scripts.nixlike every other host script.Current state and specifics
The host is rebuilt by hand with
sudo nixos-rebuild switch --flake .#<host>from whatever directory the shell is in. A deployment keeps two checkouts that both evaluate that attribute: its own composition root and the public templateallod/deploy, whosenixosConfigurationscarries the same host name so that the template stays a working example. Run from the template checkout, the command evaluates, builds, and switches cleanly, then removes the desktop, the operator's home-manager unit, the tailnet and VPN units, and the deployment's secrets, and installs the template'sallodaccount instead. Switching stops the display manager, which kills the session running the rebuild, and the next boot lands on a text console. To the operator this is indistinguishable from a bricked host; recovery was booting the previous generation from the boot menu and deleting the bad one by hand.This has now happened twice on one deployment. The second time the diagnosis took the closure diff between the two generations (
nix store diff-closures) plus an out-of-band evaluation of both flakes to match the bad generation's store path to the template. Nothing on the host said which flake it was built from.The VM scripts already solved this for guests:
rebuild-vm-from-hostandprovision-vm-from-hostreadDEPLOY_FLAKE(scripts/rebuild-vm-from-host:6,scripts/rebuild-vm-from-host:67), andnexus.provisioning.deployFlakerenders it with an absolute-path type guard so a malformed pointer fails evaluation. The host rebuild is the one path that still takes its target from the shell.Default shape:
with
switchthe default and the mode passed through tonixos-rebuildunchanged. No target-machine argument: the host rebuilds itself and the attribute is$(hostname).Validation
NIXOS_REBUILDpointing at a recorder,rebuild-hostinvokes it withswitch --flake <DEPLOY_FLAKE>#<hostname>; withDEPLOY_FLAKEunset it exits non-zero without invoking it; the printed toplevel path equals whatnix evalreports for the same attribute.rebuild-hostafter a lock bump that moved one input, confirm the new generation'sreadlink /nix/var/nix/profiles/system-<N>-linkequals the printed path, and confirmnix store diff-closuresagainst the previous generation shows only that input's consequences.Scope
In: the script, its tests, the packaging test line in
nix/provisioning-scripts.nix, and the README sentence that tells an operator how to rebuild the host. Out: rolling a host or guest back to its previous generation, which is allod/nexus#39; the VM rebuild path, which already readsDEPLOY_FLAKE; and any guard insidenixos-rebuilditself.