on iko/ghcjs-patch-master help sign in
Add compiler-nix-name to cabalProject (#610)
788e198Hamish Mackenzie
docs/user-guide.md+2−2
@@ -94,11 +94,11 @@ If your project has a `cabal.project` you can add a `default.nix` like this:
94
94
95```nix
95```nix
96{ pkgs ? import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {}).nixpkgsArgs
96{ pkgs ? import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {}).nixpkgsArgs
97−, haskellCompiler ? "ghc865"
97+, compiler-nix-name ? "ghc865"
98}:
98}:
99 pkgs.haskell-nix.cabalProject {
99 pkgs.haskell-nix.cabalProject {
100 src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
100 src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
101− ghc = pkgs.buildPackages.pkgs.haskell-nix.compiler.${haskellCompiler};
101+ inherit compiler-nix-name;
102 # pkg-def-extras = [
102 # pkg-def-extras = [
103 # # Additional packages ontop of all those listed in `cabal.project`
103 # # Additional packages ontop of all those listed in `cabal.project`
104 # ];
104 # ];
lib/call-cabal-project-to-nix.nix+26−4
@@ -7,7 +7,9 @@
7, materialized ? null # Location of a materialized copy of the nix files
7, materialized ? null # Location of a materialized copy of the nix files
8, checkMaterialization ? null # If true the nix files will be generated used to check plan-sha256 and material
8, checkMaterialization ? null # If true the nix files will be generated used to check plan-sha256 and material
9, cabalProject ? null # Cabal project file (when null uses "${src}/cabal.project")
9, cabalProject ? null # Cabal project file (when null uses "${src}/cabal.project")
10−, ghc ? defaults.ghc
10+, compiler-nix-name ? null # Nix name of the ghc compiler as a string eg. "ghc883"
11+, ghc ? null # Deprecated in favour of `compiler-nix-name`
12+, ghcOverride ? null # Used when we need to set ghc explicitly during bootstrapping
11, nix-tools ? defaults.nix-tools
13, nix-tools ? defaults.nix-tools
12, hpack ? defaults.hpack
14, hpack ? defaults.hpack
13, cabal-install ? defaults.cabal-install
15, cabal-install ? defaults.cabal-install
@@ -31,11 +33,31 @@ assert (if (builtins.compareVersions cabal-install.version "2.4.0.0") < 0
31 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"
33 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"
32 else true);
34 else true);
33
35
36+let
37+ forName = pkgs.lib.optionalString (name != null) (" for " + name);
38+
39+ ghc' =
40+ if ghcOverride != null
41+ then ghcOverride
42+ else
43+ if ghc != null
44+ then __trace ("WARNING: A `ghc` argument was passed" + forName
45+ + " this has been deprecated in favour of `compiler-nix-name`. "
46+ + "Using `ghc` will break cross compilation setups, as haskell.nix can not"
47+ + "pick the correct `ghc` package from the respective buildPackages. "
48+ + "For example use `compiler-nix-name = \"ghc865\";` for ghc 8.6.5") ghc
49+ else
50+ if compiler-nix-name != null
51+ then pkgs.buildPackages.haskell-nix.compiler."${compiler-nix-name}"
52+ else defaults.ghc;
53+
54+in
34−assert (if ghc.isHaskellNixCompiler or false then true
55+ assert (if ghc'.isHaskellNixCompiler or false then true
35− else throw ("It is likely you used `haskell.compiler.X` instead of `haskell-nix.compiler.X`"
56+ else throw ("It is likely you used `haskell.compiler.X` instead of `haskell-nix.compiler.X`"
36− + pkgs.lib.optionalString (name != null) (" for " + name)));
57+ + forName));
37
58
38let
59let
60+ ghc = ghc';
39 maybeCleanedSource =
61 maybeCleanedSource =
40 if haskellLib.canCleanSource src
62 if haskellLib.canCleanSource src
41 then haskellLib.cleanSourceWith {
63 then haskellLib.cleanSourceWith {
overlays/bootstrap.nix+3−3
@@ -384,7 +384,7 @@ in {
384 # to build ghcs from source.
384 # to build ghcs from source.
385 alex-project = hackage-project {
385 alex-project = hackage-project {
386 # Only a boot compiler is suitable here
386 # Only a boot compiler is suitable here
387− ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
387+ ghcOverride = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
388 inherit (bootstrap.packages) cabal-install nix-tools hpack;
388 inherit (bootstrap.packages) cabal-install nix-tools hpack;
389 name = "alex"; version = "3.2.4";
389 name = "alex"; version = "3.2.4";
390 index-state = final.haskell-nix.internalHackageIndexState;
390 index-state = final.haskell-nix.internalHackageIndexState;
@@ -393,7 +393,7 @@ in {
393 alex = bootstrap.packages.alex-project.hsPkgs.alex.components.exes.alex;
393 alex = bootstrap.packages.alex-project.hsPkgs.alex.components.exes.alex;
394 happy-project = hackage-project {
394 happy-project = hackage-project {
395 # Only a boot compiler is suitable here
395 # Only a boot compiler is suitable here
396− ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
396+ ghcOverride = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
397 inherit (bootstrap.packages) cabal-install nix-tools hpack;
397 inherit (bootstrap.packages) cabal-install nix-tools hpack;
398 name = "happy"; version = "1.19.11";
398 name = "happy"; version = "1.19.11";
399 index-state = final.haskell-nix.internalHackageIndexState;
399 index-state = final.haskell-nix.internalHackageIndexState;
@@ -402,7 +402,7 @@ in {
402 happy = bootstrap.packages.happy-project.hsPkgs.happy.components.exes.happy;
402 happy = bootstrap.packages.happy-project.hsPkgs.happy.components.exes.happy;
403 hscolour-project = hackage-project {
403 hscolour-project = hackage-project {
404 # Only a boot compiler is suitable here
404 # Only a boot compiler is suitable here
405− ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
405+ ghcOverride = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
406 inherit (bootstrap.packages) cabal-install nix-tools hpack;
406 inherit (bootstrap.packages) cabal-install nix-tools hpack;
407 name = "hscolour"; version = "1.24.4";
407 name = "hscolour"; version = "1.24.4";
408 index-state = final.haskell-nix.internalHackageIndexState;
408 index-state = final.haskell-nix.internalHackageIndexState;
overlays/ghc-packages.nix+1−1
@@ -172,7 +172,7 @@ in rec {
172 if __pathExists materializedPath
172 if __pathExists materializedPath
173 then materializedPath
173 then materializedPath
174 else null;
174 else null;
175− ghc = final.buildPackages.haskell-nix.compiler.${ghcName};
175+ ghcOverride = final.buildPackages.haskell-nix.compiler.${ghcName};
176 configureArgs = "--disable-tests"; # avoid failures satisfying bytestring package tests dependencies
176 configureArgs = "--disable-tests"; # avoid failures satisfying bytestring package tests dependencies
177 })
177 })
178 ghc-extra-pkgs-cabal-projects;
178 ghc-extra-pkgs-cabal-projects;
overlays/haskell.nix+4−1
@@ -463,7 +463,10 @@ final: prev: {
463 { plan-pkgs = plan.pkgs;
463 { plan-pkgs = plan.pkgs;
464 pkg-def-extras = args.pkg-def-extras or [];
464 pkg-def-extras = args.pkg-def-extras or [];
465 modules = (args.modules or [])
465 modules = (args.modules or [])
466− ++ final.lib.optional (args ? ghc) { ghc.package = args.ghc; };
466+ ++ final.lib.optional (args ? ghcOverride || args ? ghc)
467+ { ghc.package = args.ghcOverride or args.ghc; }
468+ ++ final.lib.optional (args ? compiler-nix-name)
469+ { compiler.nix-name = args.compiler-nix-name; };
467 extra-hackages = args.extra-hackages or [];
470 extra-hackages = args.extra-hackages or [];
468 };
471 };
469 in { inherit (pkg-set.config) hsPkgs; inherit pkg-set; plan-nix = plan.nix; };
472 in { inherit (pkg-set.config) hsPkgs; inherit pkg-set; plan-nix = plan.nix; };
test/compiler-nix-name/Main.hsnew file+5
@@ -0,0 +1,5 @@
1+{-# LANGUAGE CPP #-}
2+module Main where
3+
4+main :: IO ()
5+main = print __GLASGOW_HASKELL__
test/compiler-nix-name/compiler-nix-name.cabalnew file+11
@@ -0,0 +1,11 @@
1+cabal-version: >=1.10
2+name: compiler-nix-name
3+version: 0.1.0.0
4+license: PublicDomain
5+author: Hamish Mackenzie
6+build-type: Simple
7+
8+executable compiler-nix-name
9+ main-is: Main.hs
10+ build-depends: base >=4.13 && <4.14
11+ default-language: Haskell2010
test/compiler-nix-name/default.nixnew file+40
@@ -0,0 +1,40 @@
1+{ stdenv, haskell-nix, recurseIntoAttrs, testSrc }:
2+
3+with stdenv.lib;
4+
5+let
6+ project = haskell-nix.cabalProject' {
7+ src = testSrc "compiler-nix-name";
8+ compiler-nix-name = "ghc883";
9+ };
10+
11+ packages = project.hsPkgs;
12+ compiler-nix-name =
13+ packages.compiler-nix-name.components.exes.compiler-nix-name;
14+
15+in recurseIntoAttrs {
16+ ifdInputs = {
17+ inherit (project) plan-nix;
18+ };
19+
20+ run = stdenv.mkDerivation {
21+ name = "compiler-nix-name-test";
22+
23+ buildCommand = ''
24+ exe="${compiler-nix-name}/bin/compiler-nix-name${stdenv.hostPlatform.extensions.executable}"
25+ if [[ "$(${toString compiler-nix-name.config.testWrapper} $exe)" != "808" ]]; then
26+ echo "Unexpected GHC version" >& 2
27+ false
28+ else
29+ touch $out
30+ fi
31+ '';
32+
33+ meta.platforms = platforms.all;
34+
35+ passthru = {
36+ # Used for debugging with nix repl
37+ inherit project packages;
38+ };
39+ };
40+}
test/default.nix+1
@@ -176,6 +176,7 @@ let
176 stack-source-repo = callTest ./stack-source-repo {};
176 stack-source-repo = callTest ./stack-source-repo {};
177 lookup-sha256 = callTest ./lookup-sha256 {};
177 lookup-sha256 = callTest ./lookup-sha256 {};
178 extra-hackage = callTest ./extra-hackage {};
178 extra-hackage = callTest ./extra-hackage {};
179+ compiler-nix-name = callTest ./compiler-nix-name {};
179
180
180 unit = unitTests;
181 unit = unitTests;
181 };
182 };