summary refs log tree commit diff
path: root/pkgs/development
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2016-12-18 21:38:05 +0100
committerPeter Simons <simons@cryp.to>2016-12-24 16:15:35 +0100
commit19e2e7290a25819bd66a94db389e7e0d268f7fc0 (patch)
tree707e8f439003e27a8b5426711821ce66d2ea6904 /pkgs/development
parentb87a59bc69c33eca12a2e27fc28cde9538558abf (diff)
downloadnixlib-19e2e7290a25819bd66a94db389e7e0d268f7fc0.tar
nixlib-19e2e7290a25819bd66a94db389e7e0d268f7fc0.tar.gz
nixlib-19e2e7290a25819bd66a94db389e7e0d268f7fc0.tar.bz2
nixlib-19e2e7290a25819bd66a94db389e7e0d268f7fc0.tar.lz
nixlib-19e2e7290a25819bd66a94db389e7e0d268f7fc0.tar.xz
nixlib-19e2e7290a25819bd66a94db389e7e0d268f7fc0.tar.zst
nixlib-19e2e7290a25819bd66a94db389e7e0d268f7fc0.zip
haskell: workaround for bug with dynamic libraries on darwin
Diffstat (limited to 'pkgs/development')
-rw-r--r--pkgs/development/haskell-modules/generic-builder.nix32
1 files changed, 32 insertions, 0 deletions
diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix
index f91bd474c6fd..dfe9f68ec617 100644
--- a/pkgs/development/haskell-modules/generic-builder.nix
+++ b/pkgs/development/haskell-modules/generic-builder.nix
@@ -245,9 +245,41 @@ stdenv.mkDerivation ({
     runHook postConfigure
   '';
 
+  # The darwin pre/post build sections are a workaround https://github.com/haskell/cabal/issues/4183
+  # It seems like --extra-lib-dirs from the previous steps is not detected properly,
+  # to work around this we build using a DYLD_LIBRARY_PATH and fixup the build afterwards.
   buildPhase = ''
     runHook preBuild
+    ${optionalString stdenv.isDarwin ''
+      local inputClosure=""
+      for i in $propagatedNativeBuildInputs $nativeBuildInputs; do
+        findInputs $i inputClosure propagated-native-build-inputs
+      done
+      local -a inputLibs=()
+      for p in $inputClosure; do
+        if [ -d "$p/lib/${ghc.name}/package.conf.d" ]; then
+          continue
+        fi
+        if [ -d "$p/lib" ]; then
+          inputLibs+="$p/lib"
+        fi
+      done
+
+      for lib in $inputLibs; do
+        export DYLD_LIBRARY_PATH="$lib:''${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}"
+      done
+    ''}
     ${setupCommand} build ${buildTarget}${crossCabalFlagsString}
+    ${optionalString stdenv.isDarwin ''
+      unset DYLD_LIBRARY_PATH
+
+      local outputLib=dist/build/*-ghc${ghc.version}.dylib
+      for lib in $inputLib/*.dylib; do
+        for name in $(otool -L $outputLib | awk '$1 ~ /^'$(basename lib)'/ {print $1}' | cat); do
+          install_name_tool -change $name $lib $outputLib
+        done
+      done
+    ''}
     runHook postBuild
   '';