Add support for setting ghcOptions on all packages (#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"];
This commit is contained in:
Hamish Mackenzie 2021-02-19 00:38:36 +13:00 committed by GitHub
parent cb95d533b8
commit 42b10678ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 16 deletions

View File

@ -40,6 +40,8 @@ let self =
&& !(stdenv.hostPlatform.isMusl && !stdenv.hostPlatform.isx86)
, enableDeadCodeElimination ? component.enableDeadCodeElimination
, ghcOptions ? component.ghcOptions
# Options for Haddock generation
, doHaddock ? component.doHaddock # Enable haddock and hoogle generation
, doHoogle ? component.doHoogle # Also build a hoogle index
@ -180,10 +182,9 @@ let
++ lib.optionals useLLVM [
"--ghc-option=-fPIC" "--gcc-option=-fPIC"
]
++ map (o: ''--ghc${lib.optionalString (stdenv.hostPlatform.isGhcjs) "js"}-options="${o}"'') ghcOptions
);
setupGhcOptions = lib.optional (package.ghcOptions != null) '' --ghc${lib.optionalString (stdenv.hostPlatform.isGhcjs) "js"}-options="${package.ghcOptions}"'';
executableToolDepends =
(lib.concatMap (c: if c.isHaskell or false
then builtins.attrValues (c.components.exes or {})
@ -258,7 +259,7 @@ let
haddock = haddockBuilder {
inherit componentId component package flags commonConfigureFlags
commonAttrs revision setupGhcOptions doHaddock
commonAttrs revision doHaddock
doHoogle hyperlinkSource quickjump setupHaddockFlags
needsProfiling configFiles preHaddock postHaddock pkgconfig;
@ -336,7 +337,7 @@ let
buildPhase = ''
runHook preBuild
# https://gitlab.haskell.org/ghc/ghc/issues/9221
$SETUP_HS build ${haskellLib.componentTarget componentId} -j$(($NIX_BUILD_CORES > 4 ? 4 : $NIX_BUILD_CORES)) ${lib.concatStringsSep " " (setupBuildFlags ++ setupGhcOptions)}
$SETUP_HS build ${haskellLib.componentTarget componentId} -j$(($NIX_BUILD_CORES > 4 ? 4 : $NIX_BUILD_CORES)) ${lib.concatStringsSep " " setupBuildFlags}
runHook postBuild
'';

View File

@ -16,7 +16,6 @@
, hyperlinkSource
, quickjump
, setupHaddockFlags
, setupGhcOptions
, needsProfiling
, componentDrv
@ -108,7 +107,7 @@ let
${lib.optionalString doHoogle "--hoogle"} \
${lib.optionalString hyperlinkSource "--hyperlink-source"} \
${lib.optionalString quickjump "--quickjump"} \
${lib.concatStringsSep " " (setupHaddockFlags ++ setupGhcOptions)}
${lib.concatStringsSep " " setupHaddockFlags}
}
runHook postHaddock
'';

View File

@ -1,6 +1,15 @@
This file contains a summary of changes to Haskell.nix and `nix-tools`
that will impact users.
## Feb 18, 2021
* `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"];
## Feb 8, 2021
* Removed older versions of haskell-language-server from custom-tools
(0.8.0 is in hackage so we can still get that version).

View File

@ -136,11 +136,6 @@ in {
type = bool;
default = false;
};
ghcOptions = mkOption {
type = nullOr str;
default = null;
};
};
components = let

View File

@ -229,6 +229,10 @@ let
type = listOfFilteringNulls str;
default = (def.hardeningDisable or []);
};
ghcOptions = mkOption {
type = listOfFilteringNulls str;
default = def.ghcOptions or [];
};
};

View File

@ -66,16 +66,16 @@
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nix-tools": {
"branch": "master",
"branch": "hkm/global-ghc-options",
"builtin": false,
"description": "Translate Cabals Generic Package Description to a Nix expression",
"homepage": null,
"owner": "input-output-hk",
"repo": "nix-tools",
"rev": "f3148a55adcc9ed1361d524f94f3ccf61e2f1392",
"sha256": "0796gd2mr3pwsh7rsxljsbh6z1irb2rj7vqhas59z6xbgb8jqif7",
"rev": "16e3fe6ce9204bc8ac37125fb49fff71b53e0051",
"sha256": "0ks14660mjkhkwjrg748928b40znza7b754kn1srf7rfnw6dscmp",
"type": "tarball",
"url": "https://github.com/input-output-hk/nix-tools/archive/f3148a55adcc9ed1361d524f94f3ccf61e2f1392.tar.gz",
"url": "https://github.com/input-output-hk/nix-tools/archive/16e3fe6ce9204bc8ac37125fb49fff71b53e0051.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {

View File

@ -588,6 +588,8 @@ in {
final.haskell-nix.cabalProject ({
name = "nix-tools";
src = final.haskell-nix.sources.nix-tools;
# This is a handy way to use a local git clone of nix-tools when developing
# src = final.haskell-nix.haskellLib.cleanGit { name = "nix-tools"; src = ../../nix-tools; };
index-state = final.haskell-nix.internalHackageIndexState;
cabalProjectLocal = ''
allow-newer: Cabal:base, cryptohash-sha512:base, haskeline:base

View File

@ -8,7 +8,15 @@ let
index-state = "2020-05-25T00:00:00Z";
src = testSrc "ghc-options";
# TODO find a way to get the ghc-options into plan.json so we can use it in plan-to-nix
modules = [ { packages.test-ghc-options.package.ghcOptions = "-DTEST_GHC_OPTION"; } ];
modules = [ {
packages.test-ghc-options.ghcOptions = ["-DTEST_GHC_OPTION"];
# This should also work here
# ghcOptions = ["-DTEST_GHC_OPTION"];
# or this
# packages.test-ghc-options.components.library.ghcOptions = ["-DTEST_GHC_OPTION"];
# packages.test-ghc-options.components.exes.test-ghc-options-exe.ghcOptions = ["-DTEST_GHC_OPTION"];
} ];
};
packages = project.hsPkgs;