diff --git a/pkgs/development/haskell-modules/cabal-hook.sh b/pkgs/development/haskell-modules/cabal-hook.sh new file mode 100644 index 0000000000000..287f059c6bb51 --- /dev/null +++ b/pkgs/development/haskell-modules/cabal-hook.sh @@ -0,0 +1,49 @@ +# Adds hooks to run for each dependency to the generic-builder.nix. There are two types of dependencies that Cabal needs to know about. + +# - Haskell dependencies have a $package.conf.d directory that stores +# all necessary information for using the package as a dependency. - + +# - External dependencies don’t have a package.conf.d directory. Cabal +# needs the --extra-include-dirs, --extra-lib-dirs, and +# --extra-framework-dirs to detect them. We only want to set +# --extra-lib-dirs when we know that there are actual libraries +# available and not meta information like cmake or pkgconfig data. + +setupPackageConfDir="$TMPDIR/setup-package.conf.d" +mkdir -p $setupPackageConfDir + +packageConfDir="$TMPDIR/package.conf.d" +mkdir -p $packageConfDir + +# We build the Setup.hs on the *build* machine, and as such should +# only add dependencies for the build machine. + +addCabalPkgDb() { + if [ -n "$(echo $1/lib/*/package.conf.d)" ]; then + cp -f $1/lib/*/package.conf.d/*.conf "$packageConfDir" + fi +} + +addCabalSetupPkgDb() { + if [ -n "$(echo $1/lib/*/package.conf.d)" ]; then + cp -f $1/lib/*/package.conf.d/*.conf "$setupPackageConfDir" + fi +} + +addCabalConfigureFlags() { + if [ -z "$(echo $1/lib/*/package.conf.d)" ]; then + if [ -d "$1/include" ]; then + configureFlags+=" --extra-include-dirs=$1/include" + fi + if [ -n "$(echo $1/lib/lib*)" ]; then + configureFlags+=" --extra-lib-dirs=$1/lib" + fi + if [ -d "$1/Library/Frameworks" ]; then + configureFlags+=" --extra-framework-dirs=$1/Library/Frameworks" + fi + fi +} + +addEnvHooks "$hostOffset" addCabalSetupPkgDb +addEnvHooks "$targetOffset" addCabalPkgDb +addEnvHooks "$targetOffset" addCabalConfigureFlags diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index e8195668c41c2..54132f66e1d1c 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -211,12 +211,6 @@ let nativeGhcCommand = "${nativeGhc.targetPrefix}ghc"; - buildPkgDb = ghcName: packageConfDir: '' - if [ -d "$p/lib/${ghcName}/package.conf.d" ]; then - cp -f "$p/lib/${ghcName}/package.conf.d/"*.conf ${packageConfDir}/ - continue - fi - ''; in stdenv.lib.fix (drv: assert allPkgconfigDepends != [] -> pkgconfig != null; @@ -235,7 +229,8 @@ stdenv.mkDerivation ({ inherit src; - inherit depsBuildBuild nativeBuildInputs; + inherit depsBuildBuild; + nativeBuildInputs = [ ./cabal-hook.sh ] ++ nativeBuildInputs; buildInputs = otherBuildInputs ++ optionals (!isLibrary) propagatedBuildInputs; propagatedBuildInputs = optionals isLibrary propagatedBuildInputs; @@ -258,43 +253,11 @@ stdenv.mkDerivation ({ echo "Build with ${ghc}." ${optionalString (isLibrary && hyperlinkSource) "export PATH=${hscolour}/bin:$PATH"} - setupPackageConfDir="$TMPDIR/setup-package.conf.d" - mkdir -p $setupPackageConfDir - packageConfDir="$TMPDIR/package.conf.d" - mkdir -p $packageConfDir - setupCompileFlags="${concatStringsSep " " setupCompileFlags}" configureFlags="${concatStringsSep " " defaultConfigureFlags} $configureFlags" - '' - # We build the Setup.hs on the *build* machine, and as such should only add - # dependencies for the build machine. - # - # pkgs* arrays defined in stdenv/setup.hs - + '' - for p in "''${pkgsBuildBuild[@]}" "''${pkgsBuildHost[@]}" "''${pkgsBuildTarget[@]}"; do - ${buildPkgDb nativeGhc.name "$setupPackageConfDir"} - done + ${nativeGhcCommand}-pkg --${nativePackageDbFlag}="$setupPackageConfDir" recache '' - # For normal components - + '' - for p in "''${pkgsHostHost[@]}" "''${pkgsHostTarget[@]}"; do - ${buildPkgDb ghc.name "$packageConfDir"} - if [ -d "$p/include" ]; then - configureFlags+=" --extra-include-dirs=$p/include" - fi - if [ -d "$p/lib" ]; then - configureFlags+=" --extra-lib-dirs=$p/lib" - fi - '' - # It is not clear why --extra-framework-dirs does work fine on Linux - + optionalString (!stdenv.buildPlatform.isDarwin || versionAtLeast nativeGhc.version "8.0") '' - if [[ -d "$p/Library/Frameworks" ]]; then - configureFlags+=" --extra-framework-dirs=$p/Library/Frameworks" - fi - '' + '' - done - '' # only use the links hack if we're actually building dylibs. otherwise, the # "dynamic-library-dirs" point to nonexistent paths, and the ln command becomes # "ln -s $out/lib/links", which tries to recreate the links dir and fails