haskell.compiler.*: only set LANG if necessary

Our theory is that only sphinx and haddock need a working locale on
the build platform. We should actually put this into practice so our
understanding matches our build instructions.
This commit is contained in:
sternenseemann
2025-09-07 19:06:13 +02:00
parent c2a6508854
commit 22aa976316
2 changed files with 23 additions and 16 deletions
@@ -343,6 +343,10 @@ let
# TODO(@Ericson2314) Make unconditional
targetPrefix = lib.optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-";
# TODO(@sternenseemann): there's no stage0:exe:haddock target by default,
# so haddock isn't available for GHC cross-compilers. Can we fix that?
hasHaddock = stdenv.hostPlatform == stdenv.targetPlatform;
hadrianSettings =
# -fexternal-dynamic-refs apparently (because it's not clear from the
# documentation) makes the GHC RTS able to load static libraries, which may
@@ -495,9 +499,6 @@ stdenv.mkDerivation (
patchShebangs --build .
'';
# GHC needs the locale configured during the Haddock phase.
LANG = "en_US.UTF-8";
# GHC is a bit confused on its cross terminology.
# TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths
preConfigure = ''
@@ -548,9 +549,15 @@ stdenv.mkDerivation (
"${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang"
}"
''
+ lib.optionalString (stdenv.buildPlatform.libc == "glibc") ''
export LOCALE_ARCHIVE="${buildPackages.glibcLocales}/lib/locale/locale-archive"
''
# Haddock and sphinx need a working locale
+ lib.optionalString (enableDocs || hasHaddock) (
''
export LANG="en_US.UTF-8"
''
+ lib.optionalString (stdenv.buildPlatform.libc == "glibc") ''
export LOCALE_ARCHIVE="${buildPackages.glibcLocales}/lib/locale/locale-archive"
''
)
+ lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}"
''
@@ -854,14 +861,11 @@ stdenv.mkDerivation (
inherit llvmPackages;
inherit enableShared;
inherit hasHaddock;
# Expose hadrian used for bootstrapping, for debugging purposes
inherit hadrian;
# TODO(@sternenseemann): there's no stage0:exe:haddock target by default,
# so haddock isn't available for GHC cross-compilers. Can we fix that?
hasHaddock = stdenv.hostPlatform == stdenv.targetPlatform;
bootstrapAvailable = lib.meta.availableOn stdenv.buildPlatform bootPkgs.ghc;
};
@@ -378,9 +378,6 @@ stdenv.mkDerivation (
postPatch = "patchShebangs .";
# GHC needs the locale configured during the Haddock phase.
LANG = "en_US.UTF-8";
# GHC is a bit confused on its cross terminology.
# TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths
preConfigure = ''
@@ -435,9 +432,15 @@ stdenv.mkDerivation (
echo -n "${buildMK}" > mk/build.mk
sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
''
+ lib.optionalString (stdenv.buildPlatform.libc == "glibc") ''
export LOCALE_ARCHIVE="${buildPackages.glibcLocales}/lib/locale/locale-archive"
''
# Haddock and sphinx need a working locale
+ lib.optionalString (enableDocs || enableHaddockProgram) (
''
export LANG="en_US.UTF-8"
''
+ lib.optionalString (stdenv.buildPlatform.libc == "glibc") ''
export LOCALE_ARCHIVE="${buildPackages.glibcLocales}/lib/locale/locale-archive"
''
)
+ lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}"
''