Dead man switch for nixos-rebuild switch / boot

blog post

tldr; switch-fix.nix lets you set an automatic rollback to current generation / profile on nixos-rebuild [switch | boot] unless you cancel with cancel-rollback from a terminal within a set amount of time

10 Likes

Ooh, nice.

GitHub - serokell/deploy-rs: A simple multi-profile Nix-flake deploy tool. does similar things for anyone interested, I still hope that it eventually gets local deployment as a first class citizen, until then this project seems like a cool alternative :slight_smile:

Yup, I started with deploy-rs, liked it! The two issues I had were, switch would sometimes not “stick”, in that on reboot, a previous generation would be default, and the auto rollback was sometimes iffy, either because of internet connection issues, or not possible (at least at the time) with boot (instead of switch).

This bit of bits was originally to address that first issue, and eventually the second.

1 Like

Sorry maybe I’m misunderstanding but what does this do that nixos-rebuild test doesn’t?

Two things I can think of:

  • nixos-rebuild test won’t reboot into a previous generation if you’ve done something technically correct, nix config-wise, but functionally terrible (like, make your remote box inaccessible through bad network config). This is not too much of a problem in a cloud instance, you usually have access to some kind of KVM console where you can force reboot, but I’ve been in situations where I have a bare-metal server somewhere without technical people around to help me reboot.
  • nixos-rebuilt test by definition, as far as I know, can’t test the full reboot process. That is, there are config changes that require a reboot to fully test. This module allows you to do nixos-rebuild boot, reboot, and if you leave it alone without ssh’ing in and cancel-reboot, it will roll back to the last (presumably) known good generation.
2 Likes

Or imagine you’ve deployed NixOS to a satellite and there somehow was a detail different in staging :smiley:

Some providers also charge for rescue shell access in some configurations.

Ok that’s a better example. :slight_smile: I have to imagine they had all sort of failsafes for that situation, like a/b boot configs similar to phones. Hmmmmm… nixos-a-b-boot…