Skip to content

Commit 14fa435

Browse files
committed
Add support for setting ghcOptions on all packages
1 parent ba87ffb commit 14fa435

File tree

6 files changed

+29
-12
lines changed

6 files changed

+29
-12
lines changed

builder/comp-builder.nix

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ let self =
4040
&& !(stdenv.hostPlatform.isMusl && !stdenv.hostPlatform.isx86)
4141
, enableDeadCodeElimination ? component.enableDeadCodeElimination
4242

43+
, ghcOptions ? component.ghcOptions
44+
4345
# Options for Haddock generation
4446
, doHaddock ? component.doHaddock # Enable haddock and hoogle generation
4547
, doHoogle ? component.doHoogle # Also build a hoogle index
@@ -180,10 +182,9 @@ let
180182
++ lib.optionals useLLVM [
181183
"--ghc-option=-fPIC" "--gcc-option=-fPIC"
182184
]
185+
++ map (o: ''--ghc${lib.optionalString (stdenv.hostPlatform.isGhcjs) "js"}-options="${o}"'') ghcOptions
183186
);
184187

185-
setupGhcOptions = lib.optional (package.ghcOptions != null) '' --ghc${lib.optionalString (stdenv.hostPlatform.isGhcjs) "js"}-options="${package.ghcOptions}"'';
186-
187188
executableToolDepends =
188189
(lib.concatMap (c: if c.isHaskell or false
189190
then builtins.attrValues (c.components.exes or {})
@@ -258,7 +259,7 @@ let
258259

259260
haddock = haddockBuilder {
260261
inherit componentId component package flags commonConfigureFlags
261-
commonAttrs revision setupGhcOptions doHaddock
262+
commonAttrs revision doHaddock
262263
doHoogle hyperlinkSource quickjump setupHaddockFlags
263264
needsProfiling configFiles preHaddock postHaddock pkgconfig;
264265

@@ -336,7 +337,7 @@ let
336337
buildPhase = ''
337338
runHook preBuild
338339
# https://gitlab.haskell.org/ghc/ghc/issues/9221
339-
$SETUP_HS build ${haskellLib.componentTarget componentId} -j$(($NIX_BUILD_CORES > 4 ? 4 : $NIX_BUILD_CORES)) ${lib.concatStringsSep " " (setupBuildFlags ++ setupGhcOptions)}
340+
$SETUP_HS build ${haskellLib.componentTarget componentId} -j$(($NIX_BUILD_CORES > 4 ? 4 : $NIX_BUILD_CORES)) ${lib.concatStringsSep " " setupBuildFlags}
340341
runHook postBuild
341342
'';
342343

builder/haddock-builder.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
, hyperlinkSource
1717
, quickjump
1818
, setupHaddockFlags
19-
, setupGhcOptions
2019

2120
, needsProfiling
2221
, componentDrv
@@ -108,7 +107,7 @@ let
108107
${lib.optionalString doHoogle "--hoogle"} \
109108
${lib.optionalString hyperlinkSource "--hyperlink-source"} \
110109
${lib.optionalString quickjump "--quickjump"} \
111-
${lib.concatStringsSep " " (setupHaddockFlags ++ setupGhcOptions)}
110+
${lib.concatStringsSep " " setupHaddockFlags}
112111
}
113112
runHook postHaddock
114113
'';

changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
This file contains a summary of changes to Haskell.nix and `nix-tools`
22
that will impact users.
33

4+
## Feb 17, 2021
5+
* `ghcOptions` has been moved from package and is now a list of strings.
6+
old: packages.x.package.ghcOptions = "someGHCoption";
7+
new: packages.x.ghcOptions = ["someGHCoption"];
8+
To specify ghcOptions for all packages:
9+
ghcOptions = ["someGHCoption"];
10+
For a single component:
11+
packages.x.compoents.library.ghcOptions = ["someGHCoption"];
12+
413
## Feb 8, 2021
514
* Removed older versions of haskell-language-server from custom-tools
615
(0.8.0 is in hackage so we can still get that version).

modules/package.nix

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ in {
136136
type = bool;
137137
default = false;
138138
};
139-
140-
ghcOptions = mkOption {
141-
type = nullOr str;
142-
default = null;
143-
};
144139
};
145140

146141
components = let

modules/plan.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ let
229229
type = listOfFilteringNulls str;
230230
default = (def.hardeningDisable or []);
231231
};
232+
ghcOptions = mkOption {
233+
type = listOfFilteringNulls str;
234+
default = def.ghcOptions or [];
235+
merge = a: b: __trace "HELLO";
236+
};
232237
};
233238

234239

test/ghc-options/cabal.nix

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ let
88
index-state = "2020-05-25T00:00:00Z";
99
src = testSrc "ghc-options";
1010
# TODO find a way to get the ghc-options into plan.json so we can use it in plan-to-nix
11-
modules = [ { packages.test-ghc-options.package.ghcOptions = "-DTEST_GHC_OPTION"; } ];
11+
modules = [ {
12+
packages.test-ghc-options.ghcOptions = ["-DTEST_GHC_OPTION"];
13+
14+
# This should also work here
15+
# ghcOptions = ["-DTEST_GHC_OPTION"];
16+
# or this
17+
# packages.test-ghc-options.components.library.ghcOptions = ["-DTEST_GHC_OPTION"];
18+
# packages.test-ghc-options.components.exes.test-ghc-options-exe.ghcOptions = ["-DTEST_GHC_OPTION"];
19+
} ];
1220
};
1321
packages = project.hsPkgs;
1422

0 commit comments

Comments
 (0)