test: impermanence

This commit is contained in:
Nick 2025-11-05 00:04:49 -06:00
parent 4210004147
commit 270275e225

View file

@ -12,35 +12,24 @@ in
"/" = { "/" = {
device = "/dev/disk/by-label/root"; device = "/dev/disk/by-label/root";
fsType = "btrfs"; fsType = "btrfs";
options = [ options = [ "subvol=root" ];
"subvol=@"
"compress=zstd"
"noatime"
];
}; };
"/nix" = { "/nix" = {
device = "/dev/disk/by-label/root"; device = "/dev/disk/by-label/root";
fsType = "btrfs"; fsType = "btrfs";
options = [ options = [ "subvol=nix" ];
"subvol=@nix"
];
}; };
"/persistent" = { "/persistent" = {
device = "/dev/disk/by-label/root"; device = "/dev/disk/by-label/root";
fsType = "btrfs"; fsType = "btrfs";
neededForBoot = true; neededForBoot = true;
options = [ options = [ "subvol=persistent" ];
"subvol=@persistent"
];
}; };
"/boot" = { "/boot" = {
device = "/dev/disk/by-label/BOOT"; device = "/dev/disk/by-label/BOOT";
fsType = "vfat"; fsType = "vfat";
options = [ "umask=0077" ];
}; };
"/mnt/storage" = { "/mnt/storage" = {
device = "/dev/disk/by-label/storage"; device = "/dev/disk/by-label/storage";
fsType = "ext4"; fsType = "ext4";
@ -49,12 +38,12 @@ in
boot.initrd.postResumeCommands = lib.mkAfter '' boot.initrd.postResumeCommands = lib.mkAfter ''
mkdir -p /btrfs_tmp mkdir -p /btrfs_tmp
mount -o subvol=/ /dev/disk/by-label/root /btrfs_tmp mount -o subvolid=5 /dev/disk/by-label/root /btrfs_tmp
if [[ -e /btrfs_tmp/@ ]]; then if [[ -e /btrfs_tmp/root ]]; then
mkdir -p /btrfs_tmp/@old_roots mkdir -p /btrfs_tmp/old_roots
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/@)" "+%Y-%m-%d_%H:%M:%S") timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%d_%H:%M:%S")
mv /btrfs_tmp/@ "/btrfs_tmp/@old_roots/$timestamp" mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp"
fi fi
delete_subvolume_recursively() { delete_subvolume_recursively() {
@ -65,29 +54,35 @@ in
btrfs subvolume delete "$1" btrfs subvolume delete "$1"
} }
for i in $(find /btrfs_tmp/@old_roots/ -maxdepth 1 -mtime +30); do for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do
delete_subvolume_recursively "$i" delete_subvolume_recursively "$i"
done done
btrfs subvolume create /btrfs_tmp/@ btrfs subvolume create /btrfs_tmp/root
umount /btrfs_tmp umount /btrfs_tmp
''; '';
environment.persistence."/persistent" = { environment.persistence."/persistent" = {
hideMounts = true;
directories = [ directories = [
"/var/log"
"/var/lib/nixos"
"/var/lib/systemd/coredump"
"/var/cache" "/var/cache"
"/etc/ssh" "/var/lib"
]; {
files = [ directory = "/etc/ssh";
"/etc/machine-id" mode = "u=rwx,g=rx,o=rx";
user = "root";
}
]; ];
hideMounts = true;
users.${user0} = { users.${user0} = {
directories = [ directories = [
".ssh" ".cache"
".config"
".local/share/direnv"
".local/state/nix"
{
directory = ".ssh";
mode = "u=rwx,g=,o=";
}
]; ];
}; };
}; };