feat(nixos): boot the last good generation after 3 failed boots

Assisted-by: DeepSeek Harness (claude-opus-5-5)
This commit is contained in:
Ryan Yin committed 2026-11-17 21:05:20 +08:00
1 parent 9b1a716aa8
commit 08a4dd2e21
4 files changed
+15 -1

No files matched your search

+1 -1
View File
@@ -45,7 +45,7 @@ small, reversible controls and narrow exceptions; benchmark before adopting expe
| Security keys | idols-ai/shoukei use a CanoKey for touch-based sudo (pam_u2f, password fallback; servers via pam_rssh and the forwarded agent), a resident `ed25519-sk` SSH key per CanoKey as the only user SSH keys for GitHub and all hosts, FIDO2 LUKS unlock on shoukei and on-card OpenPGP subkeys; key management happens only in the phone app ([setup](./security-keys.md)) | Touch-only sudo can be triggered by any same-user process, and on a server by root through the forwarded agent; losing both CanoKeys leaves only root logins with the `romantic` recovery key |
| Secrets | agenix declarations here, encrypted data in the private nix-secrets repository | Recipients and plaintext file permissions must be reviewed; root on a recipient can read its decrypted secrets |
| Supply chain | Locked flake inputs; explicit binary-cache trust keys on NixOS; normal user is not a Nix trusted-user | A trusted cache or imported Nix module can supply code executed as root; a lock file is not a security audit |
| Recovery | NixOS generations, btrbk/restic, hourly read-only snapshots of the REST store, and documented backup procedures | A rollback does not undo compromised data or secrets; backup configuration alone does not prove restore works; the offsite immutable copy is still planned |
| Recovery | NixOS generations with automatic boot fallback on the physical servers, btrbk/restic, hourly read-only snapshots of the REST store, and documented backup procedures | A rollback does not undo compromised data or secrets; backup configuration alone does not prove restore works; the offsite immutable copy is still planned |
Sources: [host layout](../hosts/README.md), [k3s deployment](../hosts/k8s/README.md),
[firewall](../modules/nixos/base/networking/firewall.nix), [SSH](../modules/nixos/base/ssh.nix),
+9
View File
@@ -182,6 +182,15 @@ qemu-kvm path; there are none right now.
/ `br0` changes, nixpkgs updates, or any broad rebuild.
- If a host loses VM networking, check `br0` and the VM taps, or reboot the host.
## Boot Recovery on Physical Servers
`shoryu`, `shushou`, `youko` (systemd-boot) and `aquamarine` (Lanzaboote) write each new generation
with a boot counter. After 3 boots that never reach `boot-complete.target` (ordered after
`sysinit.target`), the entry is marked bad and the boot loader starts the newest good one. The root
LUKS volume unlocks through TPM2 alone, so retries need no console. Failures later in boot, such as
a broken `br0`, do not count, and a hung boot retries only after a reboot or power cycle.
`bootctl list` shows each entry's remaining tries.
## Common Build Commands
Use the Just recipes for host configuration checks and builds:
+2
View File
@@ -26,5 +26,7 @@
boot.lanzaboote = {
enable = true;
pkiBundle = "/etc/secureboot";
# Retries need no console: root LUKS unlocks through TPM2 alone (hosts/README.md).
bootCounting.initialTries = 3;
};
}
+3
View File
@@ -30,6 +30,9 @@ in
"nfs"
];
# Retries need no console: root LUKS unlocks through TPM2 alone (hosts/README.md).
boot.loader.systemd-boot.bootCounting.enable = true;
# KVM for the microVMs and the libvirt domains. AMD-specific: an Intel VM host
# would need kvm-intel instead (see hosts/idols-ai/hardware-intel.nix).
boot.kernelModules = [ "kvm-amd" ];