git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #40996 from obsidiansystems/cross-ghc

ghc, haskell-infra: #40929 take 2

commitce0180dfd56cc00223daa5ad99d4b5611f09c542 authorJohn Ericson <Ericson2314@yahoo.com> dateFri 25 May 2018, 11:09 (9 years ago) parenta0c480afe1eec9
8 files changed+155−58
pkgs/development/compilers/ghc/7.10.3.nix+13−3 pkgs/development/compilers/ghc/8.0.2.nix+19−5 pkgs/development/compilers/ghc/8.2.2.nix+17−9 pkgs/development/compilers/ghc/8.4.2.nix+25−13 pkgs/development/compilers/ghc/head.nix+23−10 pkgs/development/haskell-modules/configuration-nix.nix+1−1 pkgs/development/haskell-modules/generic-builder.nix+55−17 pkgs/development/haskell-modules/lib.nix+2
pkgs/development/compilers/ghc/7.10.3.nix+13−3
@@ -24,6 +24,10 @@
2424, # Whether to build dynamic libs for the standard library (on the target
2525 # platform). Static libs are always built.
2626 enableShared ? true
27+
28+, # What flavour to build. An empty string indicates no
29+ # specific flavour and falls back to ghc default values.
30+ ghcFlavour ? stdenv.lib.optionalString (targetPlatform != hostPlatform) "perf-cross"
2731}:
2832
2933assert !enableIntegerSimple -> gmp != null;
@@ -42,11 +46,14 @@ let
4246 };
4347
4448 buildMK = ''
49+ BuildFlavour = ${ghcFlavour}
50+ ifneq \"\$(BuildFlavour)\" \"\"
51+ include mk/flavours/\$(BuildFlavour).mk
52+ endif
4553 DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
4654 '' + stdenv.lib.optionalString enableIntegerSimple ''
4755 INTEGER_LIBRARY = integer-simple
4856 '' + stdenv.lib.optionalString (targetPlatform != hostPlatform) ''
49− BuildFlavour = perf-cross
5057 Stage1Only = YES
5158 HADDOCK_DOCS = NO
5259 '' + stdenv.lib.optionalString enableRelocatedStaticLibs ''
@@ -68,7 +75,6 @@ let
6875 targetCC = builtins.head toolsForTarget;
6976
7077in
71−
7278stdenv.mkDerivation rec {
7379 version = "7.10.3";
7480 name = "${targetPrefix}ghc-${version}";
@@ -87,6 +93,8 @@ stdenv.mkDerivation rec {
8793 ./relocation.patch
8894 ];
8995
96+ postPatch = "patchShebangs .";
97+
9098 # GHC is a bit confused on its cross terminology.
9199 preConfigure = ''
92100 for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
@@ -103,6 +111,7 @@ stdenv.mkDerivation rec {
103111 export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"
104112 export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
105113 export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip"
114+
106115 echo -n "${buildMK}" > mk/build.mk
107116 sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
108117 '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
@@ -135,7 +144,8 @@ stdenv.mkDerivation rec {
135144 crossConfig = true;
136145
137146 nativeBuildInputs = [
138− ghc perl libxml2 libxslt docbook_xsl docbook_xml_dtd_45 docbook_xml_dtd_42 hscolour
147+ perl libxml2 libxslt docbook_xsl docbook_xml_dtd_45 docbook_xml_dtd_42
148+ ghc hscolour
139149 ];
140150
141151 # For building runtime libs
pkgs/development/compilers/ghc/8.0.2.nix+19−5
@@ -23,6 +23,10 @@
2323, # Whether to build dynamic libs for the standard library (on the target
2424 # platform). Static libs are always built.
2525 enableShared ? true
26+
27+, # What flavour to build. An empty string indicates no
28+ # specific flavour and falls back to ghc default values.
29+ ghcFlavour ? stdenv.lib.optionalString (targetPlatform != hostPlatform) "perf-cross"
2630}:
2731
2832assert !enableIntegerSimple -> gmp != null;
@@ -36,11 +40,14 @@ let
3640 "${targetPlatform.config}-";
3741
3842 buildMK = ''
43+ BuildFlavour = ${ghcFlavour}
44+ ifneq \"\$(BuildFlavour)\" \"\"
45+ include mk/flavours/\$(BuildFlavour).mk
46+ endif
3947 DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
4048 '' + stdenv.lib.optionalString enableIntegerSimple ''
4149 INTEGER_LIBRARY = integer-simple
4250 '' + stdenv.lib.optionalString (targetPlatform != hostPlatform) ''
43− BuildFlavour = perf-cross
4451 Stage1Only = YES
4552 HADDOCK_DOCS = NO
4653 '' + stdenv.lib.optionalString enableRelocatedStaticLibs ''
@@ -87,6 +94,8 @@ stdenv.mkDerivation rec {
8794 ++ stdenv.lib.optional stdenv.isDarwin ./ghc-8.0.2-no-cpp-warnings.patch
8895 ++ stdenv.lib.optional stdenv.isDarwin ./backport-dylib-command-size-limit.patch;
8996
97+ postPatch = "patchShebangs .";
98+
9099 # GHC is a bit confused on its cross terminology.
91100 preConfigure = ''
92101 for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
@@ -103,6 +112,7 @@ stdenv.mkDerivation rec {
103112 export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"
104113 export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
105114 export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip"
115+
106116 echo -n "${buildMK}" > mk/build.mk
107117 sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
108118 '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
@@ -134,7 +144,10 @@ stdenv.mkDerivation rec {
134144 # masss-rebuild.
135145 crossConfig = true;
136146
137− nativeBuildInputs = [ ghc perl hscolour sphinx ];
147+ nativeBuildInputs = [
148+ perl sphinx
149+ ghc hscolour
150+ ];
138151
139152 # For building runtime libs
140153 depsBuildTarget = toolsForTarget;
@@ -151,10 +164,11 @@ stdenv.mkDerivation rec {
151164 # that in turn causes GHCi to abort
152165 stripDebugFlags = [ "-S" ] ++ stdenv.lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols";
153166
154− # zsh and other shells are smart about `{ghc}` but bash isn't, and doesn't
155− # treat that as a unary `{x,y,z,..}` repetition.
156167 postInstall = ''
157− paxmark m $out/lib/${name}/bin/${if targetPlatform != hostPlatform then "ghc" else "{ghc,haddock}"}
168+ for bin in "$out"/lib/${name}/bin/*; do
169+ isELF "$bin" || continue
170+ paxmark m "$bin"
171+ done
158172
159173 # Install the bash completion file.
160174 install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc
pkgs/development/compilers/ghc/8.2.2.nix+17−9
@@ -23,10 +23,11 @@
2323
2424, # Whether to build dynamic libs for the standard library (on the target
2525 # platform). Static libs are always built.
26− enableShared ?
27− !(targetPlatform.isDarwin
28− # On iOS, dynamic linking is not supported
29− && (targetPlatform.isAarch64 || targetPlatform.isAarch32))
26+ enableShared ? true
27+
28+, # What flavour to build. An empty string indicates no
29+ # specific flavour and falls back to ghc default values.
30+ ghcFlavour ? stdenv.lib.optionalString (targetPlatform != hostPlatform) "perf-cross"
3031, # Whether to backport https://phabricator.haskell.org/D4388 for
3132 # deterministic profiling symbol names, at the cost of a slightly
3233 # non-standard GHC API
@@ -44,11 +45,14 @@ let
4445 "${targetPlatform.config}-";
4546
4647 buildMK = ''
48+ BuildFlavour = ${ghcFlavour}
49+ ifneq \"\$(BuildFlavour)\" \"\"
50+ include mk/flavours/\$(BuildFlavour).mk
51+ endif
4752 DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
4853 '' + stdenv.lib.optionalString enableIntegerSimple ''
4954 INTEGER_LIBRARY = integer-simple
5055 '' + stdenv.lib.optionalString (targetPlatform != hostPlatform) ''
51− BuildFlavour = perf-cross
5256 Stage1Only = YES
5357 HADDOCK_DOCS = NO
5458 BUILD_SPHINX_HTML = NO
@@ -153,7 +157,10 @@ stdenv.mkDerivation rec {
153157 # masss-rebuild.
154158 crossConfig = true;
155159
156− nativeBuildInputs = [ alex autoconf autoreconfHook automake ghc happy hscolour perl python3 sphinx ];
160+ nativeBuildInputs = [
161+ autoconf autoreconfHook automake perl python3 sphinx
162+ ghc alex happy hscolour
163+ ];
157164
158165 # For building runtime libs
159166 depsBuildTarget = toolsForTarget;
@@ -172,10 +179,11 @@ stdenv.mkDerivation rec {
172179
173180 checkTarget = "test";
174181
175− # zsh and other shells are smart about `{ghc}` but bash isn't, and doesn't
176− # treat that as a unary `{x,y,z,..}` repetition.
177182 postInstall = ''
178− paxmark m $out/lib/${name}/bin/${if targetPlatform != hostPlatform then "ghc" else "{ghc,haddock}"}
183+ for bin in "$out"/lib/${name}/bin/*; do
184+ isELF "$bin" || continue
185+ paxmark m "$bin"
186+ done
179187
180188 # Install the bash completion file.
181189 install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc
pkgs/development/compilers/ghc/8.4.2.nix+25−13
@@ -3,7 +3,7 @@
33
44# build-tools
55, bootPkgs, alex, happy
6−, autoconf, automake, coreutils, fetchurl, fetchpatch, perl, python3
6+, autoconf, automake, coreutils, fetchurl, fetchpatch, perl, python3, m4
77
88, libffi, libiconv ? null, ncurses
99
@@ -15,16 +15,21 @@
1515
1616, # If enabled, GHC will be built with the GPL-free but slower integer-simple
1717 # library instead of the faster but GPLed integer-gmp library.
18− enableIntegerSimple ? false, gmp ? null, m4
18+ enableIntegerSimple ? false, gmp ? null
1919
2020, # If enabled, use -fPIC when compiling static libs.
2121 enableRelocatedStaticLibs ? targetPlatform != hostPlatform
2222
2323, # Whether to build dynamic libs for the standard library (on the target
2424 # platform). Static libs are always built.
25− enableShared ? !targetPlatform.useAndroidPrebuilt
25+ enableShared ? !targetPlatform.isWindows && !targetPlatform.useAndroidPrebuilt
2626
27−, version ? "8.4.2"
27+, # Whetherto build terminfo.
28+ enableTerminfo ? !targetPlatform.isWindows
29+
30+, # What flavour to build. An empty string indicates no
31+ # specific flavour and falls back to ghc default values.
32+ ghcFlavour ? stdenv.lib.optionalString (targetPlatform != hostPlatform) "perf-cross"
2833}:
2934
3035assert !enableIntegerSimple -> gmp != null;
@@ -38,11 +43,14 @@ let
3843 "${targetPlatform.config}-";
3944
4045 buildMK = ''
46+ BuildFlavour = ${ghcFlavour}
47+ ifneq \"\$(BuildFlavour)\" \"\"
48+ include mk/flavours/\$(BuildFlavour).mk
49+ endif
4150 DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
4251 '' + stdenv.lib.optionalString enableIntegerSimple ''
4352 INTEGER_LIBRARY = integer-simple
4453 '' + stdenv.lib.optionalString (targetPlatform != hostPlatform) ''
45− BuildFlavour = perf-cross
4654 Stage1Only = YES
4755 HADDOCK_DOCS = NO
4856 BUILD_SPHINX_HTML = NO
@@ -55,9 +63,9 @@ let
5563 '';
5664
5765 # Splicer will pull out correct variations
58− libDeps = platform: [ ncurses ]
66+ libDeps = platform: stdenv.lib.optional enableTerminfo [ ncurses ]
5967 ++ stdenv.lib.optional (!enableIntegerSimple) gmp
60− ++ stdenv.lib.optional (platform.libc != "glibc") libiconv;
68+ ++ stdenv.lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;
6169
6270 toolsForTarget =
6371 if hostPlatform == buildPlatform then
@@ -69,7 +77,7 @@ let
6977
7078in
7179stdenv.mkDerivation rec {
72− inherit version;
80+ version = "8.4.2";
7381 name = "${targetPrefix}ghc-${version}";
7482
7583 src = fetchurl {
@@ -126,7 +134,7 @@ stdenv.mkDerivation rec {
126134 "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
127135 ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && ! enableIntegerSimple) [
128136 "--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
129− ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc") [
137+ ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
130138 "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
131139 ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
132140 "--enable-bootstrap-with-devel-snapshot"
@@ -144,7 +152,10 @@ stdenv.mkDerivation rec {
144152 # masss-rebuild.
145153 crossConfig = true;
146154
147− nativeBuildInputs = [ ghc perl autoconf automake m4 happy alex python3 ];
155+ nativeBuildInputs = [
156+ perl autoconf automake m4 python3
157+ ghc alex happy
158+ ];
148159
149160 # For building runtime libs
150161 depsBuildTarget = toolsForTarget;
@@ -163,10 +174,11 @@ stdenv.mkDerivation rec {
163174
164175 checkTarget = "test";
165176
166− # zsh and other shells are smart about `{ghc}` but bash isn't, and doesn't
167− # treat that as a unary `{x,y,z,..}` repetition.
168177 postInstall = ''
169− paxmark m $out/lib/${name}/bin/${if targetPlatform != hostPlatform then "ghc" else "{ghc,haddock}"}
178+ for bin in "$out"/lib/${name}/bin/*; do
179+ isELF "$bin" || continue
180+ paxmark m "$bin"
181+ done
170182
171183 # Install the bash completion file.
172184 install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc
pkgs/development/compilers/ghc/head.nix+23−10
@@ -3,7 +3,7 @@
33
44# build-tools
55, bootPkgs, alex, happy
6−, autoconf, automake, coreutils, fetchgit, perl, python3
6+, autoconf, automake, coreutils, fetchgit, perl, python3, m4
77
88, libffi, libiconv ? null, ncurses
99
@@ -22,9 +22,15 @@
2222
2323, # Whether to build dynamic libs for the standard library (on the target
2424 # platform). Static libs are always built.
25− enableShared ? !targetPlatform.useAndroidPrebuilt
25+ enableShared ? !targetPlatform.isWindows && !targetPlatform.useAndroidPrebuilt
26+
27+, # Whetherto build terminfo.
28+ enableTerminfo ? !targetPlatform.isWindows
2629
2730, version ? "8.5.20180118"
31+, # What flavour to build. An empty string indicates no
32+ # specific flavour and falls back to ghc default values.
33+ ghcFlavour ? stdenv.lib.optionalString (targetPlatform != hostPlatform) "perf-cross"
2834}:
2935
3036assert !enableIntegerSimple -> gmp != null;
@@ -38,11 +44,14 @@ let
3844 "${targetPlatform.config}-";
3945
4046 buildMK = ''
47+ BuildFlavour = ${ghcFlavour}
48+ ifneq \"\$(BuildFlavour)\" \"\"
49+ include mk/flavours/\$(BuildFlavour).mk
50+ endif
4151 DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
4252 '' + stdenv.lib.optionalString enableIntegerSimple ''
4353 INTEGER_LIBRARY = integer-simple
4454 '' + stdenv.lib.optionalString (targetPlatform != hostPlatform) ''
45− BuildFlavour = perf-cross
4655 Stage1Only = YES
4756 HADDOCK_DOCS = NO
4857 BUILD_SPHINX_HTML = NO
@@ -55,9 +64,9 @@ let
5564 '';
5665
5766 # Splicer will pull out correct variations
58− libDeps = platform: [ ncurses ]
67+ libDeps = platform: stdenv.lib.optional enableTerminfo [ ncurses ]
5968 ++ stdenv.lib.optional (!enableIntegerSimple) gmp
60− ++ stdenv.lib.optional (platform.libc != "glibc") libiconv;
69+ ++ stdenv.lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;
6170
6271 toolsForTarget =
6372 if hostPlatform == buildPlatform then
@@ -123,7 +132,7 @@ stdenv.mkDerivation rec {
123132 "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
124133 ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && ! enableIntegerSimple) [
125134 "--with-gmp-includes=${gmp.dev}/include" "--with-gmp-libraries=${gmp.out}/lib"
126− ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc") [
135+ ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
127136 "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
128137 ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
129138 "--enable-bootstrap-with-devel-snapshot"
@@ -141,7 +150,10 @@ stdenv.mkDerivation rec {
141150 # masss-rebuild.
142151 crossConfig = true;
143152
144− nativeBuildInputs = [ ghc perl autoconf automake happy alex python3 ];
153+ nativeBuildInputs = [
154+ perl autoconf automake m4 python3
155+ ghc alex happy
156+ ];
145157
146158 # For building runtime libs
147159 depsBuildTarget = toolsForTarget;
@@ -160,10 +172,11 @@ stdenv.mkDerivation rec {
160172
161173 checkTarget = "test";
162174
163− # zsh and other shells are smart about `{ghc}` but bash isn't, and doesn't
164− # treat that as a unary `{x,y,z,..}` repetition.
165175 postInstall = ''
166− paxmark m $out/lib/${name}/bin/${if targetPlatform != hostPlatform then "ghc" else "{ghc,haddock}"}
176+ for bin in "$out"/lib/${name}/bin/*; do
177+ isELF "$bin" || continue
178+ paxmark m "$bin"
179+ done
167180
168181 # Install the bash completion file.
169182 install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc
pkgs/development/haskell-modules/configuration-nix.nix+1−1
@@ -128,7 +128,7 @@ self: super: builtins.intersectAttrs super {
128128
129129 # Prevents needing to add security_tool as a build tool to all of x509-system's
130130 # dependencies.
131− x509-system = if pkgs.stdenv.isDarwin && !pkgs.stdenv.cc.nativeLibc
131+ x509-system = if pkgs.stdenv.targetPlatform.isDarwin && !pkgs.stdenv.cc.nativeLibc
132132 then let inherit (pkgs.darwin) security_tool;
133133 in pkgs.lib.overrideDerivation (addBuildDepend super.x509-system security_tool) (drv: {
134134 postPatch = (drv.postPatch or "") + ''
pkgs/development/haskell-modules/generic-builder.nix+55−17
@@ -19,6 +19,7 @@ in
1919, buildTarget ? ""
2020, buildTools ? [], libraryToolDepends ? [], executableToolDepends ? [], testToolDepends ? [], benchmarkToolDepends ? []
2121, configureFlags ? []
22+, buildFlags ? []
2223, description ? ""
2324, doCheck ? !isCross && stdenv.lib.versionOlder "7.4" ghc.version
2425, doBenchmark ? false
@@ -31,7 +32,7 @@ in
3132, enableSharedExecutables ? false
3233, enableSharedLibraries ? ((ghc.isGhcjs or false) || stdenv.lib.versionOlder "7.7" ghc.version)
3334, enableDeadCodeElimination ? (!stdenv.isDarwin) # TODO: use -dead_strip for darwin
34−, enableStaticLibraries ? true
35+, enableStaticLibraries ? !hostPlatform.isWindows
3536, enableHsc2hsViaAsm ? hostPlatform.isWindows && stdenv.lib.versionAtLeast ghc.version "8.4"
3637, extraLibraries ? [], librarySystemDepends ? [], executableSystemDepends ? []
3738, homepage ? "http://hackage.haskell.org/package/${pname}"
@@ -68,6 +69,10 @@ in
6869
6970assert editedCabalFile != null -> revision != null;
7071
72+# --enable-static does not work on windows. This is a bug in GHC.
73+# --enable-static will pass -staticlib to ghc, which only works for mach-o and elf.
74+assert hostPlatform.isWindows -> enableStaticLibraries == false;
75+
7176let
7277
7378 inherit (stdenv.lib) optional optionals optionalString versionOlder versionAtLeast
@@ -126,6 +131,8 @@ let
126131 crossCabalFlagsString =
127132 stdenv.lib.optionalString isCross (" " + stdenv.lib.concatStringsSep " " crossCabalFlags);
128133
134+ buildFlagsString = optionalString (buildFlags != []) (" " + concatStringsSep " " buildFlags);
135+
129136 defaultConfigureFlags = [
130137 "--verbose" "--prefix=$out" "--libdir=\\$prefix/lib/\\$compiler" "--libsubdir=\\$pkgid"
131138 (optionalString enableSeparateDataOutput "--datadir=$data/share/${ghc.name}")
@@ -169,18 +176,22 @@ let
169176 optionals doCheck testPkgconfigDepends ++ optionals doBenchmark benchmarkPkgconfigDepends;
170177
171178 nativeBuildInputs = [ ghc nativeGhc removeReferencesTo ] ++ optional (allPkgconfigDepends != []) pkgconfig ++
179+ setupHaskellDepends ++
172180 buildTools ++ libraryToolDepends ++ executableToolDepends;
173181 propagatedBuildInputs = buildDepends ++ libraryHaskellDepends ++ executableHaskellDepends;
174− otherBuildInputs = setupHaskellDepends ++ extraLibraries ++ librarySystemDepends ++ executableSystemDepends ++
182+ otherBuildInputs = extraLibraries ++ librarySystemDepends ++ executableSystemDepends ++
175183 allPkgconfigDepends ++
176184 optionals doCheck (testDepends ++ testHaskellDepends ++ testSystemDepends ++ testToolDepends) ++
177185 optionals doBenchmark (benchmarkDepends ++ benchmarkHaskellDepends ++ benchmarkSystemDepends ++ benchmarkToolDepends);
186+
178187 allBuildInputs = propagatedBuildInputs ++ otherBuildInputs;
179188
180189 haskellBuildInputs = stdenv.lib.filter isHaskellPkg allBuildInputs;
181190 systemBuildInputs = stdenv.lib.filter isSystemPkg allBuildInputs;
182191
183− ghcEnv = ghc.withPackages (p: haskellBuildInputs);
192+ # When not cross compiling, also include Setup.hs dependencies.
193+ ghcEnv = ghc.withPackages (p:
194+ haskellBuildInputs ++ stdenv.lib.optional (!isCross) setupHaskellDepends);
184195
185196 setupCommand = "./Setup";
186197
@@ -190,6 +201,22 @@ let
190201
191202 nativeGhcCommand = "${nativeGhc.targetPrefix}ghc";
192203
204+ buildPkgDb = ghcName: ''
205+ if [ -d "$p/lib/${ghcName}/package.conf.d" ]; then
206+ cp -f "$p/lib/${ghcName}/package.conf.d/"*.conf $packageConfDir/
207+ continue
208+ fi
209+ if [ -d "$p/include" ]; then
210+ configureFlags+=" --extra-include-dirs=$p/include"
211+ fi
212+ if [ -d "$p/lib" ]; then
213+ configureFlags+=" --extra-lib-dirs=$p/lib"
214+ fi
215+ if [[ -d "$p/Library/Frameworks" ]]; then
216+ configureFlags+=" --extra-framework-dirs=$p/Library/Frameworks"
217+ fi
218+ '';
219+
193220in
194221
195222assert allPkgconfigDepends != [] -> pkgconfig != null;
@@ -230,30 +257,37 @@ stdenv.mkDerivation ({
230257 echo "Build with ${ghc}."
231258 ${optionalString (hasActiveLibrary && hyperlinkSource) "export PATH=${hscolour}/bin:$PATH"}
232259
260+ '' + (optionalString (setupHaskellDepends != []) ''
261+ setupPackageConfDir="$TMPDIR/setup-package.conf.d"
262+ mkdir -p $setupPackageConfDir
263+ '') + ''
233264 packageConfDir="$TMPDIR/package.conf.d"
234265 mkdir -p $packageConfDir
235266
236267 setupCompileFlags="${concatStringsSep " " setupCompileFlags}"
237268 configureFlags="${concatStringsSep " " defaultConfigureFlags} $configureFlags"
269+ ''
270+ # We build the Setup.hs on the *build* machine, and as such should only add
271+ # dependencies for the build machine.
272+ #
273+ # pkgs* arrays defined in stdenv/setup.hs
274+ + (optionalString (setupHaskellDepends != []) ''
275+ for p in "''${pkgsBuildBuild[@]}" "''${pkgsBuildHost[@]}" "''${pkgsBuildTarget[@]}"; do
276+ ${buildPkgDb nativeGhc.name}
277+ done
278+ ${nativeGhcCommand}-pkg --${nativePackageDbFlag}="$setupPackageConfDir" recache
279+ '')
238280
239− # host.*Pkgs defined in stdenv/setup.hs
281+ # For normal components
282+ + ''
240283 for p in "''${pkgsHostHost[@]}" "''${pkgsHostTarget[@]}"; do
241− if [ -d "$p/lib/${ghc.name}/package.conf.d" ]; then
242− cp -f "$p/lib/${ghc.name}/package.conf.d/"*.conf $packageConfDir/
243− continue
244− fi
245− if [ -d "$p/include" ]; then
246− configureFlags+=" --extra-include-dirs=$p/include"
247− fi
248− if [ -d "$p/lib" ]; then
249− configureFlags+=" --extra-lib-dirs=$p/lib"
250− fi
284+ ${buildPkgDb ghc.name}
251285 done
252286 ''
253287 # only use the links hack if we're actually building dylibs. otherwise, the
254288 # "dynamic-library-dirs" point to nonexistent paths, and the ln command becomes
255289 # "ln -s $out/lib/links", which tries to recreate the links dir and fails
256− + (optionalString (stdenv.isDarwin && enableSharedLibraries) ''
290+ + (optionalString (stdenv.isDarwin && (enableSharedLibraries || enableSharedExecutables)) ''
257291 # Work around a limit in the macOS Sierra linker on the number of paths
258292 # referenced by any one dynamic library:
259293 #
@@ -282,7 +316,11 @@ stdenv.mkDerivation ({
282316 done
283317
284318 echo setupCompileFlags: $setupCompileFlags
285− ${nativeGhcCommand} $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i
319+ ${optionalString (setupHaskellDepends != [])
320+ ''
321+ echo GHC_PACKAGE_PATH="$setupPackageConfDir:"
322+ GHC_PACKAGE_PATH="$setupPackageConfDir:" ''
323+ }${nativeGhcCommand} $setupCompileFlags --make -o Setup -odir $TMPDIR -hidir $TMPDIR $i
286324
287325 runHook postCompileBuildDriver
288326 '';
@@ -310,7 +348,7 @@ stdenv.mkDerivation ({
310348
311349 buildPhase = ''
312350 runHook preBuild
313− ${setupCommand} build ${buildTarget}${crossCabalFlagsString}
351+ ${setupCommand} build ${buildTarget}${crossCabalFlagsString}${buildFlagsString}
314352 runHook postBuild
315353 '';
316354
pkgs/development/haskell-modules/lib.nix+2
@@ -131,6 +131,8 @@ rec {
131131 */
132132 appendConfigureFlag = drv: x: overrideCabal drv (drv: { configureFlags = (drv.configureFlags or []) ++ [x]; });
133133
134+ appendBuildFlag = drv: x: overrideCabal drv (drv: { buildFlags = (drv.buildFlags or []) ++ [x]; });
135+ appendBuildFlags = drv: xs: overrideCabal drv (drv: { buildFlags = (drv.buildFlags or []) ++ xs; });
134136 /* removeConfigureFlag drv x is a Haskell package like drv, but with
135137 all cabal configure arguments that are equal to x removed.
136138