Aquatic-Nix/modules/hosts/mainsrv/filesystems.nix

88 lines
2.3 KiB
Nix

{ ... }:
{
flake.modules.nixos.mainsrv =
{ pkgs, ... }:
{
boot.initrd.systemd.services.rollback = {
description = "Rollback BTRFS root to blank state";
wantedBy = [ "initrd.target" ];
after = [ "initrd-root-device.target" ];
requires = [ "initrd-root-device.target" ];
before = [ "sysroot.mount" ];
unitConfig.DefaultDependencies = "no";
serviceConfig.Type = "oneshot";
path = with pkgs; [
coreutils
util-linux
btrfs-progs
];
script = ''
mkdir -p /mnt
mount -o subvol=/ /dev/disk/by-uuid/258898a5-26f3-472f-80e5-bb25807bcfa1 /mnt
btrfs subvolume list -o /mnt/@root |
cut -f9 -d' ' |
while read subvolume; do
echo "deleting /$subvolume subvolume..."
btrfs subvolume delete "/mnt/$subvolume"
done &&
echo "deleting @root subvolume..." &&
btrfs subvolume delete /mnt/@root
echo "restoring blank @root subvolume..."
btrfs subvolume snapshot /mnt/@root-empty /mnt/@root
umount /mnt
'';
};
fileSystems = {
"/boot" = {
device = "/dev/disk/by-uuid/205D-27B6";
fsType = "vfat";
options = [
"fmask=0077"
"dmask=0077"
];
};
"/" = {
device = "/dev/disk/by-uuid/258898a5-26f3-472f-80e5-bb25807bcfa1";
fsType = "btrfs";
options = [
"subvol=@root"
"compress=zstd"
"noatime"
];
};
"/nix" = {
device = "/dev/disk/by-uuid/258898a5-26f3-472f-80e5-bb25807bcfa1";
fsType = "btrfs";
options = [
"subvol=@nix-store"
"compress=zstd"
"noatime"
];
};
"/persist" = {
device = "/dev/disk/by-uuid/258898a5-26f3-472f-80e5-bb25807bcfa1";
fsType = "btrfs";
options = [
"subvol=@persist"
"compress=zstd"
"noatime"
];
neededForBoot = true;
};
"/BACKUP" = {
device = "/dev/disk/by-uuid/6becef6f-82ef-4673-881d-710263ea7592";
fsType = "ext4";
};
};
};
}