@@ -28,10 +28,10 @@ let
2828 in map ({val,...}: val) closure;
2929
3030 exactDep = pdbArg: p: ''
31− if id=$(ghc-pkg ${pdbArg} field ${p} id --simple-output); then
31+ if id=$(${ghc.targetPrefix}ghc-pkg ${pdbArg} field ${p} id --simple-output); then
3232 echo "--dependency=${p}=$id" >> $out/configure-flags
3333 fi
34− if ver=$(ghc-pkg ${pdbArg} field ${p} version --simple-output); then
34+ if ver=$(${ghc.targetPrefix}ghc-pkg ${pdbArg} field ${p} version --simple-output); then
3535 echo "constraint: ${p} == $ver" >> $out/cabal.config
3636 echo "constraint: ${p} installed" >> $out/cabal.config
3737 fi
@@ -39,7 +39,7 @@ let
3939
4040 configFiles = runCommand "${fullName}-config" { nativeBuildInputs = [ghc]; } (''
4141 mkdir -p $out
42− ghc-pkg init $out/package.conf.d
42+ ${ghc.targetPrefix}ghc-pkg init $out/package.conf.d
4343
4444 ${lib.concatStringsSep "\n" (lib.mapAttrsToList flagsAndConfig {
4545 "extra-lib-dirs" = map (p: "${p}/lib") component.libs;
@@ -48,7 +48,7 @@ let
4848 })}
4949
5050 ${lib.concatMapStringsSep "\n" (p: ''
51− ghc-pkg --package-db ${p}/package.conf.d dump | ghc-pkg --force --package-db $out/package.conf.d register -
51+ ${ghc.targetPrefix}ghc-pkg --package-db ${p}/package.conf.d dump | ${ghc.targetPrefix}ghc-pkg --force --package-db $out/package.conf.d register -
5252 '') flatDepends}
5353 ${flagsAndConfig "package-db" ["$out/package.conf.d"]}
5454
@@ -63,13 +63,20 @@ let
6363 ${lib.concatMapStringsSep "\n" (exactDep "") nonReinstallablePkgs}
6464
6565 '' + ''
66− ghc-pkg --package-db $out/package.conf.d check
66+ ${ghc.targetPrefix}ghc-pkg --package-db $out/package.conf.d check
6767 '');
6868
6969 finalConfigureFlags = lib.concatStringsSep " " (
70− [ "--prefix=$out" "${componentId.ctype}:${componentId.cname}" ]
71− ++ ["$(cat ${configFiles}/configure-flags)"]
72− ++ component.configureFlags
70+ [ "--prefix=$out"
71+ "${componentId.ctype}:${componentId.cname}"
72+ "$(cat ${configFiles}/configure-flags)"
73+ "--with-ghc=${ghc.targetPrefix}ghc"
74+ "--with-ghc-pkg=${ghc.targetPrefix}ghc-pkg"
75+ "--with-hsc2hs=${ghc.targetPrefix}hsc2hs"
76+ ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) (
77+ ["--hsc2hs-option=--cross-compile"]
78+ ++ lib.optional (package.buildType == "Configure") "--configure-option=--host=${stdenv.hostPlatform.config}"
79+ ) ++ component.configureFlags
7380 );
7481
7582in stdenv.mkDerivation {
@@ -131,8 +138,8 @@ in stdenv.mkDerivation {
131138 $SETUP_HS copy
132139 ${lib.optionalString (haskellLib.isLibrary componentId) ''
133140 $SETUP_HS register --gen-pkg-config=${name}.conf
134− ghc-pkg init $out/package.conf.d
135− ghc-pkg --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register ${name}.conf
141+ ${ghc.targetPrefix}ghc-pkg init $out/package.conf.d
142+ ${ghc.targetPrefix}ghc-pkg --package-db ${configFiles}/package.conf.d -f $out/package.conf.d register ${name}.conf
136143 ''}
137144 '';
138145}