configuration.nix/hosts/skipper/rollback.nix

28 lines
723 B
Nix
Raw Normal View History

2023-04-26 22:56:43 +05:30
{ lib, ... }: {
boot.initrd.postDeviceCommands = lib.mkBefore ''
mkdir -p /mnt
mount -o subvol=/ /dev/vg0/system /mnt
btrfs subvolume list -o /mnt |
cut -f9 -d' ' |
while read subvolume; do
echo "deleting /$subvolume subvolume..."
btrfs subvolume delete "/mnt/$subvolume"
done &&
echo "deleting /root subvolume..." &&
btrfs subvolume delete "/mnt/@root"
echo "restoring blank /root subvolume..."
btrfs subvolume snapshot /mnt/@root-blank /mnt/@root
echo "deleting /home subvolume..."
btrfs subvolume delete /mnt/@home
echo "restoring blank /home subvolume..."
btrfs subvolume snapshot /mnt/@home-blank /mnt/@home
umount /mnt
'';
}