@@ -1,16 +1,30 @@
1−{ stdenv, lib, fetchurl, bootPkgs, perl, ncurses, libiconv, binutils, coreutils
2−, autoconf, automake, happy, alex, python3, sphinx, hscolour
3−, buildPlatform, targetPlatform , selfPkgs, cross ? null
1+{ stdenv, __targetPackages
2+, buildPlatform, hostPlatform, targetPlatform
3+, selfPkgs, cross ? null
44
5− # If enabled GHC will be build with the GPL-free but slower integer-simple
5+# build-tools
6+, bootPkgs, alex, happy, hscolour
7+, autoconf, automake, binutils, coreutils, fetchurl, perl, python3, sphinx
8+
9+, libiconv ? null, ncurses
10+
11+, # If enabled, GHC will be build with the GPL-free but slower integer-simple
612 # library instead of the faster but GPLed integer-gmp library.
7−, enableIntegerSimple ? false, gmp
13+ enableIntegerSimple ? false, gmp ? null
814}:
915
16+assert !enableIntegerSimple -> gmp != null;
17+
1018let
1119 inherit (bootPkgs) ghc;
20+
1221 version = "8.2.1";
1322
23+ # TODO(@Ericson2314) Make unconditional
24+ prefix = stdenv.lib.optionalString
25+ (targetPlatform != hostPlatform)
26+ "${targetPlatform.config}-";
27+
1428 commonBuildInputs = [ alex autoconf automake ghc happy hscolour perl python3 sphinx ];
1529 commonPreConfigure = ''
1630 sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
@@ -21,9 +35,10 @@ let
2135 '' + stdenv.lib.optionalString enableIntegerSimple ''
2236 echo "INTEGER_LIBRARY=integer-simple" > mk/build.mk
2337 '';
24−in stdenv.mkDerivation (rec {
38+in
39+stdenv.mkDerivation (rec {
2540 inherit version;
26− name = "ghc-${version}";
41+ name = "${prefix}ghc-${version}";
2742
2843 src = fetchurl {
2944 url = "https://downloads.haskell.org/~ghc/${version}/${name}-src.tar.xz";
@@ -52,15 +67,17 @@ in stdenv.mkDerivation (rec {
5267
5368 # required, because otherwise all symbols from HSffi.o are stripped, and
5469 # that in turn causes GHCi to abort
55− stripDebugFlags = [ "-S" ] ++ stdenv.lib.optional (!stdenv.isDarwin) "--keep-file-symbols";
70+ stripDebugFlags = [ "-S" ] ++ stdenv.lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols";
5671
5772 checkTarget = "test";
5873
74+ # zsh and other shells are smart about `{ghc}` but bash isn't, and doesn't
75+ # treat that as a unary `{x,y,z,..}` repetition.
5976 postInstall = ''
60− paxmark m $out/lib/${name}/bin/{ghc,haddock}
77+ paxmark m $out/lib/${name}/bin/${if targetPlatform != hostPlatform then "ghc" else "{ghc,haddock}"}
6178
6279 # Install the bash completion file.
63− install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/ghc
80+ install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${prefix}ghc
6481
6582 # Patch scripts to include "readelf" and "cat" in $PATH.
6683 for i in "$out/bin/"*; do
@@ -73,7 +90,7 @@ in stdenv.mkDerivation (rec {
7390 outputs = [ "out" "doc" ];
7491
7592 passthru = {
76− inherit bootPkgs;
93+ inherit bootPkgs prefix;
7794 } // stdenv.lib.optionalAttrs (targetPlatform != buildPlatform) {
7895 crossCompiler = selfPkgs.ghc.override {
7996 cross = targetPlatform;
@@ -105,7 +122,7 @@ in stdenv.mkDerivation (rec {
105122 "--enable-bootstrap-with-devel-snapshot"
106123 ] ++
107124 # fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
108− lib.optional (cross.config or null == "aarch64-apple-darwin14") "--disable-large-address-space";
125+ stdenv.lib.optional (cross.config or null == "aarch64-apple-darwin14") "--disable-large-address-space";
109126
110127 buildInputs = commonBuildInputs ++ [ stdenv.ccCross stdenv.binutils ];
111128