garbage-collect now properly displays space freed up from clearing trash can, also optimises the nix store as well
This commit is contained in:
@@ -7,15 +7,9 @@
|
|||||||
system.stateVersion = "25.05";
|
system.stateVersion = "25.05";
|
||||||
nix = {
|
nix = {
|
||||||
settings = {
|
settings = {
|
||||||
auto-optimise-store = true;
|
|
||||||
experimental-features = [ "nix-command" "flakes" ];
|
experimental-features = [ "nix-command" "flakes" ];
|
||||||
substituters = [ "https://nix-gaming.cachix.org" ];
|
substituters = [ "https://nix-gaming.cachix.org" ];
|
||||||
};
|
};
|
||||||
gc = {
|
|
||||||
automatic = true;
|
|
||||||
dates = "weekly";
|
|
||||||
options = "--delete-older-than 7d";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
time.timeZone = "America/New_York";
|
time.timeZone = "America/New_York";
|
||||||
i18n.defaultLocale = "en_US.UTF-8";
|
i18n.defaultLocale = "en_US.UTF-8";
|
||||||
|
|||||||
@@ -11,7 +11,16 @@ pkgs.writeShellApplication {
|
|||||||
nix
|
nix
|
||||||
];
|
];
|
||||||
text = ''
|
text = ''
|
||||||
#!/run/current-system/sw/bin/bash
|
convert_size() {
|
||||||
|
units=("MB" "GB" "TB" "PB")
|
||||||
|
size=$1
|
||||||
|
divisions=0
|
||||||
|
while [ "$(echo "$size >= 1024.0" | bc -l)" -eq 1 ]; do
|
||||||
|
size=$(echo "scale=2; $size / 1024" | bc -l)
|
||||||
|
divisions=$((divisions + 1))
|
||||||
|
done
|
||||||
|
echo -e "\033[1;4;38;2;166;227;161m$size ''${units[divisions]}\033[0m"
|
||||||
|
}
|
||||||
|
|
||||||
echo "This will delete all unused paths in the nix store and delete any files in the gtrash folder."
|
echo "This will delete all unused paths in the nix store and delete any files in the gtrash folder."
|
||||||
echo -e "\033[1;4;38;2;243;139;168mThis process is irreversible.\033[0m Are you sure?"
|
echo -e "\033[1;4;38;2;243;139;168mThis process is irreversible.\033[0m Are you sure?"
|
||||||
@@ -25,25 +34,28 @@ pkgs.writeShellApplication {
|
|||||||
output=$(nix-collect-garbage | tee /dev/tty)
|
output=$(nix-collect-garbage | tee /dev/tty)
|
||||||
nix_freed=$(echo "$output" | grep -oP '\d+(\.\d+)? MiB freed' | cut -d' ' -f1)
|
nix_freed=$(echo "$output" | grep -oP '\d+(\.\d+)? MiB freed' | cut -d' ' -f1)
|
||||||
|
|
||||||
|
echo "Done, nix-collect-garbage freed up $(convert_size "$nix_freed")"
|
||||||
|
|
||||||
# Get the size of the trash folder before deleting
|
# Get the size of the trash folder before deleting
|
||||||
if [ "$(ls -A ~/.local/share/Trash/files/ 2>/dev/null)" ]; then
|
if [ "$(find ~/.local/share/Trash/files/ 2>/dev/null)" ]; then
|
||||||
|
echo "Deleting trash files..."
|
||||||
|
echo "Found $(find ~/.local/share/Trash/files/ | wc -l) files in trash can."
|
||||||
rm_freed=$(du -sm ~/.local/share/Trash/files | awk '{print $1}')
|
rm_freed=$(du -sm ~/.local/share/Trash/files | awk '{print $1}')
|
||||||
/run/current-system/sw/bin/rm -rf ~/.local/share/Trash/files/*
|
sudo /run/current-system/sw/bin/rm -rf ~/.local/share/Trash/files
|
||||||
mkdir -p ~/.local/share/Trash/files
|
mkdir -p ~/.local/share/Trash/files
|
||||||
|
echo "Done, deleting trash freed up $(convert_size "$rm_freed")"
|
||||||
else
|
else
|
||||||
rm_freed="0"
|
rm_freed="0"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
total_freed=$(echo "$nix_freed + $rm_freed" | bc)
|
total_freed=$(echo "$nix_freed + $rm_freed" | bc)
|
||||||
|
total_converted=$(convert_size "$total_freed")
|
||||||
|
|
||||||
units=("MB" "GB" "TB" "PB")
|
echo "Optimizing nix store..."
|
||||||
divisions=0
|
nix store optimise
|
||||||
while [ "$(echo "$total_freed >= 1024.0" | bc -l)" -eq 1 ]; do
|
|
||||||
total_freed=$(echo "scale=2; $total_freed / 1024" | bc -l)
|
echo -e "System cleaning complete, freed \033[1;4;38;2;166;227;161m$total_converted\033[0m in total"
|
||||||
divisions=$((divisions + 1))
|
|
||||||
done
|
|
||||||
|
|
||||||
echo -e "System cleaning complete, freed \033[1;4;38;2;166;227;161m$total_freed ''${units[$divisions]}\033[0m in total"
|
|
||||||
|
|
||||||
scheck && runbg aplay "$HOME/assets/sound/sys/rm.wav"
|
scheck && runbg aplay "$HOME/assets/sound/sys/rm.wav"
|
||||||
'';
|
'';
|
||||||
|
|||||||
Reference in New Issue
Block a user