2018-11-12 09:48:15 +00:00
|
|
|
{ stdenv, coreutils }:
|
2014-05-26 23:00:04 +00:00
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "libredirect-0";
|
|
|
|
|
2018-11-12 09:48:15 +00:00
|
|
|
unpackPhase = ''
|
|
|
|
cp ${./libredirect.c} libredirect.c
|
|
|
|
cp ${./test.c} test.c
|
|
|
|
'';
|
2014-05-26 23:00:04 +00:00
|
|
|
|
2018-11-12 08:59:39 +00:00
|
|
|
shlibext = stdenv.targetPlatform.extensions.sharedLibrary;
|
|
|
|
|
2018-11-11 18:29:12 +00:00
|
|
|
buildPhase = ''
|
2018-11-12 08:59:39 +00:00
|
|
|
$CC -Wall -std=c99 -O3 -shared libredirect.c \
|
|
|
|
-o "libredirect$shlibext" -fPIC -ldl
|
2018-11-12 09:48:15 +00:00
|
|
|
|
|
|
|
if [ -n "$doInstallCheck" ]; then
|
|
|
|
$CC -Wall -std=c99 -O3 test.c -o test
|
|
|
|
fi
|
2018-11-11 18:29:12 +00:00
|
|
|
'';
|
2014-05-26 23:00:04 +00:00
|
|
|
|
2018-11-12 08:59:39 +00:00
|
|
|
installPhase = ''
|
|
|
|
install -vD "libredirect$shlibext" "$out/lib/libredirect$shlibext"
|
|
|
|
'';
|
2016-08-02 16:06:29 +00:00
|
|
|
|
2018-11-12 09:48:15 +00:00
|
|
|
doInstallCheck = true;
|
|
|
|
|
|
|
|
installCheckPhase = if stdenv.isDarwin then ''
|
|
|
|
NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true" \
|
|
|
|
DYLD_INSERT_LIBRARIES="$out/lib/libredirect$shlibext" \
|
|
|
|
DYLD_FORCE_FLAT_NAMESPACE=1 ./test
|
|
|
|
'' else ''
|
|
|
|
NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true" \
|
|
|
|
LD_PRELOAD="$out/lib/libredirect$shlibext" ./test
|
|
|
|
'';
|
|
|
|
|
2016-08-02 16:06:29 +00:00
|
|
|
meta = {
|
2018-11-11 23:09:36 +00:00
|
|
|
platforms = stdenv.lib.platforms.unix;
|
2017-12-14 19:03:35 +00:00
|
|
|
description = "An LD_PRELOAD library to intercept and rewrite the paths in glibc calls";
|
|
|
|
longDescription = ''
|
|
|
|
libredirect is an LD_PRELOAD library to intercept and rewrite the paths in
|
|
|
|
glibc calls based on the value of $NIX_REDIRECTS, a colon-separated list
|
|
|
|
of path prefixes to be rewritten, e.g. "/src=/dst:/usr/=/nix/store/".
|
|
|
|
'';
|
2016-08-02 16:06:29 +00:00
|
|
|
};
|
2014-05-26 23:00:04 +00:00
|
|
|
}
|