configuration.nix/hosts/skipper/rollback.nix

33 lines
1,003 B
Nix
Raw Normal View History

2023-05-18 16:11:26 +05:30
{...}: {
boot.initrd.systemd.services.rollback = {
description = "Rollback root subvolume to blank state";
2023-05-18 16:11:26 +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
}