[fugitive] Use btrfs subvolume as root-fs
Using a smaller server right now with less ram to spare
This commit is contained in:
@@ -11,11 +11,44 @@
|
|||||||
boot.kernelModules = [ ];
|
boot.kernelModules = [ ];
|
||||||
boot.extraModulePackages = [ ];
|
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."/" =
|
fileSystems."/" =
|
||||||
{
|
{
|
||||||
device = "none";
|
device = "/dev/disk/by-label/Nixos";
|
||||||
fsType = "tmpfs";
|
fsType = "btrfs";
|
||||||
options = [ "size=2G" "mode=755" ];
|
options = [ "subvol=root" "compress=zstd" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
fileSystems."/boot" =
|
fileSystems."/boot" =
|
||||||
|
|||||||
Reference in New Issue
Block a user