git.delta.rocks / jrsonnet / refs/commits / 3627c6c6df00

difftreelog

source

modules/nixos/rollback.nix1.6 KiBsourcehistory
1# Tied to build_systems.rs2{config, ...}: {3  # TODO: Make it work with systemd-initrd approach.4  # In this case we can't just switch generation and re-run activation script, since the root filesystem might not be5  # mounted yet. We need to explicitly remove the last generation, and this needs deeper integration with systemd/grub/6  # whatever user uses. boot.json also might help here.78  systemd.services.rollback-watchdog = {9    description = "Rollback watchdog";10    script = ''11      set -eux12      if [ -f /etc/fleet_rollback_marker ]; then13        echo "found the rollback marker, switching to older generation"14        target=$(cat /etc/fleet_rollback_marker)15        echo "rolling back profile"16        nix profile rollback --profile /nix/var/nix/profiles/system --to "$target"17        echo "executing activation script"18        "/nix/var/nix/profiles/system-$target-link/bin/switch-to-configuration" switch || true19        echo "removing rollback marker"20        rm -f /etc/fleet_rollback_marker21      else22        echo "rollback marker was removed, upgrade is succeeded"23      fi24    '';25    path = [26      # Should have nix-command support27      config.nix.package28    ];29    serviceConfig.Type = "exec";30    unitConfig = {31      X-StopOnRemoval = false;32      X-RestartIfChanged = false;33      X-StopIfChanged = false;34    };35  };3637  systemd.timers.rollback-watchdog = {38    description = "Timer for rollback watchdog";39    wantedBy = ["timers.target"];40    timerConfig = {41      OnActiveSec = "3min";42      RemainAfterElapse = false;43    };44    unitConfig = {45      ConditionPathExists = "/etc/fleet_rollback_marker";46    };47  };48}