47 lines
1 KiB
Nix
47 lines
1 KiB
Nix
|
|
{ config, lib, ... }:
|
||
|
|
|
||
|
|
{
|
||
|
|
config = lib.mkIf (
|
||
|
|
(config.fileSystems ? "/persist")
|
||
|
|
&& (config.fileSystems."/persist".fsType or "" == "btrfs")
|
||
|
|
) {
|
||
|
|
boot.initrd.supportedFilesystems = [ "btrfs" ];
|
||
|
|
|
||
|
|
boot.initrd.postDeviceCommands = lib.mkAfter ''
|
||
|
|
mkdir -p /mnt
|
||
|
|
mount -t btrfs -o subvol=/ /dev/disk/by-label/nixos /mnt
|
||
|
|
|
||
|
|
if [ ! -d /mnt/root-blank ]; then
|
||
|
|
btrfs subvolume snapshot -r /mnt/root /mnt/root-blank
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [ -d /mnt/root ]; then
|
||
|
|
btrfs subvolume delete /mnt/root
|
||
|
|
fi
|
||
|
|
|
||
|
|
btrfs subvolume snapshot /mnt/root-blank /mnt/root
|
||
|
|
umount /mnt
|
||
|
|
'';
|
||
|
|
|
||
|
|
fileSystems."/persist".neededForBoot = true;
|
||
|
|
|
||
|
|
environment.persistence."/persist" = {
|
||
|
|
hideMounts = true;
|
||
|
|
directories = [
|
||
|
|
"/etc/nixos"
|
||
|
|
"/etc/ssh"
|
||
|
|
"/etc/cups"
|
||
|
|
"/var/lib/cups"
|
||
|
|
"/var/lib/libvirt"
|
||
|
|
"/var/lib/secureboot"
|
||
|
|
"/var/lib/tailscale"
|
||
|
|
"/var/lib/systemd"
|
||
|
|
"/var/lib/nixos"
|
||
|
|
];
|
||
|
|
files = [
|
||
|
|
"/etc/machine-id"
|
||
|
|
];
|
||
|
|
};
|
||
|
|
};
|
||
|
|
}
|