{ config, lib, pkgs, modulesPath, impermanence, ... }: { imports = [ (modulesPath + "/profiles/qemu-guest.nix") ]; boot.initrd.availableKernelModules = [ "ata_piix" "uhci_hcd" "virtio_pci" "sr_mod" "virtio_blk" ]; boot.initrd.kernelModules = [ ]; 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 = "/dev/disk/by-label/Nixos"; fsType = "btrfs"; options = [ "subvol=root" "compress=zstd" ]; }; fileSystems."/boot" = { device = "/dev/disk/by-label/Boot"; fsType = "vfat"; }; fileSystems."/nix" = { device = "/dev/disk/by-label/Nixos"; fsType = "btrfs"; options = [ "subvol=nix" "compress=zstd" ]; }; fileSystems."/persist" = { device = "/dev/disk/by-label/Nixos"; fsType = "btrfs"; neededForBoot = true; options = [ "subvol=persist" "compress=zstd" ]; }; environment.persistence."/persist" = { hideMounts = true; directories = [ "/etc/nixos" "/var/log" "/var/lib/acme" # Required to avoid excessive reissuing of certificate on reboots "/var/lib/prometheus2" "/var/lib/headscale" "/srv" ]; files = [ "/etc/machine-id" "/etc/ssh/ssh_host_ed25519_key" "/etc/ssh/ssh_host_ed25519_key.pub" "/etc/ssh/ssh_host_rsa_key" "/etc/ssh/ssh_host_rsa_key.pub" ]; }; swapDevices = [ { device = "/dev/disk/by-label/Swap"; } ]; # Enables DHCP on each ethernet and wireless interface. In case of scripted networking # (the default) this is the recommended approach. When using systemd-networkd it's # still possible to use this option, but it's recommended to use it in conjunction # with explicit per-interface declarations with `networking.interfaces..useDHCP`. networking.useDHCP = lib.mkDefault true; # networking.interfaces.ens3.useDHCP = lib.mkDefault true; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; }