From 487dfd337875866f8819f12dd7e1c1f4c37873a0 Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 29 Sep 2022 17:54:45 -0700 Subject: [PATCH] sane-reclaim-disk-space: add `--fast` flag to skip rmlint check --- pkgs/sane-scripts/default.nix | 1 + pkgs/sane-scripts/src/sane-reclaim-disk-space | 46 ++++++++++++++----- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/pkgs/sane-scripts/default.nix b/pkgs/sane-scripts/default.nix index 5e6bb57b..81968689 100644 --- a/pkgs/sane-scripts/default.nix +++ b/pkgs/sane-scripts/default.nix @@ -33,6 +33,7 @@ resholve.mkDerivation { ssh-to-age sops sudo + util-linux which ]; keep = { diff --git a/pkgs/sane-scripts/src/sane-reclaim-disk-space b/pkgs/sane-scripts/src/sane-reclaim-disk-space index 74300d33..9857e41a 100755 --- a/pkgs/sane-scripts/src/sane-reclaim-disk-space +++ b/pkgs/sane-scripts/src/sane-reclaim-disk-space @@ -1,17 +1,41 @@ #!/usr/bin/env bash -set -ex # script to reclaim some hard drive space +set -e + +options=$(getopt -l "fast" -o "f" -- "$@") +do_rmlint=true +for arg in $options; do + case $arg in + -f|--fast) + do_rmlint=false + ;; + --) + ;; + esac +done + +set -x + +# always claim nix garbage sudo nix-collect-garbage -# identify duplicate files in the nix store -rmlint --types="duplicates" --config=sh:handler=clone --output=sh:/tmp/rmlint.sh --output=json:/dev/null --progress /nix/store -# link the dupes together (uses ioctl_fideduperange) -# see: https://btrfs.wiki.kernel.org/index.php/Deduplication -# see: https://rmlint.readthedocs.io/en/latest/tutorial.html -sudo mount -o remount,rw /nix/store -# XXX: does rmlint really need to be invoked as root? -sudo /tmp/rmlint.sh -d || true # on failure, we still want to remount ro -# XXX this doesn't work: 'mount point is busy.' -sudo mount -o remount,ro /nix/store + +if [ $do_rmlint = true ] +then + # identify duplicate files in the nix store + rmlint --types="duplicates" --config=sh:handler=clone --output=sh:/tmp/rmlint.sh --output=json:/dev/null --progress /nix/store + # link the dupes together (uses ioctl_fideduperange) + # see: https://btrfs.wiki.kernel.org/index.php/Deduplication + # see: https://rmlint.readthedocs.io/en/latest/tutorial.html +fi + +if [ $do_rmlint = true ] +then + sudo mount -o remount,rw /nix/store + # XXX: does rmlint really need to be invoked as root? + sudo /tmp/rmlint.sh -d || true # on failure, we still want to remount ro + # XXX this doesn't work: 'mount point is busy.' + sudo mount -o remount,ro /nix/store +fi # TODO: instead of using rmlint, could use dduper: https://github.com/Lakshmipathi/dduper # better perf for btrfs (checksum tests)