[fugitive] Use btrfs subvolume as root-fs

Using a smaller server right now with less ram to spare
This commit is contained in:
ctsk
2024-09-23 18:24:20 +02:00
parent f750a38181
commit 86c58441f3

View File

@@ -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" =