From 396d094520ba5e9d14af7326605464cd644fe265 Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 4 Apr 2023 23:20:54 +0000 Subject: [PATCH] sane-scripts: sane-reclaim-disk-space: use nix-store --optimise --- pkgs/sane-scripts/src/sane-reclaim-disk-space | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/pkgs/sane-scripts/src/sane-reclaim-disk-space b/pkgs/sane-scripts/src/sane-reclaim-disk-space index 9857e41a..78f96bde 100755 --- a/pkgs/sane-scripts/src/sane-reclaim-disk-space +++ b/pkgs/sane-scripts/src/sane-reclaim-disk-space @@ -1,23 +1,52 @@ #!/usr/bin/env bash # script to reclaim some hard drive space +# some of this is documented here: +# - set -e -options=$(getopt -l "fast" -o "f" -- "$@") -do_rmlint=true -for arg in $options; do - case $arg in - -f|--fast) - do_rmlint=false - ;; - --) - ;; +options=$(getopt -l "gc,rmlint,all" -- "" "$@") +eval "set -- ${options}" +do_rmlint=false +do_gc=false +while true; do + 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 done set -x -# always claim nix garbage -sudo nix-collect-garbage +# scan the store and hard-link identical files +# 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 ] then