@@ -68,11 +68,15 @@ let
6868
6969 # TODO check if this posible fix for segfaults works or not.
7070 targetLibffi =
71+ # on native platforms targetPlatform.{libffi, gmp} do not exist; thus fall back
72+ # to the non-targetPlatform version in those cases.
73+ let targetLibffi = targetPackages.libffi or libffi; in
74+ # we need to set `dontDisableStatic` for musl for libffi to work.
7175 if stdenv.targetPlatform.isMusl
72− then targetPackages.libffi.overrideAttrs (old: { dontDisableStatic = true; })
73− else if targetPlatform != hostPlatform
74− then targetPackages.libffi
75− else libffi;
76+ then targetLibffi.overrideAttrs (old: { dontDisableStatic = true; })
77+ else targetLibffi;
78+
79+ targetGmp = targetPackages.gmp or gmp;
7680
7781 # TODO(@Ericson2314) Make unconditional
7882 targetPrefix = stdenv.lib.optionalString
@@ -195,16 +199,14 @@ in let configured-src = stdenv.mkDerivation (rec {
195199 done
196200 '';
197201
198− # TODO(@Ericson2314): Always pass "--target" and always prefix.
199− configurePlatforms = [ "build" "host" ]
200− ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
202+ configurePlatforms = [ "build" "host" "target" ];
201203 # `--with` flags for libraries needed for RTS linker
202204 configureFlags = [
203205 "--datadir=$doc/share/doc/ghc"
204206 "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
205207 ] ++ stdenv.lib.optionals (targetLibffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetLibffi.dev}/include" "--with-ffi-libraries=${targetLibffi.out}/lib"
206208 ] ++ stdenv.lib.optional (!enableIntegerSimple) [
207− "--with-gmp-includes=${targetPackages.gmp.dev}/include" "--with-gmp-libraries=${targetPackages.gmp.out}/lib"
209+ "--with-gmp-includes=${targetGmp.dev}/include" "--with-gmp-libraries=${targetGmp.out}/lib"
208210 ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
209211 "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
210212 ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [