1
0
Fork 0

Properly wrap scripts with runtime binaries

master
Michael Raitza 2021-02-19 20:06:28 +01:00
parent 82e3cf72dc
commit 5e28e35f94
5 changed files with 14 additions and 6 deletions

View File

@ -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

View File

@ -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"

View File

@ -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; }

View File

@ -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")

View File

@ -1,3 +1,5 @@
#!/bin/sh
PATH="@binPath@:$PATH"
f=$(realpath -s "$1")
nix eval --impure --expr "with import @libnix@ {}; /. + (whichdo \"$f\")"