This is able to automatically generate snapshots before/after DNF transactions, but the snaphots still don't show up in grub. What's missing? This is Fedora btw
sudo dnf -y install snapper python-dnf-plugin-snapper libdnf5-plugin-actions
sudo tee /etc/dnf/libdnf5-plugins/actions.d/snapper.actions > /dev/null <<'EOF'
# Get snapshot description
pre_transaction::::/usr/bin/sh -c echo\ "tmp.cmd=$(ps\ -o\ command\ --no-headers\ -p\ '${pid}')"
# Creates pre snapshot before the transaction and stores the snapshot number in the "tmp.snapper_pre_number" variable.
pre_transaction::::/usr/bin/sh -c echo\ "tmp.snapper_pre_number=$(snapper\ create\ -t\ pre\ -p\ -d\ '${tmp.cmd}')"
# If the variable "tmp.snapper_pre_number" exists, it creates post snapshot after the transaction and removes the variable "tmp.snapper_pre_number".
post_transaction::::/usr/bin/sh -c [\ -n\ "${tmp.snapper_pre_number}"\ ]\ &&\ snapper\ create\ -t\ post\ --pre-number\ "${tmp.snapper_pre_number}"\ -d\ "${tmp.cmd}"\ ;\ echo\ tmp.snapper_pre_number\ ;\ echo\ tmp.cmd
EOF
sudo snapper -c root create-config /
sudo btrfs subvolume delete /.snapshots
sudo mkdir /mnt/btrfs /.snapshots
sudo mount /dev/disk/by-uuid/$uuid /mnt/btrfs
cd /mnt/btrfs
sudo btrfs subvolume create snapshots
cd ~
sudo umount /mnt/btrfs
sudo rmdir /mnt/btrfs
echo "UUID=$uuid /.snapshots btrfs subvol=snapshots,compress=zstd:1 0 0" | sudo tee -a /etc/fstab
sudo systemctl daemon-reload
sudo mount -a
sudo btrfs subvolume set-default $root_id /
sudo grubby --update-kernel=ALL --remove-args="rootflags=subvol=root"
sudo sed -i \
-e 's|^\(NUMBER_LIMIT\s*=\s*\).*|\1"10"|' \
-e 's|^\(TIMELINE_CREATE\s*=\s*\).*|\1"no"|' \
"/etc/snapper/configs/root"