git.delta.rocks / jrsonnet / refs/heads / trunk

difftreelog

source

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