diff --git a/lib/systems/fugitive/hardware.nix b/lib/systems/fugitive/hardware.nix index dae0ea1..31ddbf2 100644 --- a/lib/systems/fugitive/hardware.nix +++ b/lib/systems/fugitive/hardware.nix @@ -11,11 +11,44 @@ boot.kernelModules = [ ]; boot.extraModulePackages = [ ]; + boot.initrd.enable = true; + boot.initrd.supportedFilesystems = [ "btrfs" ]; + boot.initrd.systemd.enable = true; + boot.initrd.systemd.services.rollback = { + description = "Rollback BTRFS root subvolume to the blank state"; + wantedBy = [ "initrd.target" ]; + after = [ "initrd-root-device.target" ]; + before = [ "sysroot.mount" ]; + unitConfig.DefaultDependencies = "no"; + serviceConfig.Type = "oneshot"; + script = '' + mkdir -p "/mnt" + mount -o subvol="/" /dev/disk/by-label/Nixos /mnt + + echo "Cleanup /root-last" + + # Delete root-last + btrfs subvolume list -o /mnt/root-last | + cut -f9 -d' ' | + while read subvolume; do + btrfs subvolume delete "/mnt/$subvolume" + done && + btrfs subvolume delete /mnt/root-last + + # Move root to root-last + echo "Moving /root subvolume to /root-last" + mv /mnt/root /mnt/root-last + + # Restore root subvolume + btrfs subvolume snapshot /mnt/root-blank /mnt/root + ''; + }; + fileSystems."/" = { - device = "none"; - fsType = "tmpfs"; - options = [ "size=2G" "mode=755" ]; + device = "/dev/disk/by-label/Nixos"; + fsType = "btrfs"; + options = [ "subvol=root" "compress=zstd" ]; }; fileSystems."/boot" =