2024-11-06 22:39:23 -05:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{
|
|
|
|
boot = {
|
2024-11-12 04:25:51 -05:00
|
|
|
kernelPackages = pkgs.linuxPackages_5_10;
|
2024-11-06 22:39:23 -05:00
|
|
|
kernel.sysctl."vm.max_map_count" = 2147483642;
|
|
|
|
|
|
|
|
initrd.systemd = {
|
|
|
|
enable = true;
|
|
|
|
services.root-reset = {
|
|
|
|
description = "Reset root and snapshot last boot";
|
|
|
|
wantedBy = [ "initrd.target" ];
|
|
|
|
before = [ "sysroot.mount" ];
|
2024-11-12 04:25:51 -05:00
|
|
|
after = [ "dev-${config.networking.hostName}-root.device" ];
|
2024-11-06 22:39:23 -05:00
|
|
|
unitConfig.DefaultDependencies = "no";
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
script = ''
|
|
|
|
mkdir -p /mnt
|
|
|
|
mount /dev/${config.networking.hostName}/root /mnt
|
|
|
|
|
|
|
|
if [[ -e /mnt/prev ]]; then
|
|
|
|
btrfs subvolume delete /mnt/prev
|
|
|
|
fi
|
|
|
|
|
|
|
|
btrfs subvolume snapshot /mnt/root /mnt/prev
|
|
|
|
|
|
|
|
btrfs subvolume list -o /mnt/root | cut -f9 -d' ' | while read subvolume; do
|
|
|
|
btrfs subvolume delete "/mnt/$subvolume"
|
|
|
|
done
|
|
|
|
|
|
|
|
btrfs subvolume delete /mnt/root
|
|
|
|
btrfs subvolume create /mnt/root
|
|
|
|
|
|
|
|
umount /mnt
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|