diff --git a/default.nix b/default.nix index 2a76b41..bba9b64 100644 --- a/default.nix +++ b/default.nix @@ -1,4 +1,4 @@ -{ stdenv, jq }: +{ stdenv, findutils, jq }: stdenv.mkDerivation { name = "nixredo-1"; @@ -8,6 +8,7 @@ stdenv.mkDerivation { libnix = ./lib.nix; files = [ ./nixredo ./nixredo-deps ./nixredo-whichdo ./nixredo-gc ]; + find = "${findutils}/bin/find"; installPhase = '' mkdir -p $out/bin diff --git a/nixredo-gc b/nixredo-gc index f721d8f..c0cf747 100644 --- a/nixredo-gc +++ b/nixredo-gc @@ -1,3 +1,24 @@ #!/bin/sh +[ "${S+x}" = x ] || { printf "Set S to the root location of your source tree\n"; exit 127; } [ "${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 /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 + nix-store --store "${NIXREDO_ROOT}" --gc +rm -rf -- "${NIXREDO_ROOT}/tmp" + +for f in $roots; do + rm -- "$f" +done