1
0
Fork 0
nixredo/nixredo-gc

25 lines
895 B
Plaintext
Raw Normal View History

2021-02-17 10:44:08 +01:00
#!/bin/sh
[ "${S+x}" = x ] || { printf "Set S to the root location of your source tree\n"; exit 127; }
2021-02-17 10:44:08 +01:00
[ "${NIXREDO_ROOT+x}" = x ] || { printf "$0 only runs for private a nix store. Set NIXREDO_ROOT to a non-empty value\n"; exit 127; }
# Work around broken GCROOT support in local stores
# Add a fake gcroot which points to /nix/store/... instead of <local/store>/nix/store
# Remove fake roots after gc
roots=
mkdir -p "${NIXREDO_ROOT}/nix/var/nix/gcroots/auto"
for f in $(@find@ "$S" -path "${NIXREDO_ROOT}" -prune -o -type l -print) ; do
p=$(realpath "$f")
if [ "${p#${NIXREDO_ROOT}}" != "$p" ]; then
gcroot=$(mktemp -u -p "${NIXREDO_ROOT}/nix/var/nix/gcroots/auto")
ln -s "${p#${NIXREDO_ROOT}}" "$gcroot"
roots="${roots} ${gcroot}"
fi
done
2021-02-17 10:44:08 +01:00
nix-store --store "${NIXREDO_ROOT}" --gc
rm -rf -- "${NIXREDO_ROOT}/tmp"
for f in $roots; do
rm -- "$f"
done