mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-24 07:53:19 +00:00
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.
This commit is contained in:
parent
e62db105c4
commit
91c130e2f5
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user