{ pkgs, lib, ... }: { boot.initrd.postDeviceCommands = lib.mkAfter '' mkdir /btrfs_tmp mount /dev/root_vg/root /btrfs_tmp delete_subvolume_recursively() { IFS=$'\n' for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do delete_subvolume_recursively "/btrfs_tmp/$i" done btrfs subvolume delete "$1" } delete_subvolume_recursively "/btrfs_tmp/root" btrfs subvolume create /btrfs_tmp/root umount /btrfs_tmp ''; fileSystems."/persist".neededForBoot = true; environment.persistence."/persist/system" = { hideMounts = true; directories = [ "/var/log" "/var/lib/bluetooth" "/var/lib/nixos" "/var/lib/libvirt" "/var/lib/systemd/coredump" "/etc/NetworkManager/system-connections" "/var/lib/docker" ]; files = [ "/etc/machine-id" { file = "/var/keys/secret_file"; parentDirectory = { mode = "u=rwx,g=,o="; }; } ]; }; }