on iko/ghcjs-patch-master help sign in
Check ghc used is haskell-nix.compiler one (#312)

It is easy to mistakenly pass in a `haskell.compiler.ghcXXX` compiler instead of a `haskell-nix.compiler.ghcXXX` one. This leads to subtle bugs (for instance missing Cabal library patch).

commit7d96b156c53bc86f3ad79d8588575ee0dc774f3c authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateMon 11 Nov 2019, 01:01 (7 years ago) parent3c78559
4 files changed+24−5
builder/hspkg-builder.nix+4 compiler/ghc/default.nix+3 lib/call-cabal-project-to-nix.nix+5 overlays/bootstrap.nix+12−5
builder/hspkg-builder.nix+4
@@ -18,6 +18,10 @@
1818, ...
1919}@config:
2020
21+assert (if ghc.isHaskellNixCompiler or false then true
22+ else throw ("It is likely you used `haskell.compiler.X` instead of `haskell-nix.compiler.X`"
23+ + pkgs.lib.optionalString (name != null) (" for " + name)));
24+
2125let
2226 cabalFile = if revision == null || revision == 0 then null else
2327 fetchurl {
compiler/ghc/default.nix+3
@@ -310,6 +310,9 @@ in stdenv.mkDerivation (rec {
310310 haskellCompilerName = "ghc-${version}";
311311
312312 configured-src = configured-src;
313+
314+ # Used to detect non haskell-nix compilers (accedental use of nixpkgs compilers can lead to unexpected errors)
315+ isHaskellNixCompiler = true;
313316 } // extra-passthru;
314317
315318 meta = {
lib/call-cabal-project-to-nix.nix+5
@@ -16,6 +16,11 @@
1616assert (if (builtins.compareVersions cabal-install.version "2.4.0.0") < 0
1717 then throw "cabal-install (current version: ${cabal-install.version}) needs to be at least 2.4 for plan-to-nix to work without cabal-to-nix"
1818 else true);
19+
20+assert (if ghc.isHaskellNixCompiler or false then true
21+ else throw ("It is likely you used `haskell.compiler.X` instead of `haskell-nix.compiler.X`"
22+ + pkgs.lib.optionalString (name != null) (" for " + name)));
23+
1924let
2025 maybeCleanedSource =
2126 if haskellLib.canCleanSource src
overlays/bootstrap.nix+12−5
@@ -229,7 +229,10 @@ self: super: {
229229 # this is not ideal!
230230 # get binary compilers for bootstrapping. We'll put the eventual proper
231231 # compilers into the same place where nix expects them.
232− compiler = import ../compiler/old-ghc-nix { pkgs = self; };
232+ # We mark these compilers as boot compilers to make sure they are only used
233+ # where a boot compiler is expected.
234+ compiler = builtins.mapAttrs (_: v: v // { isHaskellNixBootCompiler = true; })
235+ (import ../compiler/old-ghc-nix { pkgs = self; });
233236
234237 packages = {
235238 # cabal has it's own bootstrap script which we'll use.
@@ -246,7 +249,8 @@ self: super: {
246249 # disable hpack support during bootstrap
247250 hpack = null;
248251 nix-tools = nix-tools.override {
249− inherit ghc;
252+ # Only a boot compiler is suitable here
253+ ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
250254 inherit (bootstrap.packages) hpack;
251255 };
252256
@@ -256,7 +260,8 @@ self: super: {
256260 # need to use the boot strap compiler as we need them
257261 # to build ghcs from source.
258262 alex-project = hackage-project {
259− inherit ghc;
263+ # Only a boot compiler is suitable here
264+ ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
260265 inherit (bootstrap.packages) cabal-install nix-tools hpack;
261266 name = "alex"; version = "3.2.4";
262267 index-state = "2019-10-20T00:00:00Z";
@@ -264,7 +269,8 @@ self: super: {
264269 };
265270 alex = bootstrap.packages.alex-project.alex.components.exes.alex;
266271 happy-project = hackage-project {
267− inherit ghc;
272+ # Only a boot compiler is suitable here
273+ ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
268274 inherit (bootstrap.packages) cabal-install nix-tools hpack;
269275 name = "happy"; version = "1.19.11";
270276 index-state = "2019-10-20T00:00:00Z";
@@ -272,7 +278,8 @@ self: super: {
272278 };
273279 happy = bootstrap.packages.happy-project.happy.components.exes.happy;
274280 hscolour-project = hackage-project {
275− inherit ghc;
281+ # Only a boot compiler is suitable here
282+ ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
276283 inherit (bootstrap.packages) cabal-install nix-tools hpack;
277284 name = "hscolour"; version = "1.24.4";
278285 index-state = "2019-10-20T00:00:00Z";