@@ -0,0 +1,117 @@
1+{ stdenv, lib, fetchurl, bootPkgs, perl, ncurses, libiconv, binutils, coreutils
2+, autoconf, automake, happy, alex, python3, sphinx, hscolour
3+, buildPlatform, targetPlatform , selfPkgs, cross ? null
5+ # If enabled GHC will be build with the GPL-free but slower integer-simple
6+ # library instead of the faster but GPLed integer-gmp library.
7+, enableIntegerSimple ? false, gmp
11+ inherit (bootPkgs) ghc;
12+ version = "8.2.1-rc2";
13+ preReleaseName = "ghc-8.2.0.20170507";
14+ commonBuildInputs = [ alex autoconf automake ghc happy hscolour perl python3 sphinx ];
15+ commonPreConfigure = ''
16+ sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
17+ '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
18+ export NIX_LDFLAGS="$NIX_LDFLAGS -rpath $out/lib/${preReleaseName}"
19+ '' + stdenv.lib.optionalString stdenv.isDarwin ''
20+ export NIX_LDFLAGS+=" -no_dtrace_dof"
21+ '' + stdenv.lib.optionalString enableIntegerSimple ''
22+ echo "INTEGER_LIBRARY=integer-simple" > mk/build.mk
24+in stdenv.mkDerivation (rec {
26+ name = "ghc-${version}";
29+ url = "https://downloads.haskell.org/~ghc/${version}/${preReleaseName}-src.tar.xz";
30+ sha256 = "1hy3l6nzkyhzwy9mii4zs51jv048zwvdqk1q3188jznz35392zrn";
33+ postPatch = "patchShebangs .";
35+ preConfigure = commonPreConfigure;
37+ buildInputs = commonBuildInputs;
39+ enableParallelBuilding = true;
42+ "CC=${stdenv.cc}/bin/cc"
43+ "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
44+ "--datadir=$doc/share/doc/ghc"
45+ ] ++ stdenv.lib.optional (! enableIntegerSimple) [
46+ "--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
47+ ] ++ stdenv.lib.optional stdenv.isDarwin [
48+ "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
51+ # required, because otherwise all symbols from HSffi.o are stripped, and
52+ # that in turn causes GHCi to abort
53+ stripDebugFlags = [ "-S" ] ++ stdenv.lib.optional (!stdenv.isDarwin) "--keep-file-symbols";
55+ checkTarget = "test";
58+ paxmark m $out/lib/${preReleaseName}/bin/{ghc,haddock}
60+ # Install the bash completion file.
61+ install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/ghc
63+ # Patch scripts to include "readelf" and "cat" in $PATH.
64+ for i in "$out/bin/"*; do
65+ test ! -h $i || continue
66+ egrep --quiet '^#!' <(head -n 1 $i) || continue
67+ sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ binutils coreutils ]}"' $i
71+ outputs = [ "out" "doc" ];
75+ } // stdenv.lib.optionalAttrs (targetPlatform != buildPlatform) {
76+ crossCompiler = selfPkgs.ghc.override {
77+ cross = targetPlatform;
83+ homepage = "http://haskell.org/ghc";
84+ description = "The Glasgow Haskell Compiler";
85+ maintainers = with stdenv.lib.maintainers; [ marcweber andres peti ];
86+ inherit (ghc.meta) license platforms;
89+} // stdenv.lib.optionalAttrs (cross != null) {
90+ name = "${cross.config}-ghc-${version}";
92+ preConfigure = commonPreConfigure + ''
93+ sed 's|#BuildFlavour = quick-cross|BuildFlavour = perf-cross|' mk/build.mk.sample > mk/build.mk
97+ "CC=${stdenv.ccCross}/bin/${cross.config}-cc"
98+ "LD=${stdenv.binutils}/bin/${cross.config}-ld"
99+ "AR=${stdenv.binutils}/bin/${cross.config}-ar"
100+ "NM=${stdenv.binutils}/bin/${cross.config}-nm"
101+ "RANLIB=${stdenv.binutils}/bin/${cross.config}-ranlib"
102+ "--target=${cross.config}"
103+ "--enable-bootstrap-with-devel-snapshot"
105+ # fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
106+ lib.optional (cross.config or null == "aarch64-apple-darwin14") "--disable-large-address-space";
108+ buildInputs = commonBuildInputs ++ [ stdenv.ccCross stdenv.binutils ];
110+ dontSetConfigureCross = true;
113+ inherit bootPkgs cross;
114+ cc = "${stdenv.ccCross}/bin/${cross.config}-cc";
115+ ld = "${stdenv.binutils}/bin/${cross.config}-ld";