diff --git a/hardware/filesystem.nix b/hardware/filesystem.nix index 1ab6a3a..dbb2ed4 100644 --- a/hardware/filesystem.nix +++ b/hardware/filesystem.nix @@ -9,8 +9,11 @@ in boot.initrd.postDeviceCommands = lib.mkAfter '' mkdir /btrfs_tmp mount ${rootDisk} /btrfs_tmp + + # Ensure the old_roots directory exists + mkdir -p /btrfs_tmp/old_roots + if [[ -e /btrfs_tmp/root ]]; then - mkdir -p /btrfs_tmp/old_roots timestamp=$(date +%Y-%m-%d_%H-%M-%S) mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp" fi @@ -24,6 +27,8 @@ in } for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +7); do + # Don't delete the old_roots directory itself + if [[ "$i" == "/btrfs_tmp/old_roots/" ]]; then continue; fi delete_subvolume_recursively "$i" done