Skip to content

Add haskell-nix.project (and project') #703

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 9 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
44 changes: 44 additions & 0 deletions overlays/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,50 @@ final: prev: {
shells.ghc = p.hsPkgs.shellFor {};
};

# `project'` and `project` automatically select between `cabalProject`
# and `stackProject` (when possible) by looking for `stack.yaml` or
# `cabal.project` files. If both exist we can pass in one of:
# `projectFileName = "stack.yaml;"`
# `projectFileName = "cabal.project";`
# to let it know which to choose (or pick another name). If the
# selected file ends in a `.yaml` it is assumed to be for `stackProject`.
# If niether `stack.yaml` nor `cabal.project` exist `cabalProject` is
# used (as it will use a default `cabal.project`).
project' = { src, projectFileName ? null, ... }@args:
let
dir = __readDir (src.origSrcSubDir or src);
exists = fileName: builtins.elem (dir.${fileName} or "") ["regular" "symlink"];
stackYamlExists = exists "stack.yaml";
cabalProjectExists = exists "cabal.project";
selectedFileName =
if projectFileName != null
then projectFileName # Prefer the user selected project file name
else
if stackYamlExists && cabalProjectExists
then null # If both exist we will throw an error
else
if stackYamlExists
then "stack.yaml" # stack needs a stack.yaml
else "cabal.project"; # the cabal.project file is optional
in
assert (
if selectedFileName != null then true
else throw ("haskell-nix.project : both `stack.yaml` and `cabal.project` files exist "
+ "set `projectFileName = \"stack.yaml\";` or `projectFileName = \"cabal.project\";`"));
if final.lib.hasSuffix ".yaml" selectedFileName
then stackProject' (args // { stackYaml = selectedFileName; })
else cabalProject' (args // { cabalProjectFileName = selectedFileName; });

# This is the same as the `cabalPackage` and `stackPackage` wrappers
# for `cabalPackage` and `stackPackage`.
project = args: let p = project' args;
in p.hsPkgs // {
# Provide `nix-shell -A shells.ghc` for users migrating from the reflex-platform.
# But we should encourage use of `nix-shell -A shellFor`
shells.ghc = p.hsPkgs.shellFor {};
} // final.lib.optionalAttrs (p ? stack-nix) { inherit (p) stack-nix; }
// final.lib.optionalAttrs (p ? plan-nix ) { inherit (p) plan-nix; };

# Like `cabalProject'`, but for building the GHCJS compiler.
# This is exposed to allow GHCJS developers to work on the GHCJS
# code in a nix-shell with `shellFor`.
Expand Down
4 changes: 2 additions & 2 deletions test/cabal-simple/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Test a package set
{ stdenv, util, mkCabalProjectPkgSet, cabalProject', haskellLib, recurseIntoAttrs, testSrc }:
{ stdenv, util, mkCabalProjectPkgSet, project', haskellLib, recurseIntoAttrs, testSrc }:

with stdenv.lib;

Expand All @@ -12,7 +12,7 @@ let
}
];

project = cabalProject' {
project = project' {
src = testSrc "cabal-simple";
inherit modules;
};
Expand Down
3 changes: 2 additions & 1 deletion test/haskell-language-server/cabal.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{ testSrc, evalPackages, buildPackages }:

(buildPackages.haskell-nix.cabalProject {
(buildPackages.haskell-nix.project {
src = evalPackages.fetchgit {
url = "https://github.com/haskell/haskell-language-server.git";
fetchSubmodules = true;
rev = "d2654185eef1b0d703cebc694e85438e20600e37";
sha256 = "0s0k2i0imkcn9zykhrlqq0r4ssv25mwbpdyc675xkzgl1vj1l8kd";
};
projectFileName = "cabal.project";
sha256map = {
"https://github.com/wz1000/shake"."fb3859dca2e54d1bbb2c873e68ed225fa179fbef" = "0sa0jiwgyvjsmjwpfcpvzg2p7277aa0dgra1mm6afh2rfnjphz8z";
"https://github.com/peti/cabal-plan"."894b76c0b6bf8f7d2f881431df1f13959a8fce87" = "06iklj51d9kh9bhc42lrayypcpgkjrjvna59w920ln41rskhjr4y";
Expand Down
4 changes: 2 additions & 2 deletions test/haskell-language-server/stack.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{ testSrc, haskell-nix, evalPackages, buildPackages }:

(buildPackages.haskell-nix.stackProject {
(buildPackages.haskell-nix.project {
src = evalPackages.fetchgit {
url = "https://github.com/haskell/haskell-language-server.git";
fetchSubmodules = true;
rev = "d2654185eef1b0d703cebc694e85438e20600e37";
sha256 = "0s0k2i0imkcn9zykhrlqq0r4ssv25mwbpdyc675xkzgl1vj1l8kd";
};
stackYaml = "stack-${haskell-nix.ghc.version}.yaml";
projectFileName = "stack-${haskell-nix.ghc.version}.yaml";
sha256map = {
"https://github.com/wz1000/shake.git"."fb3859dca2e54d1bbb2c873e68ed225fa179fbef" = "0sa0jiwgyvjsmjwpfcpvzg2p7277aa0dgra1mm6afh2rfnjphz8z";
"https://github.com/peti/cabal-plan.git"."894b76c0b6bf8f7d2f881431df1f13959a8fce87" = "06iklj51d9kh9bhc42lrayypcpgkjrjvna59w920ln41rskhjr4y";
Expand Down
4 changes: 2 additions & 2 deletions test/stack-local-resolver/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ stackProject', recurseIntoAttrs, testSrc }:
{ project', recurseIntoAttrs, testSrc }:

let
project = stackProject' {
project = project' {
src = testSrc "stack-local-resolver";
};
packages = project.hsPkgs;
Expand Down