on iko/ghcjs-patch-master help sign in
Give more control over the compilation of Setup.hs (#277)

Allows adding of overrides through package.components.setup. I need this to specify frameworks that Setup.hs needs on macOS.

commite15c59ba2eba05936c14bfb0ba9adea5e47e850f authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateThu 31 Oct 2019, 19:15 (7 years ago) parentccd1349
4 files changed+39−23
builder/default.nix+1 builder/hspkg-builder.nix+4−1 builder/setup-builder.nix+13−22 modules/package.nix+21
builder/default.nix+1
@@ -9,6 +9,7 @@ let
99 setup-builder = haskellLib.weakCallPackage pkgs ./setup-builder.nix {
1010 ghc = (ghc.passthru.buildGHC or ghc);
1111 hsPkgs = hsPkgs.buildPackages;
12+ inherit buildPackages pkgconfig;
1213 inherit haskellLib nonReinstallablePkgs makeSetupConfigFiles;
1314 };
1415
builder/hspkg-builder.nix+4−1
@@ -39,7 +39,10 @@ let
3939 setup = if package.buildType == "Simple" && package.setup-depends == []
4040 then defaultSetup
4141 else setup-builder {
42− setup-depends = package.setup-depends;
42+ component = components.setup // {
43+ depends = components.setup.depends ++ package.setup-depends;
44+ extraSrcFiles = components.setup.extraSrcFiles ++ [ "Setup.hs" "Setup.lhs" ];
45+ };
4346 inherit package name src flags revision patches defaultSetupSrc;
4447 inherit (config) preUnpack postUnpack;
4548 };
builder/setup-builder.nix+13−22
@@ -1,33 +1,15 @@
1−{ stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles }:
1+{ stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles, pkgconfig }:
22
3−{ setup-depends, package, name, src, flags, revision, patches, defaultSetupSrc
3+{ component, package, name, src, flags, revision, patches, defaultSetupSrc
44, preUnpack ? null, postUnpack ? null
55}:
66
77let
8− component = {
9− depends = setup-depends;
10− libs = [];
11− frameworks = [];
12− doExactConfig = false;
13− # We have to set hsSourceDirs or cleanCabalComponent will
14− # include everything (and as a result all the components of
15− # the package will depend on eveything in the package).
16− # TODO find a better way
17− hsSourceDirs = ["setup-src"];
18− includeDirs = [];
19− asmSources = [];
20− cSources = [];
21− cmmSources = [];
22− cxxSources = [];
23− jsSources = [];
24− extraSrcFiles = [ "Setup.hs" "Setup.lhs" ];
25− };
268 cleanSrc = haskellLib.cleanCabalComponent package component src;
279
2810 fullName = "${name}-setup";
2911
30− includeGhcPackage = lib.any (p: p.identifier.name == "ghc") setup-depends;
12+ includeGhcPackage = lib.any (p: p.identifier.name == "ghc") component.depends;
3113
3214 configFiles = makeSetupConfigFiles {
3315 inherit (package) identifier;
@@ -37,12 +19,21 @@ let
3719 inherit preUnpack postUnpack;
3820 };
3921
22+ executableToolDepends =
23+ (lib.concatMap (c: if c.isHaskell or false
24+ then builtins.attrValues (c.components.exes or {})
25+ else [c]) component.build-tools) ++
26+ lib.optional (component.pkgconfig != []) pkgconfig;
27+
4028in
4129 stdenv.lib.fix (drv:
4230 stdenv.mkDerivation ({
4331 name = "${fullName}";
4432 src = cleanSrc;
45− nativeBuildInputs = [ghc];
33+ buildInputs = component.libs
34+ ++ component.frameworks
35+ ++ builtins.concatLists component.pkgconfig;
36+ nativeBuildInputs = [ghc] ++ executableToolDepends;
4637
4738 passthru = {
4839 inherit (package) identifier;
modules/package.nix+21
@@ -213,6 +213,27 @@ in {
213213 };
214214 };
215215 in {
216+ setup = mkOption {
217+ type = nullOr componentType;
218+ default = {
219+ depends = [];
220+ libs = [];
221+ frameworks = [];
222+ doExactConfig = false;
223+ # We have to set hsSourceDirs or cleanCabalComponent will
224+ # include everything (and as a result all the components of
225+ # the package will depend on eveything in the package).
226+ # TODO find a better way
227+ hsSourceDirs = ["setup-src"];
228+ includeDirs = [];
229+ asmSources = [];
230+ cSources = [];
231+ cmmSources = [];
232+ cxxSources = [];
233+ jsSources = [];
234+ extraSrcFiles = [ "Setup.hs" "Setup.lhs" ];
235+ };
236+ };
216237 library = mkOption {
217238 type = nullOr componentType;
218239 default = null;