diff --git a/default.nix b/default.nix index bba9b64..5ed732f 100644 --- a/default.nix +++ b/default.nix @@ -1,14 +1,15 @@ -{ stdenv, findutils, jq }: +{ stdenv, lib, findutils, jq, nixUnstable, coreutils }: stdenv.mkDerivation { - name = "nixredo-1"; + pname = "nixredo"; + version = "1"; phases = [ "installPhase" "fixupPhase" ]; - jq = "${jq}/bin/jq"; + + binPath = lib.makeBinPath [ findutils coreutils jq nixUnstable ]; buildernix = ./builder.nix; libnix = ./lib.nix; files = [ ./nixredo ./nixredo-deps ./nixredo-whichdo ./nixredo-gc ]; - find = "${findutils}/bin/find"; installPhase = '' mkdir -p $out/bin diff --git a/nixredo b/nixredo index af025bf..79754d3 100644 --- a/nixredo +++ b/nixredo @@ -1,4 +1,5 @@ #!/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; } @@ -28,7 +29,7 @@ out=$(nix -vL --show-trace build ${NIXREDO_ROOT:+--store "$NIXREDO_ROOT"} \ --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') + jq -r '.[0].outputs.out') [ -n "$out" ] || exit 127 ln -s "${NIXREDO_ROOT+$NIXREDO_ROOT}$out" "$3" mv "$3" "$1" diff --git a/nixredo-deps b/nixredo-deps index 622bc45..9a115d8 100644 --- a/nixredo-deps +++ b/nixredo-deps @@ -1,4 +1,5 @@ #!/bin/sh +PATH="@binPath@:$PATH" exec >&2 [ "${NIXREDO_ROOT-x}" != x ] || { printf "Set NIXREDO_ROOT. Set empty to use global nix store\n"; exit 127; } diff --git a/nixredo-gc b/nixredo-gc index c0cf747..b62bcd1 100644 --- a/nixredo-gc +++ b/nixredo-gc @@ -1,4 +1,7 @@ #!/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; } @@ -7,7 +10,7 @@ # 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 +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") diff --git a/nixredo-whichdo b/nixredo-whichdo index a702d56..3ad9dfa 100644 --- a/nixredo-whichdo +++ b/nixredo-whichdo @@ -1,3 +1,5 @@ #!/bin/sh +PATH="@binPath@:$PATH" + f=$(realpath -s "$1") nix eval --impure --expr "with import @libnix@ {}; /. + (whichdo \"$f\")"