sane-scripts: sane-reclaim-disk-space: use nix-store --optimise

This commit is contained in:
Colin 2023-04-04 23:20:54 +00:00
parent ad819e4cc0
commit ddf1be7410

View File

@ -1,23 +1,52 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# script to reclaim some hard drive space # script to reclaim some hard drive space
# some of this is documented here:
# - <https://nixos.wiki/wiki/Storage_optimization>
set -e set -e
options=$(getopt -l "fast" -o "f" -- "$@") options=$(getopt -l "gc,rmlint,all" -- "" "$@")
do_rmlint=true eval "set -- ${options}"
for arg in $options; do do_rmlint=false
case $arg in do_gc=false
-f|--fast) while true; do
do_rmlint=false case "$1" in
;; (--all)
--) shift
;; do_gc=true
do_rmlint=true
;;
(--gc)
shift
do_gc=true
;;
(--rmlint)
shift
do_rmlint=true
;;
(--)
shift
if [ $# -eq 0 ]; then
break
fi
;;
(*)
echo "invalid arguments"
exit 1
;;
esac esac
done done
set -x set -x
# always claim nix garbage # scan the store and hard-link identical files
sudo nix-collect-garbage # nix-store --optimise
if [ $do_gc = true ]
then
# TODO: do we need `sudo` here?
# TODO: `nix-store --gc`?
sudo nix-collect-garbage
fi
if [ $do_rmlint = true ] if [ $do_rmlint = true ]
then then