Skip to content

Commit

Permalink
Merge pull request NixOS#30150 from copumpkin/no-rpath-nonsense
Browse files Browse the repository at this point in the history
Get rid of most @rpath nonsense on Darwin
  • Loading branch information
copumpkin authored Oct 8, 2017
2 parents d32f7f4 + b426c85 commit 416979f
Show file tree
Hide file tree
Showing 23 changed files with 44 additions and 75 deletions.
8 changes: 0 additions & 8 deletions pkgs/applications/altcoins/go-ethereum.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ buildGoPackage rec {
sha256 = "1rhqnqp2d951d4084z7dc07q0my4wd5401968a0nqj030a9vgng2";
};

# Fix cyclic referencing on Darwin
postInstall = stdenv.lib.optionalString (stdenv.isDarwin) ''
for file in $bin/bin/*; do
# Not all files are referencing $out/lib so consider this step non-critical
install_name_tool -delete_rpath $out/lib $file || true
done
'';

meta = with stdenv.lib; {
homepage = https://ethereum.github.io/go-ethereum/;
description = "Official golang implementation of the Ethereum protocol";
Expand Down
2 changes: 0 additions & 2 deletions pkgs/applications/networking/syncthing/inotify.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ buildGoPackage rec {
substitute $src/etc/linux-systemd/user/syncthing-inotify.service \
$bin/lib/systemd/user/syncthing-inotify.service \
--replace /usr/bin/syncthing-inotify $bin/bin/syncthing-inotify
'' + stdenv.lib.optionalString stdenv.isDarwin ''
install_name_tool -delete_rpath $out/lib -add_rpath $bin $bin/bin/syncthing-inotify
'';

meta = with stdenv.lib; {
Expand Down
4 changes: 1 addition & 3 deletions pkgs/applications/version-management/gogs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ buildGoPackage rec {

outputs = [ "bin" "out" "data" ];

postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
install_name_tool -delete_rpath $out/lib $bin/bin/gogs
'' + ''
postInstall = ''
mkdir $data
cp -R $src/{public,templates} $data
Expand Down
8 changes: 5 additions & 3 deletions pkgs/build-support/cc-wrapper/ld-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,13 @@ if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ]; then
done
done

if [ -n "${NIX_COREFOUNDATION_RPATH:-}" ]; then
extraAfter+=(-rpath $NIX_COREFOUNDATION_RPATH)
fi
fi

# This is outside the DONT_SET_RPATH branch because it's more targeted and we
# usually want it (on Darwin) even if DONT_SET_RPATH is set.
if [ -n "${NIX_COREFOUNDATION_RPATH:-}" ]; then
extraAfter+=(-rpath $NIX_COREFOUNDATION_RPATH)
fi

# Only add --build-id if this is a final link. FIXME: should build gcc
# with --enable-linker-build-id instead?
Expand Down
6 changes: 6 additions & 0 deletions pkgs/development/compilers/llvm/3.5/llvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ in stdenv.mkDerivation rec {

propagatedBuildInputs = [ ncurses zlib ];

prePatch = ''
substituteInPlace CMakeLists.txt \
--replace 'set(CMAKE_INSTALL_NAME_DIR "@rpath")' "set(CMAKE_INSTALL_NAME_DIR "$out/lib")" \
--replace 'set(CMAKE_INSTALL_RPATH "@executable_path/../lib")' ""
'';

# hacky fix: created binaries need to be run before installation
preBuild = ''
mkdir -p $out/
Expand Down
7 changes: 5 additions & 2 deletions pkgs/development/compilers/llvm/3.8/llvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ in stdenv.mkDerivation rec {
# 10.9. This is a temporary measure until nixpkgs darwin support is
# updated.
postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
sed -i 's/os_trace(\(.*\)");$/printf(\1\\n");/g' ./projects/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc
sed -i 's/os_trace(\(.*\)");$/printf(\1\\n");/g' ./projects/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc
substituteInPlace CMakeLists.txt \
--replace 'set(CMAKE_INSTALL_NAME_DIR "@rpath")' "set(CMAKE_INSTALL_NAME_DIR "$out/lib")" \
--replace 'set(CMAKE_INSTALL_RPATH "@executable_path/../lib")' ""
'';

# hacky fix: created binaries need to be run before installation
Expand Down Expand Up @@ -75,7 +79,6 @@ in stdenv.mkDerivation rec {
'';

postInstall = stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
install_name_tool -id $out/lib/libLLVM.dylib $out/lib/libLLVM.dylib
ln -s $out/lib/libLLVM.dylib $out/lib/libLLVM-${version}.dylib
'';

Expand Down
6 changes: 4 additions & 2 deletions pkgs/development/compilers/llvm/3.9/llvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ in stdenv.mkDerivation rec {
+ stdenv.lib.optionalString stdenv.isDarwin ''
substituteInPlace ./projects/compiler-rt/cmake/config-ix.cmake \
--replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
substituteInPlace CMakeLists.txt \
--replace 'set(CMAKE_INSTALL_NAME_DIR "@rpath")' "set(CMAKE_INSTALL_NAME_DIR "$lib/lib")" \
--replace 'set(CMAKE_INSTALL_RPATH "@executable_path/../lib")' ""
''
# Patch llvm-config to return correct library path based on --link-{shared,static}.
+ stdenv.lib.optionalString (enableSharedLibraries) ''
Expand Down Expand Up @@ -130,8 +134,6 @@ in stdenv.mkDerivation rec {
+ stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-release.cmake" \
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM.dylib" "$lib/lib/libLLVM.dylib"
install_name_tool -id $lib/lib/libLLVM.dylib $lib/lib/libLLVM.dylib
install_name_tool -change @rpath/libLLVM.dylib $lib/lib/libLLVM.dylib $out/bin/llvm-config
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${version}.dylib
'';
Expand Down
6 changes: 4 additions & 2 deletions pkgs/development/compilers/llvm/4/llvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ in stdenv.mkDerivation rec {
postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
substituteInPlace ./projects/compiler-rt/cmake/config-ix.cmake \
--replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
substituteInPlace cmake/modules/AddLLVM.cmake \
--replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir INSTALL_NAME_DIR "$lib/lib")" \
--replace 'set(_install_rpath "@loader_path/../lib" ''${extra_libdir})' ""
''
# Patch llvm-config to return correct library path based on --link-{shared,static}.
+ stdenv.lib.optionalString (enableSharedLibraries) ''
Expand Down Expand Up @@ -121,8 +125,6 @@ in stdenv.mkDerivation rec {
+ stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM.dylib" "$lib/lib/libLLVM.dylib"
install_name_tool -id $lib/lib/libLLVM.dylib $lib/lib/libLLVM.dylib
install_name_tool -change @rpath/libLLVM.dylib $lib/lib/libLLVM.dylib $out/bin/llvm-config
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib
'';
Expand Down
6 changes: 4 additions & 2 deletions pkgs/development/compilers/llvm/5/llvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ in stdenv.mkDerivation rec {
postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
substituteInPlace ./projects/compiler-rt/cmake/config-ix.cmake \
--replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
substituteInPlace cmake/modules/AddLLVM.cmake \
--replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir INSTALL_NAME_DIR "$lib/lib")" \
--replace 'set(_install_rpath "@loader_path/../lib" ''${extra_libdir})' ""
''
# Patch llvm-config to return correct library path based on --link-{shared,static}.
+ stdenv.lib.optionalString (enableSharedLibraries) ''
Expand Down Expand Up @@ -129,8 +133,6 @@ in stdenv.mkDerivation rec {
+ stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM.dylib" "$lib/lib/libLLVM.dylib"
install_name_tool -id $lib/lib/libLLVM.dylib $lib/lib/libLLVM.dylib
install_name_tool -change @rpath/libLLVM.dylib $lib/lib/libLLVM.dylib $out/bin/llvm-config
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib
'';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ buildGoPackage rec {
go generate github.com/drone/drone/store/datastore/ddl
'';

postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
install_name_tool -delete_rpath $out/lib -add_rpath $bin $bin/bin/drone
'';

src = fetchFromGitHub {
owner = "drone";
repo = "drone";
Expand Down
4 changes: 0 additions & 4 deletions pkgs/development/tools/textql/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ buildGoPackage rec {

goDeps = ./deps.nix;

preFixup = stdenv.lib.optionalString stdenv.isDarwin ''
install_name_tool -delete_rpath $out/lib $bin/bin/textql
'';

meta = with stdenv.lib; {
description = "Execute SQL against structured text like CSV or TSV";
homepage = https://github.com/dinedal/textql;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ appleDerivation rec {
install_name_tool \
-id $out/lib/libresolv.9.dylib \
-change "$resolv_libSystem" $out/lib/libSystem.dylib \
-delete_rpath ${libresolv}/lib \
$out/lib/libresolv.9.dylib
ln -s libresolv.9.dylib $out/lib/libresolv.dylib
'';
Expand Down
4 changes: 0 additions & 4 deletions pkgs/servers/consul/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ buildGoPackage rec {
buildFlagsArray+=("-ldflags" "-X github.com/hashicorp/consul/version.GitDescribe=v${version} -X github.com/hashicorp/consul/version.Version=${version} -X github.com/hashicorp/consul/version.VersionPrerelease=")
'';

preFixup = stdenv.lib.optionalString stdenv.isDarwin ''
install_name_tool -delete_rpath $out/lib $bin/bin/consul
'';

meta = with stdenv.lib; {
description = "Tool for service discovery, monitoring and configuration";
homepage = https://www.consul.io/;
Expand Down
8 changes: 0 additions & 8 deletions pkgs/servers/dgraph/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ buildGoPackage rec {
-X github.com/dgraph-io/dgraph/cmd/dgraph/main.uiDir=$dashboard/src/assets/"
'';

preFixup = stdenv.lib.optionalString stdenv.isDarwin ''
# Somehow on Darwin, $out/lib (which doesn't exist) ends up in RPATH.
# Removing it fixes cycle between $out and $bin
install_name_tool -delete_rpath $out/lib $bin/bin/dgraph
install_name_tool -delete_rpath $out/lib $bin/bin/dgraphloader
install_name_tool -delete_rpath $out/lib $bin/bin/bulkloader
'';

meta = {
homepage = "https://dgraph.io/";
description = "Fast, Distributed Graph DB";
Expand Down
4 changes: 0 additions & 4 deletions pkgs/servers/monitoring/prometheus/node-exporter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ buildGoPackage rec {
sha256 = "0rm43jjqv7crfahl973swi4warqmqnmv740cg800yvzvnlp37kl4";
};

preFixup = stdenv.lib.optionalString stdenv.isDarwin ''
install_name_tool -delete_rpath $out/lib $bin/bin/node_exporter
'';

# FIXME: megacli test fails
doCheck = false;

Expand Down
4 changes: 0 additions & 4 deletions pkgs/shells/elvish/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ buildGoPackage rec {
name = "elvish-${version}";
version = "0.10";

postInstall = stdenv.lib.optionalString (stdenv.isDarwin) ''
install_name_tool -delete_rpath $out/lib $bin/bin/elvish
'';

goPackagePath = "github.com/elves/elvish";

src = fetchFromGitHub {
Expand Down
15 changes: 14 additions & 1 deletion pkgs/stdenv/generic/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,20 @@ let

setup = setupScript;

inherit preHook initialPath shell
# We pretty much never need rpaths on Darwin, since all library path references
# are absolute unless we go out of our way to make them relative (like with CF)
# TODO: This really wants to be in stdenv/darwin but we don't have hostPlatform
# there (yet?) so it goes here until then.
preHook = preHook+ lib.optionalString buildPlatform.isDarwin ''
export NIX_BUILD_DONT_SET_RPATH=1
'' + lib.optionalString hostPlatform.isDarwin ''
export NIX_DONT_SET_RPATH=1
export NIX_NO_SELF_RPATH=1
'' + lib.optionalString targetPlatform.isDarwin ''
export NIX_TARGET_DONT_SET_RPATH=1
'';

inherit initialPath shell
defaultNativeBuildInputs defaultBuildInputs;
}
// lib.optionalAttrs buildPlatform.isDarwin {
Expand Down
4 changes: 0 additions & 4 deletions pkgs/tools/filesystems/go-mtpfs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,5 @@ buildGoPackage rec {
sha256 = "1jcqp9n8fd9psfsnhfj6w97yp0zmyxplsig8pyp2gqzh4lnb5fqm";
};

preFixup = stdenv.lib.optionalString stdenv.isDarwin ''
install_name_tool -delete_rpath "$out/lib" $bin/bin/go-mtpfs
'';

goDeps = ./deps.nix;
}
2 changes: 0 additions & 2 deletions pkgs/tools/misc/direnv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ buildGoPackage rec {
make install DESTDIR=$bin
mkdir -p $bin/share/fish/vendor_conf.d
echo "eval ($bin/bin/direnv hook fish)" > $bin/share/fish/vendor_conf.d/direnv.fish
'' + stdenv.lib.optionalString (stdenv.isDarwin) ''
install_name_tool -delete_rpath $out/lib $bin/bin/direnv
'';

meta = with stdenv.lib; {
Expand Down
4 changes: 1 addition & 3 deletions pkgs/tools/networking/assh/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ buildGoPackage rec {

nativeBuildInputs = [ makeWrapper ];

postInstall = stdenv.lib.optionalString (stdenv.isDarwin) ''
install_name_tool -delete_rpath $out/lib $bin/bin/assh
'' + ''
postInstall = ''
wrapProgram "$bin/bin/assh" \
--prefix PATH : ${openssh}/bin
'';
Expand Down
4 changes: 0 additions & 4 deletions pkgs/tools/security/keybase/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ buildGoPackage rec {
sha256 = "1zgvriyir2ga0p4ah9ia1sbl9ydnrnw5ggq4c1ya8gcfgn8vzdsf";
};

postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
install_name_tool -delete_rpath $out/lib $bin/bin/keybase
'';

buildFlags = [ "-tags production" ];

meta = with stdenv.lib; {
Expand Down
4 changes: 0 additions & 4 deletions pkgs/tools/security/sudolikeaboss/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ buildGoPackage rec {
fixDarwinDylibNames
];

postInstall = ''
install_name_tool -delete_rpath $out/lib -add_rpath $bin $bin/bin/sudolikeaboss
'';

meta = with stdenv.lib; {
inherit version;
inherit (src.meta) homepage;
Expand Down
4 changes: 0 additions & 4 deletions pkgs/tools/text/sift/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ buildGoPackage rec {

goDeps = ./deps.nix;

postInstall = lib.optionalString stdenv.isDarwin ''
install_name_tool -delete_rpath $out/lib -add_rpath $bin $bin/bin/sift
'';

meta = with lib; {
description = "sift is a fast and powerful alternative to grep";
homepage = https://sift-tool.org;
Expand Down

0 comments on commit 416979f

Please sign in to comment.