Browse Source

Properly wrap scripts with runtime binaries

master
Michael Raitza 7 months ago
parent
commit
5e28e35f94
  1. 9
      default.nix
  2. 3
      nixredo
  3. 1
      nixredo-deps
  4. 5
      nixredo-gc
  5. 2
      nixredo-whichdo

9
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

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

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

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

2
nixredo-whichdo

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