Skip to content

Commit a5ee00f

Browse files
hamishmackbooniepepper
authored andcommitted
Add support for setting ghcOptions on all packages (input-output-hk#1046)
`ghcOptions` has been moved from package and is now a list of strings. old: packages.x.package.ghcOptions = "someGHCoption"; new: packages.x.ghcOptions = ["someGHCoption"]; To specify ghcOptions for all packages: ghcOptions = ["someGHCoption"]; For a single component: packages.x.compoents.library.ghcOptions = ["someGHCoption"];
1 parent 4a5e00a commit a5ee00f

File tree

8 files changed

+34
-16
lines changed

8 files changed

+34
-16
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 18, 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ let
229229
type = listOfFilteringNulls str;
230230
default = (def.hardeningDisable or []);
231231
};
232+
ghcOptions = mkOption {
233+
type = listOfFilteringNulls str;
234+
default = def.ghcOptions or [];
235+
};
232236
};
233237

234238

nix/sources.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@
6666
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
6767
},
6868
"nix-tools": {
69-
"branch": "master",
69+
"branch": "hkm/global-ghc-options",
7070
"builtin": false,
7171
"description": "Translate Cabals Generic Package Description to a Nix expression",
7272
"homepage": null,
7373
"owner": "input-output-hk",
7474
"repo": "nix-tools",
75-
"rev": "f3148a55adcc9ed1361d524f94f3ccf61e2f1392",
76-
"sha256": "0796gd2mr3pwsh7rsxljsbh6z1irb2rj7vqhas59z6xbgb8jqif7",
75+
"rev": "16e3fe6ce9204bc8ac37125fb49fff71b53e0051",
76+
"sha256": "0ks14660mjkhkwjrg748928b40znza7b754kn1srf7rfnw6dscmp",
7777
"type": "tarball",
78-
"url": "https://github.com/input-output-hk/nix-tools/archive/f3148a55adcc9ed1361d524f94f3ccf61e2f1392.tar.gz",
78+
"url": "https://github.com/input-output-hk/nix-tools/archive/16e3fe6ce9204bc8ac37125fb49fff71b53e0051.tar.gz",
7979
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
8080
},
8181
"nixpkgs": {

overlays/bootstrap.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ in {
588588
final.haskell-nix.cabalProject ({
589589
name = "nix-tools";
590590
src = final.haskell-nix.sources.nix-tools;
591+
# This is a handy way to use a local git clone of nix-tools when developing
592+
# src = final.haskell-nix.haskellLib.cleanGit { name = "nix-tools"; src = ../../nix-tools; };
591593
index-state = final.haskell-nix.internalHackageIndexState;
592594
cabalProjectLocal = ''
593595
allow-newer: Cabal:base, cryptohash-sha512:base, haskeline:base

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)