From c2ffd1f4a80efa1872c97c5ea6f3e1b692d7110f Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Mon, 9 Jun 2025 15:25:39 -0700 Subject: [PATCH] haskell.packages.*.ghcWithPackages: Fix on darwin Previously, `ghcWithPackages` would fail to build on macOS because package `.conf` files now contain a literal `${pkgroot}` (which of course does not exist): ``` $ grep -Poz "dynamic-library-dirs:\s*\K .+\n" /nix/store/s5xrmb3583fd5qjrqsg73fblaq46gqpd-ghc-9.10.1-with-packages/lib/ghc-9.10.1/lib/package.conf.d/* ... /nix/store/s5xrmb3583fd5qjrqsg73fblaq46gqpd-ghc-9.10.1-with-packages/lib/ghc-9.10.1/lib/package.conf.d/unix-2.8.5.1-ce1b.conf.copy: ${pkgroot}/../lib/aarch64-osx-ghc-9.10.1 ... ``` Therefore, we use `ghc-pkg --simple-output list` to get a list of `.conf` files and `ghc-pkg --simple-output field "$pkg" dynamic-library-dirs` to get the value of the field while expanding `${pkgroot}` prefixes. --- .../haskell-modules/with-packages-wrapper.nix | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/pkgs/development/haskell-modules/with-packages-wrapper.nix b/pkgs/development/haskell-modules/with-packages-wrapper.nix index d1b8aeebf4f8..528c87fef4b9 100644 --- a/pkgs/development/haskell-modules/with-packages-wrapper.nix +++ b/pkgs/development/haskell-modules/with-packages-wrapper.nix @@ -62,13 +62,6 @@ let else "$out/lib/${ghc.targetPrefix}${ghc.haskellCompilerName}" + lib.optionalString (ghc ? hadrian) "/lib"; - # Boot libraries for GHC are present in a separate directory. - bootLibDir = - let - arch = if stdenv.targetPlatform.isAarch64 then "aarch64" else "x86_64"; - platform = if stdenv.targetPlatform.isDarwin then "osx" else "linux"; - in - "${ghc}/lib/${ghc.haskellCompilerName}/lib/${arch}-${platform}-${ghc.haskellCompilerName}"; docDir = "$out/share/doc/ghc/html"; packageCfgDir = "${libDir}/package.conf.d"; paths = lib.concatLists ( @@ -154,14 +147,17 @@ else # symlinkJoin: rm -f $dynamicLinksDir/* - # Boot libraries are located differently than other libraries since GHC 9.6, so handle them separately. - if [[ -x "${bootLibDir}" ]]; then - find "${bootLibDir}" -name '*.dylib' -exec ln -s {} "$dynamicLinksDir" \; - fi + dynamicLibraryDirs=() - for d in $(grep -Poz "dynamic-library-dirs:\s*\K .+\n" $packageConfDir/*|awk '{print $2}'|sort -u); do - find "$d" -name '*.dylib' -exec ln -s {} "$dynamicLinksDir" \; + for pkg in $($out/bin/ghc-pkg list --simple-output); do + dynamicLibraryDirs+=($($out/bin/ghc-pkg --simple-output field "$pkg" dynamic-library-dirs)) done + + for dynamicLibraryDir in $(echo "''${dynamicLibraryDirs[@]}" | tr ' ' '\n' | sort -u); do + echo "Linking $dynamicLibraryDir/*.dylib from $dynamicLinksDir" + find "$dynamicLibraryDir" -name '*.dylib' -exec ln -s {} "$dynamicLinksDir" \; + done + for f in $packageConfDir/*.conf; do # Initially, $f is a symlink to a read-only file in one of the inputs # (as a result of this symlinkJoin derivation).