diff --git a/pkgs/development/compilers/ghc/9.0.2.nix b/pkgs/development/compilers/ghc/9.0.2.nix index 56b16c5d48c4213..f7624741b68bef1 100644 --- a/pkgs/development/compilers/ghc/9.0.2.nix +++ b/pkgs/development/compilers/ghc/9.0.2.nix @@ -33,7 +33,7 @@ , # Whether to build dynamic libs for the standard library (on the target # platform). Static libs are always built. - enableShared ? !stdenv.targetPlatform.isWindows && !stdenv.targetPlatform.useiOSPrebuilt + enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic , # Whether to build terminfo. enableTerminfo ? !stdenv.targetPlatform.isWindows @@ -105,9 +105,13 @@ let CrossCompilePrefix = ${targetPrefix} '' + lib.optionalString (!enableProfiledLibs) '' GhcLibWays = "v dyn" - '' + lib.optionalString enableRelocatedStaticLibs '' - GhcLibHcOpts += -fPIC - GhcRtsHcOpts += -fPIC + '' + + # -fexternal-dynamic-refs apparently (because it's not clear from the documentation) + # makes the GHC RTS able to load static libraries, which may be needed for TemplateHaskell. + # This solution was described in https://www.tweag.io/blog/2020-09-30-bazel-static-haskell + lib.optionalString enableRelocatedStaticLibs '' + GhcLibHcOpts += -fPIC -fexternal-dynamic-refs + GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' EXTRA_CC_OPTS += -std=gnu99 ''; diff --git a/pkgs/development/compilers/ghc/9.2.2.nix b/pkgs/development/compilers/ghc/9.2.2.nix index 151bd202b022865..6db6eb3b0ebced1 100644 --- a/pkgs/development/compilers/ghc/9.2.2.nix +++ b/pkgs/development/compilers/ghc/9.2.2.nix @@ -34,7 +34,7 @@ , # Whether to build dynamic libs for the standard library (on the target # platform). Static libs are always built. - enableShared ? !stdenv.targetPlatform.isWindows && !stdenv.targetPlatform.useiOSPrebuilt + enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic , # Whether to build terminfo. enableTerminfo ? !stdenv.targetPlatform.isWindows @@ -106,9 +106,13 @@ let CrossCompilePrefix = ${targetPrefix} '' + lib.optionalString (!enableProfiledLibs) '' GhcLibWays = "v dyn" - '' + lib.optionalString enableRelocatedStaticLibs '' - GhcLibHcOpts += -fPIC - GhcRtsHcOpts += -fPIC + '' + + # -fexternal-dynamic-refs apparently (because it's not clear from the documentation) + # makes the GHC RTS able to load static libraries, which may be needed for TemplateHaskell. + # This solution was described in https://www.tweag.io/blog/2020-09-30-bazel-static-haskell + lib.optionalString enableRelocatedStaticLibs '' + GhcLibHcOpts += -fPIC -fexternal-dynamic-refs + GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' EXTRA_CC_OPTS += -std=gnu99 '';