From 1875df23a43d80ec4ef72141f2748f767d0013d7 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Sat, 30 Jan 2021 22:25:57 -0500 Subject: [PATCH] stdenv/darwin: set NIX_COREFOUNDATION_RPATH via hook This will unset the variable in the cross stdenv where CF is taken out of extraBuildInputs. This is useful for cross compilation to linux where setting RPATH on glibc will break it in runtime. The hook needs to be turned off during the bootstrapping to prevent unwanted references between the stages. --- .../swift-corelibs/corefoundation-setup-hook.sh | 8 ++++++++ .../darwin/swift-corelibs/corefoundation.nix | 9 ++++++--- pkgs/stdenv/darwin/default.nix | 15 ++++++++------- 3 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 pkgs/os-specific/darwin/swift-corelibs/corefoundation-setup-hook.sh diff --git a/pkgs/os-specific/darwin/swift-corelibs/corefoundation-setup-hook.sh b/pkgs/os-specific/darwin/swift-corelibs/corefoundation-setup-hook.sh new file mode 100644 index 0000000000000..6eba947c01697 --- /dev/null +++ b/pkgs/os-specific/darwin/swift-corelibs/corefoundation-setup-hook.sh @@ -0,0 +1,8 @@ +useCoreFoundationFramework () { + # Avoid overriding value set by the impure CF + if [ -z "${NIX_COREFOUNDATION_RPATH+x}" ]; then + export NIX_COREFOUNDATION_RPATH=@out@/Library/Frameworks + fi +} + +addEnvHooks "$hostOffset" useCoreFoundationFramework diff --git a/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix b/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix index 7c48d695e11d1..eae617b447bf5 100644 --- a/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix +++ b/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix @@ -1,4 +1,5 @@ -{ lib, stdenv, fetchFromGitHub, fetchurl, ninja, python3, curl, libxml2, objc4, ICU }: +{ lib, stdenv, fetchFromGitHub, fetchurl, ninja, python3, curl, libxml2, objc4, ICU +, withRpathHook ? true }: let # 10.12 adds a new sysdir.h that our version of CF in the main derivation depends on, but @@ -10,7 +11,7 @@ let }; in -stdenv.mkDerivation { +stdenv.mkDerivation ({ pname = "swift-corefoundation"; version = "unstable-2018-09-14"; @@ -104,4 +105,6 @@ stdenv.mkDerivation { ln -s Versions/Current/$i $base/$i done ''; -} +} // lib.optionalAttrs withRpathHook { + setupHook = ./corefoundation-setup-hook.sh; +}) diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index ffe99da869225..c236310cfabea 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -54,6 +54,7 @@ let "/usr/lib/system/libunc.dylib" # This dependency is "hidden", so our scanning code doesn't pick it up ]; + withoutRpathHook = drv: if useAppleSDKLibs then drv else drv.override { withRpathHook = false; }; in rec { commonPreHook = '' @@ -461,7 +462,8 @@ rec { darwin = super.darwin.overrideScope (_: _: { inherit (darwin) binutils dyld Libsystem xnu configd ICU libdispatch libclosure - launchd CF objc4 darwin-stubs sigtool postLinkSignHook signingUtils; + launchd objc4 darwin-stubs sigtool postLinkSignHook signingUtils; + CF = withoutRpathHook darwin.CF; }); }; in @@ -471,7 +473,7 @@ rec { ''; extraNativeBuildInputs = [ pkgs.xz ]; - extraBuildInputs = [ pkgs.darwin.CF ]; + extraBuildInputs = [ (withoutRpathHook pkgs.darwin.CF) ]; libcxx = pkgs."${finalLlvmPackages}".libcxx; allowedRequisites = @@ -541,7 +543,7 @@ rec { # and instead goes by $PATH, which happens to contain bootstrapTools. So it goes and # patches our shebangs back to point at bootstrapTools. This makes sure bash comes first. extraNativeBuildInputs = with pkgs; [ xz ]; - extraBuildInputs = [ pkgs.darwin.CF pkgs.bash ]; + extraBuildInputs = [ (withoutRpathHook pkgs.darwin.CF) pkgs.bash ]; libcxx = pkgs."${finalLlvmPackages}".libcxx; extraPreHook = '' @@ -617,17 +619,17 @@ rec { # See useAppleSDKLibs in darwin-packages.nix CF = if useAppleSDKLibs then super.darwin.CF else - superDarwin.CF.override { + withoutRpathHook (superDarwin.CF.override { inherit libxml2; python3 = prevStage.python3; - }; + }); }); }; in with prevStage; stageFun 4 prevStage { shell = "${pkgs.bash}/bin/bash"; extraNativeBuildInputs = with pkgs; [ xz ]; - extraBuildInputs = [ pkgs.darwin.CF pkgs.bash ]; + extraBuildInputs = [ (withoutRpathHook pkgs.darwin.CF) pkgs.bash ]; libcxx = pkgs."${finalLlvmPackages}".libcxx; extraPreHook = '' @@ -681,7 +683,6 @@ rec { targetPlatform = localSystem; preHook = commonPreHook + '' - export NIX_COREFOUNDATION_RPATH=${pkgs.darwin.CF}/Library/Frameworks export PATH_LOCALE=${pkgs.darwin.locale}/share/locale '';