89 lines
2.3 KiB
Nix
89 lines
2.3 KiB
Nix
{ ... }:
|
|
{
|
|
flake.modules.nixos.controlstation =
|
|
{ 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/9a5d07a2-e1e7-4bb9-be0d-5e9c07231547 /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/E61F-4154";
|
|
fsType = "vfat";
|
|
options = [
|
|
"fmask=0077"
|
|
"dmask=0077"
|
|
];
|
|
};
|
|
|
|
"/" = {
|
|
device = "/dev/disk/by-uuid/9a5d07a2-e1e7-4bb9-be0d-5e9c07231547";
|
|
fsType = "btrfs";
|
|
options = [
|
|
"subvol=@root"
|
|
"compress=zstd"
|
|
"noatime"
|
|
];
|
|
};
|
|
|
|
"/nix" = {
|
|
device = "/dev/disk/by-uuid/9a5d07a2-e1e7-4bb9-be0d-5e9c07231547";
|
|
fsType = "btrfs";
|
|
options = [
|
|
"subvol=@nix-store"
|
|
"compress=zstd"
|
|
"noatime"
|
|
];
|
|
};
|
|
|
|
"/persist" = {
|
|
device = "/dev/disk/by-uuid/9a5d07a2-e1e7-4bb9-be0d-5e9c07231547";
|
|
fsType = "btrfs";
|
|
options = [
|
|
"subvol=@persist"
|
|
"compress=zstd"
|
|
"noatime"
|
|
];
|
|
neededForBoot = true;
|
|
};
|
|
|
|
"/home/aqua/Games" = {
|
|
device = "/dev/disk/by-uuid/d4ec18c9-83ad-410a-94e3-33a849a730c3";
|
|
fsType = "ext4";
|
|
};
|
|
};
|
|
};
|
|
}
|