diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index 31a3c57c02..574fd51437 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -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 ''; diff --git a/builder/haddock-builder.nix b/builder/haddock-builder.nix index e582d93503..21440c3916 100644 --- a/builder/haddock-builder.nix +++ b/builder/haddock-builder.nix @@ -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 ''; diff --git a/changelog.md b/changelog.md index f49ed7e72f..4a7927dcfd 100644 --- a/changelog.md +++ b/changelog.md @@ -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). diff --git a/modules/package.nix b/modules/package.nix index dc72329ebd..e700996a28 100644 --- a/modules/package.nix +++ b/modules/package.nix @@ -136,11 +136,6 @@ in { type = bool; default = false; }; - - ghcOptions = mkOption { - type = nullOr str; - default = null; - }; }; components = let diff --git a/modules/plan.nix b/modules/plan.nix index 857637392f..34ddcc9e8a 100644 --- a/modules/plan.nix +++ b/modules/plan.nix @@ -229,6 +229,10 @@ let type = listOfFilteringNulls str; default = (def.hardeningDisable or []); }; + ghcOptions = mkOption { + type = listOfFilteringNulls str; + default = def.ghcOptions or []; + }; }; diff --git a/nix/sources.json b/nix/sources.json index 9591d4cdf9..6d57cc0966 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -66,16 +66,16 @@ "url_template": "https://github.com///archive/.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///archive/.tar.gz" }, "nixpkgs": { diff --git a/overlays/bootstrap.nix b/overlays/bootstrap.nix index e9f5f2453b..6d8bfb95e5 100644 --- a/overlays/bootstrap.nix +++ b/overlays/bootstrap.nix @@ -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 diff --git a/test/ghc-options/cabal.nix b/test/ghc-options/cabal.nix index f39e9106fa..7cd65ed4c6 100644 --- a/test/ghc-options/cabal.nix +++ b/test/ghc-options/cabal.nix @@ -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;