configuration.nix/hosts/skipper/persistence/rollback.nix

33 lines
1,005 B
Nix
Raw Normal View History

2023-07-11 22:41:18 +05:30
_: {
boot.initrd.systemd.services.rollback = {
description = "Rollback root subvolume to blank state";
2023-11-04 16:12:45 +05:30
wantedBy = [ "initrd.target" ];
after = [ "dev-vg0-system.device" ];
before = [ "sysroot.mount" ];
unitConfig.DefaultDependencies = "no";
serviceConfig.Type = "oneshot";
script = ''
mkdir -p /mnt
mount -o subvol=/ /dev/vg0/system /mnt
2023-04-26 22:56:43 +05:30
btrfs subvolume list -o /mnt/@root | cut -f9 -d' ' | while read subvolume; do
2023-04-26 22:56:43 +05:30
echo "deleting /$subvolume subvolume..."
btrfs subvolume delete "/mnt/$subvolume"
done &&
echo "deleting /root subvolume..." &&
btrfs subvolume delete "/mnt/@root"
2023-04-26 22:56:43 +05:30
echo "restoring blank /root subvolume..."
btrfs subvolume snapshot "/mnt/@root-blank" "/mnt/@root"
2023-04-26 22:56:43 +05:30
echo "deleting /home subvolume..."
btrfs subvolume delete "/mnt/@home"
2023-04-26 22:56:43 +05:30
echo "restoring blank /home subvolume..."
btrfs subvolume snapshot "/mnt/@home-blank" "/mnt/@home"
2023-04-26 22:56:43 +05:30
umount /mnt
'';
};
2023-04-26 22:56:43 +05:30
}