Skip to content

Add compiler-nix-name to cabalProject #610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ If your project has a `cabal.project` you can add a `default.nix` like this:

```nix
{ pkgs ? import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {}).nixpkgsArgs
, haskellCompiler ? "ghc865"
, compiler-nix-name ? "ghc865"
}:
pkgs.haskell-nix.cabalProject {
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
ghc = pkgs.buildPackages.pkgs.haskell-nix.compiler.${haskellCompiler};
inherit compiler-nix-name;
# pkg-def-extras = [
# # Additional packages ontop of all those listed in `cabal.project`
# ];
Expand Down
30 changes: 26 additions & 4 deletions lib/call-cabal-project-to-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
, materialized ? null # Location of a materialized copy of the nix files
, checkMaterialization ? null # If true the nix files will be generated used to check plan-sha256 and material
, cabalProject ? null # Cabal project file (when null uses "${src}/cabal.project")
, ghc ? defaults.ghc
, compiler-nix-name ? null # Nix name of the ghc compiler as a string eg. "ghc883"
, ghc ? null # Deprecated in favour of `compiler-nix-name`
, ghcOverride ? null # Used when we need to set ghc explicitly during bootstrapping
, nix-tools ? defaults.nix-tools
, hpack ? defaults.hpack
, cabal-install ? defaults.cabal-install
Expand All @@ -31,11 +33,31 @@ assert (if (builtins.compareVersions cabal-install.version "2.4.0.0") < 0
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"
else true);

assert (if ghc.isHaskellNixCompiler or false then true
else throw ("It is likely you used `haskell.compiler.X` instead of `haskell-nix.compiler.X`"
+ pkgs.lib.optionalString (name != null) (" for " + name)));
let
forName = pkgs.lib.optionalString (name != null) (" for " + name);

ghc' =
if ghcOverride != null
then ghcOverride
else
if ghc != null
then __trace ("WARNING: A `ghc` argument was passed" + forName
+ " this has been deprecated in favour of `compiler-nix-name`. "
+ "Using `ghc` will break cross compilation setups, as haskell.nix can not"
+ "pick the correct `ghc` package from the respective buildPackages. "
+ "For example use `compiler-nix-name = \"ghc865\";` for ghc 8.6.5") ghc
else
if compiler-nix-name != null
then pkgs.buildPackages.haskell-nix.compiler."${compiler-nix-name}"
else defaults.ghc;

in
assert (if ghc'.isHaskellNixCompiler or false then true
else throw ("It is likely you used `haskell.compiler.X` instead of `haskell-nix.compiler.X`"
+ forName));

let
ghc = ghc';
maybeCleanedSource =
if haskellLib.canCleanSource src
then haskellLib.cleanSourceWith {
Expand Down
6 changes: 3 additions & 3 deletions overlays/bootstrap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ in {
# to build ghcs from source.
alex-project = hackage-project {
# Only a boot compiler is suitable here
ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
ghcOverride = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
inherit (bootstrap.packages) cabal-install nix-tools hpack;
name = "alex"; version = "3.2.4";
index-state = final.haskell-nix.internalHackageIndexState;
Expand All @@ -393,7 +393,7 @@ in {
alex = bootstrap.packages.alex-project.hsPkgs.alex.components.exes.alex;
happy-project = hackage-project {
# Only a boot compiler is suitable here
ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
ghcOverride = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
inherit (bootstrap.packages) cabal-install nix-tools hpack;
name = "happy"; version = "1.19.11";
index-state = final.haskell-nix.internalHackageIndexState;
Expand All @@ -402,7 +402,7 @@ in {
happy = bootstrap.packages.happy-project.hsPkgs.happy.components.exes.happy;
hscolour-project = hackage-project {
# Only a boot compiler is suitable here
ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
ghcOverride = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; };
inherit (bootstrap.packages) cabal-install nix-tools hpack;
name = "hscolour"; version = "1.24.4";
index-state = final.haskell-nix.internalHackageIndexState;
Expand Down
2 changes: 1 addition & 1 deletion overlays/ghc-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ in rec {
if __pathExists materializedPath
then materializedPath
else null;
ghc = final.buildPackages.haskell-nix.compiler.${ghcName};
ghcOverride = final.buildPackages.haskell-nix.compiler.${ghcName};
configureArgs = "--disable-tests"; # avoid failures satisfying bytestring package tests dependencies
})
ghc-extra-pkgs-cabal-projects;
Expand Down
5 changes: 4 additions & 1 deletion overlays/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,10 @@ final: prev: {
{ plan-pkgs = plan.pkgs;
pkg-def-extras = args.pkg-def-extras or [];
modules = (args.modules or [])
++ final.lib.optional (args ? ghc) { ghc.package = args.ghc; };
++ final.lib.optional (args ? ghcOverride || args ? ghc)
{ ghc.package = args.ghcOverride or args.ghc; }
++ final.lib.optional (args ? compiler-nix-name)
{ compiler.nix-name = args.compiler-nix-name; };
extra-hackages = args.extra-hackages or [];
};
in { inherit (pkg-set.config) hsPkgs; inherit pkg-set; plan-nix = plan.nix; };
Expand Down
5 changes: 5 additions & 0 deletions test/compiler-nix-name/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{-# LANGUAGE CPP #-}
module Main where

main :: IO ()
main = print __GLASGOW_HASKELL__
11 changes: 11 additions & 0 deletions test/compiler-nix-name/compiler-nix-name.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cabal-version: >=1.10
name: compiler-nix-name
version: 0.1.0.0
license: PublicDomain
author: Hamish Mackenzie
build-type: Simple

executable compiler-nix-name
main-is: Main.hs
build-depends: base >=4.13 && <4.14
default-language: Haskell2010
40 changes: 40 additions & 0 deletions test/compiler-nix-name/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ stdenv, haskell-nix, recurseIntoAttrs, testSrc }:

with stdenv.lib;

let
project = haskell-nix.cabalProject' {
src = testSrc "compiler-nix-name";
compiler-nix-name = "ghc883";
};

packages = project.hsPkgs;
compiler-nix-name =
packages.compiler-nix-name.components.exes.compiler-nix-name;

in recurseIntoAttrs {
ifdInputs = {
inherit (project) plan-nix;
};

run = stdenv.mkDerivation {
name = "compiler-nix-name-test";

buildCommand = ''
exe="${compiler-nix-name}/bin/compiler-nix-name${stdenv.hostPlatform.extensions.executable}"
if [[ "$(${toString compiler-nix-name.config.testWrapper} $exe)" != "808" ]]; then
echo "Unexpected GHC version" >& 2
false
else
touch $out
fi
'';

meta.platforms = platforms.all;

passthru = {
# Used for debugging with nix repl
inherit project packages;
};
};
}
1 change: 1 addition & 0 deletions test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ let
stack-source-repo = callTest ./stack-source-repo {};
lookup-sha256 = callTest ./lookup-sha256 {};
extra-hackage = callTest ./extra-hackage {};
compiler-nix-name = callTest ./compiler-nix-name {};

unit = unitTests;
};
Expand Down