summary refs log tree commit diff
path: root/pkgs/development/haskell-modules/generic-builder.nix
diff options
context:
space:
mode:
authorJudah Jacobson <judah@users.noreply.github.com>2017-05-03 13:13:05 -0700
committerJudah Jacobson <judah@users.noreply.github.com>2017-05-05 09:26:58 -0700
commit7131e06214560625cc85b89d93df3764d223a6e6 (patch)
treedecd0d228082118345c688bf04a4afb1bb233899 /pkgs/development/haskell-modules/generic-builder.nix
parent4ff4f6e0384be49bbd429c56c102c6af69edb78d (diff)
downloadnixlib-7131e06214560625cc85b89d93df3764d223a6e6.tar
nixlib-7131e06214560625cc85b89d93df3764d223a6e6.tar.gz
nixlib-7131e06214560625cc85b89d93df3764d223a6e6.tar.bz2
nixlib-7131e06214560625cc85b89d93df3764d223a6e6.tar.lz
nixlib-7131e06214560625cc85b89d93df3764d223a6e6.tar.xz
nixlib-7131e06214560625cc85b89d93df3764d223a6e6.tar.zst
nixlib-7131e06214560625cc85b89d93df3764d223a6e6.zip
haskell: work around linker limits on Mac OS X Sierra.
The Sierra linker added a limit on the number of paths that any one
dynamic library (`*.dylib`) can reference.  This causes problems when
a Haskell library has many immediate dependencies (#22810).

We follow a similar fix as GHC/Cabal/Stack: for each derivation,
create a new directory with symlinks to all the dylibs of its immediate
dependencies, and patch its package DB to reference that directory
using the new `dynamic-library-dirs` field.

Note that this change is a no-op for older versions of GHC, i.e., they will
continue to fail on some packages as before.

Also note that this change causes the bootstrapped versions of GHC to be
recompiled, since they depend on `hscolour` which is built by
`generic-builder.nix`.

Tested by building the `stack` binary as described in #22810.
Diffstat (limited to 'pkgs/development/haskell-modules/generic-builder.nix')
-rw-r--r--pkgs/development/haskell-modules/generic-builder.nix19
1 files changed, 19 insertions, 0 deletions
diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix
index f2b98e541e81..29f0fc5b496a 100644
--- a/pkgs/development/haskell-modules/generic-builder.nix
+++ b/pkgs/development/haskell-modules/generic-builder.nix
@@ -228,6 +228,25 @@ stdenv.mkDerivation ({
         configureFlags+=" --extra-lib-dirs=$p/lib"
       fi
     done
+
+    if "${if stdenv.isDarwin then "true" else "false"}"; then
+      # Work around a limit in the Mac OS X Sierra linker on the number of paths
+      # referenced by any one dynamic library:
+      #
+      # Create a local directory with symlinks of the *.dylib (Mac OS X shared
+      # libraries) from all the dependencies.
+      local dynamicLinksDir="$out/lib/links"
+      mkdir -p $dynamicLinksDir
+      local foundDylib=false
+      for d in $(grep dynamic-library-dirs $packageConfDir/*|awk '{print $2}'); do
+        ln -s $d/*.dylib $dynamicLinksDir
+      done
+      # Edit the local package DB to reference the links directory.
+      for f in $packageConfDir/*.conf; do
+        sed -i "s,dynamic-library-dirs: .*,dynamic-library-dirs: $dynamicLinksDir," $f
+      done
+    fi
+
     ${ghcCommand}-pkg --${packageDbFlag}="$packageConfDir" recache
 
     runHook postSetupCompilerEnvironment