From 1990b8b5b24643d7c8c9313fbab169abcb98d26d Mon Sep 17 00:00:00 2001 From: Florian Peter <4farlion@gmail.com> Date: Mon, 21 Apr 2025 19:59:58 +0100 Subject: [PATCH] feat(gc): add guardrails against wiping everything accidentally See https://github.com/nix-community/impermanence/issues/258#issuecomment-2733383737 --- final/configuration.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/final/configuration.nix b/final/configuration.nix index 3248d68..0bfe35d 100644 --- a/final/configuration.nix +++ b/final/configuration.nix @@ -30,6 +30,13 @@ delete_subvolume_recursively() { IFS=$'\n' + + # If we accidentally end up with a file or directory under old_roots, + # the code will enumerate all subvolumes under the main volume. + # We don't want to remove everything under true main volume. Only + # proceed if this path is a btrfs subvolume (inode=256). + if [ $(stat -c %i "$1") -ne 256 ]; then return; fi + for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do delete_subvolume_recursively "/btrfs_tmp/$i" done