1
0
Fork 0
nixredo/nixredo

36 lines
1.2 KiB
Bash

#!/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 "Set NIXREDO_ROOT. Set empty to use global nix store\n"; exit 127; }
if [ $# -eq 0 ]; then set -- all; fi
if [ -n "${NIXREDO_ROOT}" ]; then
export TMPDIR="${NIXREDO_ROOT}/tmp"
mkdir -p "$TMPDIR"
fi
S=$(realpath -s "$S")
if [ "${NIXREDO_ROOT#$S}" != "${NIXREDO_ROOT}" ]; then
filter=$(realpath -s "${NIXREDO_ROOT}")
else
filter=
fi
set -e
set -- "$1" "$1" "$1.redo.tmp"
f=$(realpath -s "$1")
rm -f -- "$3"
# Work around broken local store support. out-links are not correctly resolved.
# We solve gcroots in nixredo-gc
out=$(nix -vL --show-trace build ${NIXREDO_ROOT:+--store "$NIXREDO_ROOT"} \
--option auto-optimise-store true --option substituters daemon \
--option keep-failed true --option keep-outputs true \
--impure --json --no-link \
--expr " import @buildernix@ { lib = import @libnix@ {}; root =\"$S\"; filter = [ \"$filter\" \"$f\" ]; } \"$f\"" |
jq -r '.[0].outputs.out')
[ -n "$out" ] || exit 127
ln -s "${NIXREDO_ROOT+$NIXREDO_ROOT}$out" "$3"
mv "$3" "$1"