Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GHC not building with musl #129289

Merged
merged 16 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 211 additions & 60 deletions pkgs/development/compilers/ghc/8.10.2-binary.nix

Large diffs are not rendered by default.

51 changes: 46 additions & 5 deletions pkgs/development/compilers/ghc/8.10.4.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,31 @@
ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
(if useLLVM then "perf-cross" else "perf-cross-ncg")

, # Whether to build sphinx documentation.
enableDocs ? (
# Docs disabled for musl and cross because it's a large task to keep
# all `sphinx` dependencies building in those environments.
# `sphinx` pulls in among others:
# Ruby, Python, Perl, Rust, OpenGL, Xorg, gtk, LLVM.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenGL, Xorg, gtk, LLVM

(FYI) This seems to be mostly because of librsvg. Issue #126611

Regardless, I don't think we want the other dependencies for cross, so +1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sphinx is only used at build time, so all these should be no problem except for annoying bugs where stuff is target sensative.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ericson2314 Yes, the problem with it is that a lot of those build-time dependencies often simply have broken builds in pkgsMusl.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pkgsMusl.buildPackages uses glibc though, so these should just work as normally.

Copy link
Contributor Author

@nh2 nh2 Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sphinx definitely pulls in musl-based builds of the big stuff when put into nativeBuildInputs.

With enableDocs = true;:

# NIX_PATH=nixpkgs=. nix-build --no-out-link -A pkgsMusl.haskell.compiler.ghc8104
these derivations will be built:
  /nix/store/dqb7wllys8fi4c05kayp7vis7q7sqyv5-rustc-1.52.1.drv
  /nix/store/c8dhv4bza2b3sgfxnsgyw4c4mmpyg2hf-cargo-1.52.1.drv
  /nix/store/0191j4bjc3wqgzw5wwb4rsjlnj9qj5fs-cargo-check-hook.sh.drv
  /nix/store/0w4ccsgzvm1hjxh2paq929jwmr28a016-python3.8-hypothesis-6.14.0.drv
  /nix/store/22a6r5zcprs7ripgmph3ww9nlb22aj3w-glib-2.68.2.drv
  /nix/store/ch2l8i5m59dkrzh493pl7nl8ipsbj8a9-cargo-build-hook.sh.drv
  /nix/store/d8h8yax5hx51pr6zdka7kf20ar8b8s0f-cargo-c-0.8.1.drv
  /nix/store/3xqxbjv3hjjhkjqclcz86i945lk0xbwb-rav1e-0.4.1.drv
  /nix/store/z39qinmxgsr8y0h53mvm9z1yym8rkb4x-python3.8-chardet-4.0.0.drv
  /nix/store/4ybzkp5mr8gq32fxb8844kyh57a509di-python3.8-requests-2.25.1.drv
  /nix/store/c03b857b2sjf4r8ww22ibpm5bk5b6skq-fontforge-20201107.drv
  /nix/store/hl4bc00gx82pyp2d03bmijbkhs390zkh-dejavu-fonts-full-2.37.drv
  /nix/store/87vvdnk0419cs3mmjivyqjrqm3vf681s-dejavu-fonts-minimal-2.37.drv
  /nix/store/j9nn88akwhczqj3ld826xw2c4fgi2mcn-fontconfig-2.13.92.drv
  /nix/store/rjkz68g7w2b6z0i7hdnjyskkq6jn7ks9-cairo-1.16.0.drv
  /nix/store/jc7gnc7hi0vfm580l15pb5ik5bhqzycf-absolute_gir_path.patch.drv
  /nix/store/bbsdxnx2a9mv5p0vljrhvcf7dcf62v4g-gobject-introspection-1.68.0.drv
  /nix/store/akvj0gh18dkcs5yqza16ym3f8hqla5c5-harfbuzz-2.8.1.drv
  /nix/store/j7p5ygq1aj3yhs5xds156n7qa8982a0m-fonts.conf.drv
  /nix/store/rxnhk21hmfrhm1lfhn3yw8ckv5cc0x7d-libXft-2.3.3.drv
  /nix/store/d8h9p3dr36lwn42mvrhs7yjrv5zkf9yn-pango-1.48.4.drv
  /nix/store/fq7ky3d1s005nsr8vdrf59ybrcff9ipf-vala-0.52.2.drv
  /nix/store/w7qxqy20bhhi370xx1p482kf8yyxblmq-gdk-pixbuf-2.42.6.drv
  /nix/store/bl58hg9v5ni17wl5255n6gn8ryqn0ncr-librsvg-2.50.6.drv
  /nix/store/fhsvgbjgxaxxi3bvypsp2kbm4vpakrwl-libheif-1.12.0.drv
  /nix/store/idjyn2lxazwfv50zjjlwb7a39f5gczk9-djvulibre-3.5.28.drv
  /nix/store/dh9vh2mcp67yqy9jy30jlz67mxf8j8hm-imagemagick-7.1.0-0.drv
  /nix/store/rwknqkhd87phxq8iw1hz2kh983za44xi-python3.8-sphinx-4.0.2.drv
  /nix/store/79w1vxjxp3fj1asaz7aqi0lrk2gn6n7c-ghc-8.10.4.drv

Investigation:

nix-store -q --tree $(NIX_PATH=nixpkgs=. nix-instantiate -A pkgsMusl.haskell.compiler.ghc8104)

+---/nix/store/rwknqkhd87phxq8iw1hz2kh983za44xi-python3.8-sphinx-4.0.2.drv
    +---/nix/store/ck02h2ph9zsscw3cb59brn669hbzynfm-python3.8-sphinxcontrib-serializinghtml-1.1.5.drv
    |   +---/nix/store/bl58hg9v5ni17wl5255n6gn8ryqn0ncr-librsvg-2.50.6.drv
    |   |   +---/nix/store/dqb7wllys8fi4c05kayp7vis7q7sqyv5-rustc-1.52.1.drv

nix-store -q --tree $(NIX_PATH=nixpkgs=. nix-instantiate -A haskell.compiler.ghc8104)

        +---/nix/store/pr7m6hbnn9xhcwmq1mnxcygnm06qkfgk-librsvg-2.50.6.drv

Diffing those two librsvg derivations:

nix-diff /nix/store/pr7m6hbnn9xhcwmq1mnxcygnm06qkfgk-librsvg-2.50.6.drv /nix/store/bl58hg9v5ni17wl5255n6gn8ryqn0ncr-librsvg-2.50.6.drv

        • The input named `bootstrap-stage0-binutils-wrapper-` differs
          - /nix/store/pmvn7qs31f8fwl04w6qdrzb6kqsjizbg-bootstrap-stage0-binutils-wrapper-.drv:{out}
          + /nix/store/fz2w0rj4rvmbny1hrz8hc0hlhjahffrs-bootstrap-stage0-binutils-wrapper-.drv:{out}
          • The builders do not match
              - /nix/store/p4s4jf7aq6v6z9iazll1aiqwb34aqxq9-bootstrap-tools/bin/bash
              + /nix/store/5b7a4ynm23gm375q1fzbsh4sqc806864-bootstrap-tools/bin/bash
          • The set of input names do not match:
              - bootstrap-stage0-glibc-bootstrap
              + bootstrap-stage0-musl-bootstrap

glibc-bootstrap vs musl-bootstrap in here.

Copy link
Contributor Author

@nh2 nh2 Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved on Matrix: https://matrix.to/#/!RbXGJhHMsnQcNIDFWN:nixos.org/$2dtglPPokoMcxS7yQt53iBLFvMkqr-R3yqdYA5hJyVg?via=nixos.org&via=matrix.org&via=orbstheorem.ch

oh yeah it [pkgsMusl] isn't cross compiled, nevermind

pkgsMusl = if stdenv.hostPlatform.isLinux then nixpkgsFun {
overlays = [ (self': super': {
pkgsMusl = super';
})] ++ overlays;
${if stdenv.hostPlatform == stdenv.buildPlatform
then "localSystem" else "crossSystem"} = {
parsed = stdenv.hostPlatform.parsed // {
abi = {
gnu = lib.systems.parse.abis.musl;
gnueabi = lib.systems.parse.abis.musleabi;
gnueabihf = lib.systems.parse.abis.musleabihf;
}.${stdenv.hostPlatform.parsed.abi.name}
or lib.systems.parse.abis.musl;
};
};
} else throw "Musl libc only supports Linux systems.";

(stdenv.targetPlatform == stdenv.hostPlatform)
&& !stdenv.hostPlatform.isMusl
)

, enableHaddockProgram ?
# Disabled for cross; see note [HADDOCK_DOCS].
(stdenv.targetPlatform == stdenv.hostPlatform)

, # Whether to disable the large address space allocator
# necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
disableLargeAddressSpace ? stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64
}:

assert !enableIntegerSimple -> gmp != null;

# Cross cannot currently build the `haddock` program for silly reasons,
# see note [HADDOCK_DOCS].
assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram;

let
inherit (stdenv) buildPlatform hostPlatform targetPlatform;

Expand All @@ -60,14 +78,26 @@ let
ifneq \"\$(BuildFlavour)\" \"\"
include mk/flavours/\$(BuildFlavour).mk
endif
BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"}
BUILD_SPHINX_PDF = NO
'' +
# Note [HADDOCK_DOCS]:
# Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock`
# program is built (which we generally always want to have a complete GHC install)
# and whether it is run on the GHC sources to generate hyperlinked source code
# (which is impossible for cross-compilation); see:
# https://gitlab.haskell.org/ghc/ghc/-/issues/20077
# This implies that currently a cross-compiled GHC will never have a `haddock`
# program, so it can never generate haddocks for any packages.
# If this is solved in the future, we'd like to unconditionally
# build the haddock program (removing the `enableHaddockProgram` option).
''
HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"}
DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"}
'' + lib.optionalString (targetPlatform != hostPlatform) ''
Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"}
CrossCompilePrefix = ${targetPrefix}
HADDOCK_DOCS = NO
BUILD_SPHINX_HTML = NO
BUILD_SPHINX_PDF = NO
'' + lib.optionalString (!enableProfiledLibs) ''
GhcLibWays = "v dyn"
'' + lib.optionalString enableRelocatedStaticLibs ''
Expand Down Expand Up @@ -217,8 +247,10 @@ stdenv.mkDerivation (rec {
dontAddExtraLibs = true;

nativeBuildInputs = [
perl autoconf automake m4 python3 sphinx
perl autoconf automake m4 python3
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
] ++ lib.optionals enableDocs [
sphinx
];

# For building runtime libs
Expand All @@ -238,7 +270,16 @@ stdenv.mkDerivation (rec {

checkTarget = "test";

hardeningDisable = [ "format" ] ++ lib.optional stdenv.targetPlatform.isMusl "pie";
hardeningDisable =
[ "format" ]
# In nixpkgs, musl based builds currently enable `pie` hardening by default
# (see `defaultHardeningFlags` in `make-derivation.nix`).
# But GHC cannot currently produce outputs that are ready for `-pie` linking.
# Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear.
# See:
# * https://github.com/NixOS/nixpkgs/issues/129247
# * https://gitlab.haskell.org/ghc/ghc/-/issues/19580
++ lib.optional stdenv.targetPlatform.isMusl "pie";

postInstall = ''
# Install the bash completion file.
Expand Down
12 changes: 11 additions & 1 deletion pkgs/development/compilers/ghc/8.6.5-binary.nix
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ stdenv.mkDerivation rec {

configurePlatforms = [ ];
configureFlags = [
"--with-gmp-libraries=${lib.getLib gmp}/lib"
"--with-gmp-includes=${lib.getDev gmp}/include"
# Note `--with-gmp-libraries` does nothing for GHC bindists:
# https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6124
] ++ lib.optional stdenv.isDarwin "--with-gcc=${./gcc-clang-wrapper.sh}"
++ lib.optional stdenv.hostPlatform.isMusl "--disable-ld-override";

Expand Down Expand Up @@ -152,6 +153,15 @@ stdenv.mkDerivation rec {
done
'';

# In nixpkgs, musl based builds currently enable `pie` hardening by default
# (see `defaultHardeningFlags` in `make-derivation.nix`).
# But GHC cannot currently produce outputs that are ready for `-pie` linking.
# Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear.
# See:
# * https://github.com/NixOS/nixpkgs/issues/129247
# * https://gitlab.haskell.org/ghc/ghc/-/issues/19580
hardeningDisable = lib.optional stdenv.targetPlatform.isMusl "pie";

doInstallCheck = true;
installCheckPhase = ''
unset ${libEnvVar}
Expand Down
62 changes: 53 additions & 9 deletions pkgs/development/compilers/ghc/8.8.4.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,31 @@
ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
(if useLLVM then "perf-cross" else "perf-cross-ncg")

, # Whether to build sphinx documentation.
enableDocs ? (
# Docs disabled for musl and cross because it's a large task to keep
# all `sphinx` dependencies building in those environments.
# `sphinx` pullls in among others:
# Ruby, Python, Perl, Rust, OpenGL, Xorg, gtk, LLVM.
(stdenv.targetPlatform == stdenv.hostPlatform)
&& !stdenv.hostPlatform.isMusl
)

, enableHaddockProgram ?
# Disabled for cross; see note [HADDOCK_DOCS].
(stdenv.targetPlatform == stdenv.hostPlatform)

, # Whether to disable the large address space allocator
# necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
disableLargeAddressSpace ? stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64
}:

assert !enableIntegerSimple -> gmp != null;

# Cross cannot currently build the `haddock` program for silly reasons,
# see note [HADDOCK_DOCS].
assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram;

let
inherit (stdenv) buildPlatform hostPlatform targetPlatform;

Expand All @@ -60,6 +78,21 @@ let
ifneq \"\$(BuildFlavour)\" \"\"
include mk/flavours/\$(BuildFlavour).mk
endif
BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"}
BUILD_SPHINX_PDF = NO
'' +
# Note [HADDOCK_DOCS]:
# Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock`
# program is built (which we generally always want to have a complete GHC install)
# and whether it is run on the GHC sources to generate hyperlinked source code
# (which is impossible for cross-compilation); see:
# https://gitlab.haskell.org/ghc/ghc/-/issues/20077
# This implies that currently a cross-compiled GHC will never have a `haddock`
# program, so it can never generate haddocks for any packages.
# If this is solved in the future, we'd like to unconditionally
# build the haddock program (removing the `enableHaddockProgram` option).
''
HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"}
DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"}
''
Expand All @@ -72,9 +105,6 @@ let
+ lib.optionalString (targetPlatform != hostPlatform) ''
Stage1Only = ${if (targetPlatform.system == hostPlatform.system && !targetPlatform.isiOS) then "NO" else "YES"}
CrossCompilePrefix = ${targetPrefix}
HADDOCK_DOCS = NO
BUILD_SPHINX_HTML = NO
BUILD_SPHINX_PDF = NO
'' + lib.optionalString dontStrip ''
STRIP_CMD = :
'' + lib.optionalString (!enableProfiledLibs) ''
Expand Down Expand Up @@ -142,11 +172,14 @@ stdenv.mkDerivation (rec {
postPatch = "patchShebangs .";

# GHC is a bit confused on its cross terminology.
preConfigure = lib.optionalString stdenv.isAarch64 ''
preConfigure =
# Aarch64 allow backward bootstrapping since earlier versions are unstable.
find . -name \*\.cabal\* -exec sed -i -e 's/\(base.*\)4.14/\14.16/' {} \; \
-exec sed -i -e 's/\(prim.*\)0.6/\10.8/' {} \;
'' + ''
# Same for musl, as earlier versions do not provide a musl bindist for bootstrapping.
lib.optionalString (stdenv.isAarch64 || stdenv.hostPlatform.isMusl) ''
find . -name \*\.cabal\* -exec sed -i -e 's/\(base.*\)4.14/\14.16/' {} \; \
-exec sed -i -e 's/\(prim.*\)0.6/\10.8/' {} \;
''
+ ''
for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
export "''${env#TARGET_}=''${!env}"
done
Expand Down Expand Up @@ -224,8 +257,10 @@ stdenv.mkDerivation (rec {
dontAddExtraLibs = true;

nativeBuildInputs = [
perl autoconf automake m4 python3 sphinx
perl autoconf automake m4 python3
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
] ++ lib.optionals enableDocs [
sphinx
];

# For building runtime libs
Expand All @@ -245,7 +280,16 @@ stdenv.mkDerivation (rec {

checkTarget = "test";

hardeningDisable = [ "format" ] ++ lib.optional stdenv.targetPlatform.isMusl "pie";
hardeningDisable =
[ "format" ]
# In nixpkgs, musl based builds currently enable `pie` hardening by default
# (see `defaultHardeningFlags` in `make-derivation.nix`).
# But GHC cannot currently produce outputs that are ready for `-pie` linking.
# Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear.
# See:
# * https://github.com/NixOS/nixpkgs/issues/129247
# * https://gitlab.haskell.org/ghc/ghc/-/issues/19580
++ lib.optional stdenv.targetPlatform.isMusl "pie";

postInstall = ''
# Install the bash completion file.
Expand Down
53 changes: 47 additions & 6 deletions pkgs/development/compilers/ghc/9.0.1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,31 @@
ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
(if useLLVM then "perf-cross" else "perf-cross-ncg")

, # Whether to build sphinx documentation.
enableDocs ? (
# Docs disabled for musl and cross because it's a large task to keep
# all `sphinx` dependencies building in those environments.
# `sphinx` pullls in among others:
# Ruby, Python, Perl, Rust, OpenGL, Xorg, gtk, LLVM.
(stdenv.targetPlatform == stdenv.hostPlatform)
&& !stdenv.hostPlatform.isMusl
)

, enableHaddockProgram ?
# Disabled for cross; see note [HADDOCK_DOCS].
(stdenv.targetPlatform == stdenv.hostPlatform)

, # Whether to disable the large address space allocator
# necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
disableLargeAddressSpace ? stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64
}:

assert !enableIntegerSimple -> gmp != null;

# Cross cannot currently build the `haddock` program for silly reasons,
# see note [HADDOCK_DOCS].
assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram;

let
inherit (stdenv) buildPlatform hostPlatform targetPlatform;

Expand All @@ -61,14 +79,26 @@ let
ifneq \"\$(BuildFlavour)\" \"\"
include mk/flavours/\$(BuildFlavour).mk
endif
BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"}
BUILD_SPHINX_PDF = NO
'' +
# Note [HADDOCK_DOCS]:
# Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock`
# program is built (which we generally always want to have a complete GHC install)
# and whether it is run on the GHC sources to generate hyperlinked source code
# (which is impossible for cross-compilation); see:
# https://gitlab.haskell.org/ghc/ghc/-/issues/20077
# This implies that currently a cross-compiled GHC will never have a `haddock`
# program, so it can never generate haddocks for any packages.
# If this is solved in the future, we'd like to unconditionally
# build the haddock program (removing the `enableHaddockProgram` option).
''
HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"}
DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"}
'' + lib.optionalString (targetPlatform != hostPlatform) ''
Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"}
CrossCompilePrefix = ${targetPrefix}
HADDOCK_DOCS = NO
BUILD_SPHINX_HTML = NO
BUILD_SPHINX_PDF = NO
'' + lib.optionalString (!enableProfiledLibs) ''
GhcLibWays = "v dyn"
'' + lib.optionalString enableRelocatedStaticLibs ''
Expand Down Expand Up @@ -143,7 +173,7 @@ stdenv.mkDerivation (rec {

echo -n "${buildMK}" > mk/build.mk
sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
'' + lib.optionalString (stdenv.isLinux) ''
'' + lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") ''
export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive"
'' + lib.optionalString (!stdenv.isDarwin) ''
export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}"
Expand Down Expand Up @@ -204,8 +234,10 @@ stdenv.mkDerivation (rec {
dontAddExtraLibs = true;

nativeBuildInputs = [
perl autoconf automake m4 python3 sphinx
perl autoconf automake m4 python3
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
] ++ lib.optionals enableDocs [
sphinx
];

# For building runtime libs
Expand All @@ -225,7 +257,16 @@ stdenv.mkDerivation (rec {

checkTarget = "test";

hardeningDisable = [ "format" ] ++ lib.optional stdenv.targetPlatform.isMusl "pie";
hardeningDisable =
[ "format" ]
# In nixpkgs, musl based builds currently enable `pie` hardening by default
# (see `defaultHardeningFlags` in `make-derivation.nix`).
# But GHC cannot currently produce outputs that are ready for `-pie` linking.
# Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear.
# See:
# * https://github.com/NixOS/nixpkgs/issues/129247
# * https://gitlab.haskell.org/ghc/ghc/-/issues/19580
++ lib.optional stdenv.targetPlatform.isMusl "pie";

postInstall = ''
# Install the bash completion file.
Expand Down
Loading