Skip to content

Commit efab350

Browse files
hamishmackangerman
authored andcommitted
Fix setup-depends dependencies (#124)
* Use setup-depends from nix-tools output * Use `-package ghc` when building Setup.hs * Include --package-db when building Setup * Fix for tests on case insensitive FS (macOS) The file `conduit.hs` looks like `Conduit.hs` to ghc and it uses it by mistake for `import Conduit`.
1 parent 4c2cc47 commit efab350

File tree

8 files changed

+246
-206
lines changed

8 files changed

+246
-206
lines changed

builder/default.nix

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ let
66
inherit ghc haskellLib makeConfigFiles ghcForComponent hsPkgs;
77
};
88

9+
setup-builder = haskellLib.weakCallPackage pkgs ./setup-builder.nix {
10+
ghc = buildGHC;
11+
hsPkgs = hsPkgs.buildPackages;
12+
inherit haskellLib nonReinstallablePkgs makeSetupConfigFiles;
13+
};
14+
915
# Wraps GHC to provide dependencies in a way that works for both the
1016
# component builder and for nix-shells.
1117
ghcForComponent = import ./ghc-for-component-wrapper.nix {
@@ -19,6 +25,12 @@ let
1925
makeConfigFiles = haskellLib.weakCallPackage pkgs ./make-config-files.nix {
2026
inherit ghc haskellLib nonReinstallablePkgs;
2127
};
28+
# When building setup depends we need to use the build systems GHC and Packages
29+
makeSetupConfigFiles = haskellLib.weakCallPackage buildPackages ./make-config-files.nix {
30+
inherit haskellLib nonReinstallablePkgs;
31+
ghc = buildGHC;
32+
};
33+
2234

2335
hoogleLocal = let
2436
nixpkgsHoogleLocal = import (pkgs.path + /pkgs/development/haskell-modules/hoogle.nix);
@@ -45,7 +57,7 @@ in {
4557
# Build a Haskell package from its config.
4658
# TODO: this pkgs is the adjusted pkgs, but pkgs.pkgs is unadjusted
4759
build-package = haskellLib.weakCallPackage pkgs ./hspkg-builder.nix {
48-
inherit haskellLib ghc buildGHC comp-builder;
60+
inherit haskellLib ghc buildGHC comp-builder setup-builder;
4961
};
5062

5163
inherit shellFor;

builder/hspkg-builder.nix

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ pkgs, buildPackages, stdenv, lib, haskellLib, ghc, buildGHC, fetchurl, runCommand, pkgconfig, comp-builder }:
1+
{ pkgs, buildPackages, stdenv, lib, haskellLib, ghc, buildGHC, fetchurl, runCommand, comp-builder, setup-builder }:
22

33

44
{ flags
@@ -38,26 +38,9 @@ let
3838

3939
setup = if package.buildType == "Simple"
4040
then defaultSetup
41-
else stdenv.mkDerivation {
42-
name = "${name}-setup";
43-
nativeBuildInputs = [buildGHC];
44-
inherit src;
45-
phases = ["unpackPhase" "buildPhase" "installPhase"];
46-
buildPhase = ''
47-
for f in Setup.hs Setup.lhs; do
48-
if [ -f $f ]; then
49-
echo Compiling package $f
50-
ghc $f --make -o ./Setup
51-
setup=$(pwd)/Setup
52-
fi
53-
done
54-
[ -f ./Setup ] || (echo Failed to build Setup && exit 1)
55-
'';
56-
57-
installPhase = ''
58-
mkdir -p $out/bin
59-
install ./Setup $out/bin/Setup
60-
'';
41+
else setup-builder {
42+
setup-depends = package.setup-depends;
43+
inherit package name src flags;
6144
};
6245

6346
buildComp = componentId: component: comp-builder {

builder/setup-builder.nix

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{ stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles }:
2+
3+
{ setup-depends, package, name, src, flags }:
4+
5+
let
6+
fullName = "${name}-setup";
7+
8+
includeGhcPackage = lib.any (p: p.identifier.name == "ghc") setup-depends;
9+
10+
configFiles = makeSetupConfigFiles {
11+
inherit (package) identifier;
12+
inherit fullName flags;
13+
component = {
14+
depends = setup-depends;
15+
libs = [];
16+
frameworks = [];
17+
doExactConfig = false;
18+
};
19+
};
20+
21+
in
22+
stdenv.lib.fix (drv:
23+
stdenv.mkDerivation {
24+
name = "${fullName}";
25+
inherit src;
26+
nativeBuildInputs = [ghc];
27+
28+
CABAL_CONFIG = configFiles + /cabal.config;
29+
phases = ["unpackPhase" "buildPhase" "installPhase"];
30+
buildPhase = ''
31+
for f in Setup.hs Setup.lhs; do
32+
if [ -f $f ]; then
33+
echo Compiling package $f
34+
ghc $f '' + (if includeGhcPackage then "-package ghc " else "")
35+
+ ''-package-db ${configFiles}/package.conf.d --make -o ./Setup
36+
setup=$(pwd)/Setup
37+
fi
38+
done
39+
[ -f ./Setup ] || (echo Failed to build Setup && exit 1)
40+
'';
41+
42+
installPhase = ''
43+
mkdir -p $out/bin
44+
install ./Setup $out/bin/Setup
45+
'';
46+
})

nix-tools/.plan.nix/nix-tools.nix

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix-tools/default.nix

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ lib, symlinkJoin, makeWrapper
1+
{ pkgs, lib, symlinkJoin, makeWrapper
22
, hpack, git, nix, nix-prefetch-git
33
, fetchExternal, cleanSourceHaskell, mkCabalProjectPkgSet }:
44

@@ -8,6 +8,14 @@ let
88
specJSON = ./nix-tools-src.json;
99
override = "nix-tools-src";
1010
});
11+
# we need to patch Cabal, as its data directory logic is broken for component builds, which haskell.nix
12+
# uses excessively. See issue https://github.com/haskell/cabal/issues/5862, and the fix for Cabal 3.0
13+
# in https://github.com/haskell/cabal/pull/6055. We apply the haskell/cabal#6055 here.
14+
cabalPatch = pkgs.fetchpatch {
15+
url = "https://patch-diff.githubusercontent.com/raw/haskell/cabal/pull/6055.diff";
16+
sha256 = "145g7s3z9q8d18pxgyngvixgsm6gmwh1rgkzkhacy4krqiq0qyvx";
17+
stripLen = 1;
18+
};
1119

1220
pkgSet = mkCabalProjectPkgSet {
1321
plan-pkgs = import ./pkgs.nix;
@@ -22,6 +30,12 @@ let
2230
{
2331
packages.nix-tools.src = src;
2432
}
33+
34+
({ config, ...}: {
35+
packages = {
36+
Cabal.patches = [ cabalPatch ];
37+
};
38+
})
2539
];
2640
};
2741

0 commit comments

Comments
 (0)