Skip to content

Commit 2b9b99a

Browse files
authored
Fix implicit cabal project (#1639)
#1588 does not provide an implicit project the way cabal does. So for instance: ``` $ cabal unpack hello $ cd hello-1.0.0.2 $ echo 'constraints: hello<0' >cabal.project.local $ cabal build all Resolving dependencies... Error: cabal: Could not resolve dependencies: [__0] next goal: hello (user goal) [__0] rejecting: hello-1.0.0.2 (constraint from project config /Users/hamish/iohk/hello-1.0.0.2/cabal.project.local requires <0) [__0] rejecting: hello-1.0.0.1, hello-1.0 (constraint from user target requires ==1.0.0.2) [__0] fail (backjumping, conflict set: hello) After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: hello ``` So even though there was no `packages:` it is looking for the package in the default location (the default is `packages: ./*.cabal` according to the cabal docs). I also checked that including `packages:` in `.local` does not change the implicit `packages: ./*.cabal` with: ``` $ cabal unpack split $ echo 'packages: ./split-0.2.3.5' > cabal.project.local $ cabal build hello:exe:hello split:lib:split ```
1 parent f43c5cc commit 2b9b99a

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

lib/call-cabal-project-to-nix.nix

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{ pkgs, runCommand, cacert, index-state-hashes, haskellLib }@defaults:
22
let readIfExists = src: fileName:
3+
# Using origSrcSubDir bypasses any cleanSourceWith.
34
let origSrcDir = src.origSrcSubDir or src;
45
in
56
if builtins.elem ((__readDir origSrcDir)."${fileName}" or "") ["regular" "symlink"]
@@ -122,24 +123,38 @@ let
122123
type == "directory" ||
123124
pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".cabal" "package.yaml" ]); };
124125

125-
# Using origSrcSubDir bypasses any cleanSourceWith so that it will work when
126-
# access to the store is restricted. If origSrc was already in the store
127-
# you can pass the project in as a string.
128-
rawCabalProject =
129-
# Even if `cabal.project` doesn't exist, `cabal.project.local` is still used by cabal.
130-
# We tested this: https://github.com/input-output-hk/haskell.nix/pull/1588
131-
if cabalProject == null && cabalProjectLocal == null
132-
then null
133-
else (
134-
# like fmap
135-
let f = g: x: if x == null then "" else g x; in
136-
f (x: x) cabalProject + f (x: "\n-- Added from cabalProjectLocal argument to cabalProject\n${x}") cabalProjectLocal
137-
);
138-
139-
cabalProjectIndexState =
140-
if rawCabalProject != null
141-
then pkgs.haskell-nix.haskellLib.parseIndexState rawCabalProject
142-
else null;
126+
# When there is no `cabal.project` file `cabal-install` behaves as if there was
127+
# one containing `packages: ./*.cabal`. Even if there is a `cabal.project.local`
128+
# containing some other `packages:`, it still includes `./*.cabal`.
129+
#
130+
# We could write to `cabal.project.local` instead of `cabal.project` when
131+
# `cabalProject == null`. However then `cabal-install` will look in parent
132+
# directories for a `cabal.project` file. That would complicate reasoning about
133+
# the relative directories of packages.
134+
#
135+
# Instead we treat `cabalProject == null` as if it was `packages: ./*.cabal`.
136+
#
137+
# See: https://github.com/input-output-hk/haskell.nix/pull/1588
138+
# https://github.com/input-output-hk/haskell.nix/pull/1639
139+
#
140+
rawCabalProject = ''
141+
${
142+
if cabalProject == null
143+
then ''
144+
-- Included to match the implicit project used by `cabal-install`
145+
packages: ./*.cabal
146+
''
147+
else cabalProject
148+
}
149+
${
150+
pkgs.lib.optionalString (cabalProjectLocal != null) ''
151+
-- Added from `cabalProjectLocal` argument to the `cabalProject` function
152+
${cabalProjectLocal}
153+
''
154+
}
155+
'';
156+
157+
cabalProjectIndexState = pkgs.haskell-nix.haskellLib.parseIndexState rawCabalProject;
143158

144159
index-state-found =
145160
if index-state != null
@@ -292,10 +307,7 @@ let
292307
);
293308
};
294309

295-
fixedProject =
296-
if rawCabalProject == null
297-
then { sourceRepos = []; repos = {}; extra-hackages = []; makeFixedProjectFile = ""; replaceLocations = ""; }
298-
else replaceSourceRepos rawCabalProject;
310+
fixedProject = replaceSourceRepos rawCabalProject;
299311

300312
# The use of the actual GHC can cause significant problems:
301313
# * For hydra to assemble a list of jobs from `components.tests` it must

0 commit comments

Comments
 (0)