difftreelog
feat more resilent rollback service
in: trunk
1 file changed
nixos/rollback.nixdiffbeforeafterboth1{config, ...}: {2 # TODO: Make it work with systemd-initrd approach.3 # In this case we can't just switch generation and re-run activation script, since the root filesystem might not be4 # mounted yet. We need to explicitly remove the last generation, and this needs deeper integration with systemd/grub/5 # whatever user uses. boot.json also might help here.67 systemd.services.rollback-watchdog = {8 description = "Rollback watchdog";9 script = ''10 set -eu11 if [ -f /etc/fleet_rollback_marker ]; then12 echo "found the rollback marker, switching to older generation"13 target=cat14 echo "rolling back profile"15 nix profile rollback --profile /nix/var/nix/profiles/system --to "$target"16 echo "executing activation script"17 "/nix/var/nix/profiles/system-$target-link/bin/switch-to-configuration" switch18 echo "removing rollback marker"19 rm -f /etc/fleet_rollback_marker20 else21 echo "rollback marker was removed, upgrade is succeeded"22 fi23 '';24 path = [25 # Should have nix-command support26 config.nix.package27 ];28 serviceConfig.Type = "exec";29 unitConfig = {30 X-StopOnRemoval = false;31 };32 };3334 systemd.timers.rollback-watchdog = {35 description = "Timer for rollback watchdog";36 wantedBy = ["timers.target"];37 timerConfig = {38 OnUnitActiveSec = "3min";39 RemainAfterElapse = false;40 };41 unitConfig = {42 ConditionPathExists = "/etc/fleet_rollback_marker";43 };44 };45}1{config, ...}: {2 # TODO: Make it work with systemd-initrd approach.3 # In this case we can't just switch generation and re-run activation script, since the root filesystem might not be4 # mounted yet. We need to explicitly remove the last generation, and this needs deeper integration with systemd/grub/5 # whatever user uses. boot.json also might help here.67 systemd.services.rollback-watchdog = {8 description = "Rollback watchdog";9 script = ''10 set -eux11 if [ -f /etc/fleet_rollback_marker ]; then12 echo "found the rollback marker, switching to older generation"13 target=cat14 echo "rolling back profile"15 nix profile rollback --profile /nix/var/nix/profiles/system --to "$target"16 echo "executing activation script"17 "/nix/var/nix/profiles/system-$target-link/bin/switch-to-configuration" switch || true18 echo "removing rollback marker"19 rm -f /etc/fleet_rollback_marker20 else21 echo "rollback marker was removed, upgrade is succeeded"22 fi23 '';24 path = [25 # Should have nix-command support26 config.nix.package27 ];28 serviceConfig.Type = "exec";29 unitConfig = {30 X-StopOnRemoval = false;31 X-RestartIfChanged = false;32 X-StopIfChanged = false;33 };34 };3536 systemd.timers.rollback-watchdog = {37 description = "Timer for rollback watchdog";38 wantedBy = ["timers.target"];39 timerConfig = {40 OnActiveSec = "3min";41 RemainAfterElapse = false;42 };43 unitConfig = {44 ConditionPathExists = "/etc/fleet_rollback_marker";45 };46 };47}