2021-02-14 23:40:26 +01:00
|
|
|
#!/bin/sh
|
|
|
|
exec >&2
|
2021-02-16 13:17:01 +01:00
|
|
|
[ "${NIXREDO_ROOT-x}" != x ] || { printf "Set NIXREDO_ROOT. Set empty to use global nix store\n"; exit 127; }
|
2021-02-14 23:40:26 +01:00
|
|
|
if [ $# -eq 0 ]; then set -- all; fi
|
2021-02-16 20:32:15 +01:00
|
|
|
set -e
|
|
|
|
set -- "$1" "$1" "$1.redo.tmp"
|
|
|
|
f=$(realpath -s "$1")
|
|
|
|
out=$(nix -vL --show-trace build ${NIXREDO_ROOT:+--store "$NIXREDO_ROOT"} \
|
|
|
|
--option auto-optimise-store true --option substituters daemon \
|
|
|
|
--impure --json --no-link \
|
|
|
|
--expr " import @buildernix@ { lib = import @libnix@ {}; } \"$f\"" |
|
|
|
|
@jq@ -r '.[0].outputs.out')
|
|
|
|
[ -n "$out" ] || exit 127
|
|
|
|
rm -rf "$3"
|
|
|
|
ln -s "${NIXREDO_ROOT+$NIXREDO_ROOT}$out" "$3"
|
|
|
|
# ln "${NIXREDO_ROOT+$NIXREDO_ROOT/}$out" "$3"
|
|
|
|
# chmod +w "$3"
|
|
|
|
# touch "$3"
|
|
|
|
mv "$3" "$1"
|