@@ -39,37 +39,28 @@ let
3939
4040 defaultSetupSrc = if stdenv.hostPlatform.isGhcjs then ./Setup.ghcjs.hs else ./Setup.hs;
4141
42− # Get the Cabal lib used to build `cabal-install`.
43− # To avoid infinite recursion we have to leave this out for packages
44− # needed to build `cabal-install`.
45− # We always do this for ghcjs as the patched version of Cabal is needed.
46− cabalLibDepends = lib.optional (
47− stdenv.hostPlatform.isGhcjs || (
48− !builtins.elem package.identifier.name
49− ["nix-tools" "alex" "happy" "hscolour" "Cabal" "bytestring" "aeson" "time"
50− "filepath" "base-compat-batteries" "base-compat" "unix" "directory" "transformers"
51− "containers" "binary" "mtl" "text" "process" "parsec"]
52− )
53− )
54− buildPackages.haskell-nix.cabal-install-unchecked.${compiler-nix-name}.project.hsPkgs.Cabal.components.library;
42+ # This is the `Cabal` library that was built for `cabal-install` to use.
43+ # It makes sense to use this version (when possible) because it will match the behavior of
44+ # building with `cabal-install` (including fixes that may not be in the
45+ # version of Cabal bundled with GHC).
46+ cabalFromCabalInstall = buildPackages.haskell-nix.cabal-install-unchecked.${compiler-nix-name}.project.hsPkgs.Cabal.components.library;
5547
56− # This logic is needed so that we don't get duplicate packages if we
57− # add a custom Cabal package to the dependencies. That way custom
58− # setups won't complain about e.g. binary from the Cabal dependencies
59− # and binary from the global package-db.
60− nonReinstallablePkgs = if (
61− stdenv.hostPlatform.isGhcjs || (
48+ # Check there is no chance we are building `cabalFromCabalInstall`. Using `cabalFromCabalInstall`
49+ # to build itseld would cause infinite recursion.
50+ useCabalFromCabalInstall =
51+ # `cabalFromCabalInstall` is not cross compiled
52+ stdenv.buildPlatform != stdenv.hostPlatform
53+ ||
54+ # These are the dependencies of `Cabal`
6255 !builtins.elem package.identifier.name
6356 ["nix-tools" "alex" "happy" "hscolour" "Cabal" "bytestring" "aeson" "time"
6457 "filepath" "base-compat-batteries" "base-compat" "unix" "directory" "transformers"
65− "containers" "binary" "mtl" "text" "process" "parsec"]
66− )
67− ) then [] else null;
58+ "containers" "binary" "mtl" "text" "process" "parsec"];
6859
6960 defaultSetup = setup-builder ({
7061 name = "${ghc.targetPrefix}default-Setup";
7162 component = {
72− depends = config.setup-depends ++ cabalLibDepends;
63+ depends = config.setup-depends ++ lib.optional useCabalFromCabalInstall cabalFromCabalInstall;
7364 libs = [];
7465 frameworks = [];
7566 doExactConfig = false;
@@ -103,7 +94,13 @@ let
10394 cat ${defaultSetupSrc} > $out/Setup.hs
10495 '';
10596 inherit defaultSetupSrc;
106− } // (if nonReinstallablePkgs == null then {} else { inherit nonReinstallablePkgs; }));
97+ } // lib.optionalAttrs useCabalFromCabalInstall {
98+ # This is needed so that we don't get duplicate packages when we
99+ # add a custom Cabal package to the dependencies. That way custom
100+ # setups won't complain about e.g. binary from the Cabal dependencies
101+ # and binary from the global package-db.
102+ nonReinstallablePkgs = [];
103+ });
107104
108105 # buildPackages.runCommand "default-Setup" { nativeBuildInputs = [(ghc.passthru.buildGHC or ghc)]; } ''
109106 # cat ${defaultSetupSrc} > Setup.hs
@@ -134,7 +131,7 @@ in rec {
134131 checks = pkgs.recurseIntoAttrs (builtins.mapAttrs
135132 (_: d: haskellLib.check d)
136133 (lib.filterAttrs (_: d: d.config.doCheck) components.tests));
137− inherit (package) identifier detailLevel isLocal isProject;
134+ inherit (package) identifier detailLevel isLocal isProject buildType;
138135 inherit setup cabalFile;
139136 isHaskell = true;
140137 inherit src;