65 lines
1.9 KiB
Nix
65 lines
1.9 KiB
Nix
{ modulesPath, pkgs, ... }:
|
|
{
|
|
|
|
imports =
|
|
[
|
|
(modulesPath + "/installer/scan/not-detected.nix")
|
|
];
|
|
|
|
boot = {
|
|
initrd = {
|
|
availableKernelModules = [ "xhci_pci" "ahci" "nvme" "uas" "sd_mod" ];
|
|
kernelModules = [ ];
|
|
systemd = {
|
|
enable = true;
|
|
initrdBin = [ pkgs.libuuid pkgs.gawk ];
|
|
services.rollback = {
|
|
description = "Rollback btrfs root subvolume";
|
|
wantedBy = [ "initrd.target" ];
|
|
before = [ "sysroot.mount" ];
|
|
after = [ "initrd-root-device.target" ];
|
|
unitConfig.DefaultDependencies = "no";
|
|
serviceConfig.Type = "oneshot";
|
|
script = ''
|
|
mkdir -p /mnt
|
|
DISK_LABEL="NixOS-Primary"
|
|
ATTEMPTS=5
|
|
printf "Attempting to find disk with label '%s'\n" "$DISK_LABEL"
|
|
while ((ATTEMPTS > 0)); do
|
|
if findfs LABEL="$DISK_LABEL"; then
|
|
printf "Found disk!\n"
|
|
break;
|
|
fi
|
|
((ATTEMPTS--))
|
|
sleep 3
|
|
printf "Remaining disk discovery attempts: %s\n" "$ATTEMPTS"
|
|
done
|
|
mount -t btrfs -o subvol=/ $(findfs LABEL="$DISK_LABEL") /mnt
|
|
btrfs subvolume list -to /mnt/root \
|
|
| awk 'NR>2 { printf $4"\n" }' \
|
|
| while read subvol; do
|
|
printf "Removing Subvolume: %s\n" "$subvol";
|
|
btrfs subvolume delete "/mnt/$subvol"
|
|
done
|
|
|
|
printf "Removing /root subvolume\n"
|
|
btrfs subvolume delete /mnt/root
|
|
|
|
printf "Restoring base /root subvolume\n"
|
|
btrfs subvolume snapshot /mnt/root-base /mnt/root
|
|
|
|
umount /mnt
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
loader = {
|
|
systemd-boot.enable = true;
|
|
efi.canTouchEfiVariables = true;
|
|
};
|
|
kernelModules = [ "kvm-intel" ];
|
|
extraModulePackages = [ ];
|
|
};
|
|
|
|
}
|