impermanence

This commit is contained in:
randogoth 2026-02-10 09:25:12 +02:00
parent 9205ec2d23
commit 1795a4a275
4 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,46 @@
{ 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"
];
};
};
}