#!/bin/sh PATH="@binPath@:$PATH" exec >&2 [ "${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