Reorganize imports
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
41
hosts/common/configs/system/nix-cleanup/cleanup.sh
Normal file
41
hosts/common/configs/system/nix-cleanup/cleanup.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
if [[ "${EUID}" -ne 0 ]]; then
|
||||
echo "Please run the script as root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
delete_subvolume_recursively() {
|
||||
IFS=$'\n'
|
||||
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
|
||||
delete_subvolume_recursively "/mnt/btrfs/${i}"
|
||||
done
|
||||
btrfs subvolume delete "$1"
|
||||
}
|
||||
|
||||
if [[ -e /mnt/btrfs && -n $(mountpoint -q /mnt/btrfs) ]]; then
|
||||
echo "/mnt/btrfs is already mounted. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$DEVICE" ]]; then
|
||||
echo "Error: DEVICE variable is not set."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p /mnt/btrfs
|
||||
mount "/dev/mapper/$DEVICE" /mnt/btrfs
|
||||
|
||||
if [[ -e /mnt/btrfs/@.bak ]]; then
|
||||
if [[ -n "$(ls -A /mnt/btrfs/@.bak)" ]]; then
|
||||
for i in /mnt/btrfs/@.bak/*; do
|
||||
delete_subvolume_recursively "${i}"
|
||||
done
|
||||
else
|
||||
echo "/mnt/btrfs/@.bak is empty. Nothing to delete."
|
||||
fi
|
||||
fi
|
||||
|
||||
umount /mnt/btrfs
|
||||
rmdir /mnt/btrfs
|
||||
|
||||
nix-collect-garbage -d
|
||||
nix-store --gc -v
|
17
hosts/common/configs/system/nix-cleanup/default.nix
Normal file
17
hosts/common/configs/system/nix-cleanup/default.nix
Normal file
@@ -0,0 +1,17 @@
|
||||
{ config, pkgs, ... }:
|
||||
{
|
||||
environment.systemPackages = [
|
||||
(pkgs.writeShellApplication {
|
||||
name = "nix-cleanup";
|
||||
runtimeInputs = with pkgs; [
|
||||
coreutils
|
||||
util-linux
|
||||
findutils
|
||||
btrfs-progs
|
||||
nix
|
||||
];
|
||||
runtimeEnv.DEVICE = config.environment.impermanence.device;
|
||||
text = builtins.readFile ./cleanup.sh;
|
||||
})
|
||||
];
|
||||
}
|
Reference in New Issue
Block a user