summary refs log tree commit diff
diff options
context:
space:
mode:
authorzimbatm <zimbatm@zimbatm.com>2018-11-13 12:35:10 +0100
committerzimbatm <zimbatm@zimbatm.com>2018-11-14 00:05:23 +0100
commit91c130e2f5d6702e195dd6c25abafc5f16b7e505 (patch)
tree79a7c8b1124a58c86c6dc6679a570ebcc1f3b7ed
parente62db105c4bc1837cff46702d760c3e04403b6b5 (diff)
downloadnixpkgs-91c130e2f5d6702e195dd6c25abafc5f16b7e505.tar
nixpkgs-91c130e2f5d6702e195dd6c25abafc5f16b7e505.tar.gz
nixpkgs-91c130e2f5d6702e195dd6c25abafc5f16b7e505.tar.bz2
nixpkgs-91c130e2f5d6702e195dd6c25abafc5f16b7e505.tar.lz
nixpkgs-91c130e2f5d6702e195dd6c25abafc5f16b7e505.tar.xz
nixpkgs-91c130e2f5d6702e195dd6c25abafc5f16b7e505.tar.zst
nixpkgs-91c130e2f5d6702e195dd6c25abafc5f16b7e505.zip
libredirect: introduce optional setup-hook
This allows to simplify the usage of libredirect inside of nix build
sandboxes. Add "libredirect.hook" to the build inputs to get everything
linked in automaticall. All that's left is to set NIX_REDIRECTS and call
the target program.
-rw-r--r--pkgs/build-support/libredirect/default.nix24
1 files changed, 17 insertions, 7 deletions
diff --git a/pkgs/build-support/libredirect/default.nix b/pkgs/build-support/libredirect/default.nix
index e92945a4030..7caca2fc003 100644
--- a/pkgs/build-support/libredirect/default.nix
+++ b/pkgs/build-support/libredirect/default.nix
@@ -10,6 +10,8 @@ stdenv.mkDerivation {
 
   libName = "libredirect" + stdenv.targetPlatform.extensions.sharedLibrary;
 
+  outputs = ["out" "hook"];
+
   buildPhase = ''
     $CC -Wall -std=c99 -O3 -shared libredirect.c \
       -o "$libName" -fPIC -ldl
@@ -21,17 +23,25 @@ stdenv.mkDerivation {
 
   installPhase = ''
     install -vD "$libName" "$out/lib/$libName"
+
+    mkdir -p "$hook/nix-support"
+    cat <<SETUP_HOOK > "$hook/nix-support/setup-hook"
+    ${if stdenv.isDarwin then ''
+    export DYLD_INSERT_LIBRARIES="$out/lib/$libName"
+    export DYLD_FORCE_FLAT_NAMESPACE=1
+    '' else ''
+    export LD_PRELOAD="$out/lib/$libName"
+    ''}
+    SETUP_HOOK
   '';
 
   doInstallCheck = true;
 
-  installCheckPhase = if stdenv.isDarwin then ''
-    NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true" \
-    DYLD_INSERT_LIBRARIES="$out/lib/$libName" \
-    DYLD_FORCE_FLAT_NAMESPACE=1 ./test
-  '' else ''
-    NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true" \
-    LD_PRELOAD="$out/lib/$libName" ./test
+  installCheckPhase = ''
+    (
+      source "$hook/nix-support/setup-hook"
+      NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true" ./test
+    )
   '';
 
   meta = {