Cabal sandbox is using a global dependency. Could not resolve - haskell

I'm trying to add timerep onto an existing application. I can't get it to resolve my dependencies. It looks like it is using the globally installed version of time == 1.4.2, when >= 1.5 would be ideal for my application.
How can I get cabal to use time 1.5? I've poked through unix, tls, process, timerep, and they all seem like they would work fine if it would just use time >= 1.5.
Here's the error:
serials> cabal install --only-dependencies
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: serials-0.1.0.2 (user goal)
trying: mandrill-0.2.2.0 (dependency of serials-0.1.0.2)
trying: http-client-tls-0.2.2 (dependency of mandrill-0.2.2.0)
trying: tls-1.2.17 (dependency of http-client-tls-0.2.2)
trying: x509-validation-1.5.2 (dependency of tls-1.2.17)
trying: process-1.2.0.0/installed-487... (dependency of x509-validation-1.5.2)
next goal: unix (dependency of process-1.2.0.0/installed-487...)
rejecting: unix-2.7.0.1/installed-299... (conflict: unix =>
time==1.4.2/installed-bf9..., serials => time>=1.5)
rejecting: unix-2.7.1.0, 2.7.0.1, 2.7.0.0, 2.6.0.1, 2.6.0.0, 2.5.1.1, 2.5.1.0,
2.5.0.0, 2.4.2.0, 2.4.1.0, 2.4.0.2, 2.4.0.1, 2.4.0.0, 2.3.2.0, 2.3.1.0,
2.3.0.0, 2.2.0.0, 2.0 (conflict: process => unix==2.7.0.1/installed-299...)
Dependency tree exhaustively searched.
Cabal file:
-- Initial serials.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: serials
version: 0.1.0.2
synopsis: serials
description: serials
license: MIT
license-file: LICENSE
author: Sean Hess
maintainer: Sean Hess
-- copyright:
category: Web Scraper
build-type: Simple
extra-source-files: README.md
cabal-version: >=1.10
Source-repository head
type: git
location: git#github.com:seanhess/serials.git
executable serials
main-is: Main.hs
hs-source-dirs: server
ghc-options: -fcontext-stack=36
-- other-modules:
-- other-extensions:
default-language: Haskell2010
build-depends:
base >=4.7 && <5,
tagsoup,
text,
scalpel,
containers,
network-uri,
monad-loops,
wreq,
lens,
bytestring,
parsec,
utf8-string,
tagsoup,
xml,
feed,
regex-pcre,
aeson,
network,
wai,
wai-extra,
wai-cors,
wai-middleware-static,
warp,
servant-server >= 0.4,
rethinkdb >= 1.16,
transformers,
either,
unordered-containers,
mtl,
http-types,
safe,
hashable,
resource-pool,
time >= 1.5,
pooled-io,
shelly,
string-conversions,
bcrypt,
random,
jwt,
cookie,
entropy,
mandrill == 0.2.2.0,
email-validate,
blaze-markup,
blaze-html,
iso8601-time,
scotty == 0.10.0,
timerep >= 2.0.0

It is difficult for cabal-install to produce a complete description of the mutual incompatibilities of an installation problem. It instead decides to print the first path to failure.
However, it prints Dependency tree exhaustively searched. which indicates that there actually is no solution to the given problem.
One thing that often helps is to look at the choices cabal-install has made, find one that seems suboptimal, and then add an explicit constraint to change that. This may result in a better error message.
Let's try [note that I'm not sure if I have exactly the same package DB as you have, so it may produce different results on your system].
You had (modulo hashes of installed packages):
$ cabal install --only-dependencies
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: serials-0.1.0.2 (user goal)
trying: mandrill-0.2.2.0 (dependency of serials-0.1.0.2)
trying: http-client-tls-0.2.2 (dependency of mandrill-0.2.2.0)
trying: tls-1.2.17 (dependency of http-client-tls-0.2.2)
trying: x509-validation-1.5.2 (dependency of tls-1.2.17)
trying: process-1.2.0.0/installed-06c... (dependency of x509-validation-1.5.2)
next goal: unix (dependency of process-1.2.0.0/installed-06c...)
rejecting: unix-2.7.0.1/installed-f86... (conflict: unix =>
time==1.4.2/installed-9b3..., serials => time>=1.5)
rejecting: unix-2.7.1.0, 2.7.0.1, 2.7.0.0, 2.6.0.1, 2.6.0.0, 2.5.1.1, 2.5.1.0,
2.5.0.0, 2.4.2.0, 2.4.1.0, 2.4.0.2, 2.4.0.1, 2.4.0.0, 2.3.2.0, 2.3.1.0,
2.3.0.0, 2.2.0.0, 2.0 (conflict: process => unix==2.7.0.1/installed-f86...)
Dependency tree exhaustively searched.
Looking through this, the error occurs with unix, which is a dependency of process. So the installed instance of process being chosen leads to trouble. So what if we disallow choosing that instance of process?
$ cabal install --only-dependencies --constraint="process source"
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: serials-0.1.0.2 (user goal)
next goal: time (dependency of serials-0.1.0.2)
rejecting: time-1.4.2/installed-9b3... (conflict: serials => time>=1.5)
trying: time-1.5.0.1
next goal: rethinkdb (dependency of serials-0.1.0.2)
rejecting: rethinkdb-1.16.0.0 (conflict: time==1.5.0.1, rethinkdb =>
time==1.4.*)
rejecting: rethinkdb-1.15.2.1, 1.15.2.0, 1.15.1.0, 1.15.0.0, 1.8.0.5, 1.8.0.4,
1.8.0.3, 1.8.0.2, 1.8.0.1, 1.8.0.0, 0.1.0.0 (conflict: serials =>
rethinkdb>=1.16)
Dependency tree exhaustively searched.
Aha! So rethinkdb, which is a direct dependency of serials, has an explicit dependency on time == 1.4.*. This is in direct conflict with the dependency of serials on time >= 1.5.
This is not easy to fix. You either need to make rethinkdb work with the newer time library, or serials with the older.
We enter the realm of speculation now: It is possible, but not guaranteed, that rethinkdb actually works with a newer version of time. We can try to instruct cabal-install to consider such install plans:
$ cabal install --only-dependencies --allow-newer=time
This actually yields an install plan on my machine. I have not tried building it, and I don't know whether it works. But it may be worth a try.

Related

Why does omitting cabal-version cause the build to fail?

I have a minimal example project:
Test
Test
Test.hs
Test.cabal
Test.hs contains an empty module Test.Test. The contents of Test.cabal are as follows:
name: Test
version: 0.0.0
library
build-depends: base
exposed-modules: Test.Test
Running cabal build fails with a long, confusing error message (copied below) unless I add cabal-version: 2.2 to the cabal file. Higher than 2.2 works as well but lower versions result in a similar error. My cabal version is 3.2. Why does the build fail unless I specify a cabal version and why are versions lower than 2.2 not sufficient?
The error message that I get without specifying cabal version is as follows:
Resolving dependencies...
cabal.exe: Could not resolve dependencies:
[__0] trying: Test-0.0.0 (user goal)
[__1] next goal: Test:setup.Cabal (dependency of Test)
[__1] rejecting: Test:setup.Cabal-3.2.0.0/installed-3.2.0.0 (conflict: Test =>
Test:setup.Cabal>=0 && <1.25)
[__1] skipping: Test:setup.Cabal-3.6.3.0, Test:setup.Cabal-3.6.2.0,
Test:setup.Cabal-3.6.1.0, Test:setup.Cabal-3.6.0.0, Test:setup.Cabal-3.4.1.0,
Test:setup.Cabal-3.4.0.0, Test:setup.Cabal-3.2.1.0, Test:setup.Cabal-3.2.0.0,
Test:setup.Cabal-3.0.2.0, Test:setup.Cabal-3.0.1.0, Test:setup.Cabal-3.0.0.0,
Test:setup.Cabal-2.4.1.0, Test:setup.Cabal-2.4.0.1, Test:setup.Cabal-2.4.0.0,
Test:setup.Cabal-2.2.0.1, Test:setup.Cabal-2.2.0.0, Test:setup.Cabal-2.0.1.1,
Test:setup.Cabal-2.0.1.0, Test:setup.Cabal-2.0.0.2 (has the same
characteristics that caused the previous version to fail: excluded by
constraint '>=0 && <1.25' from 'Test')
[__1] rejecting: Test:setup.Cabal-1.24.2.0, Test:setup.Cabal-1.24.0.0,
Test:setup.Cabal-1.22.8.0, Test:setup.Cabal-1.22.7.0,
Test:setup.Cabal-1.22.6.0, Test:setup.Cabal-1.22.5.0,
Test:setup.Cabal-1.22.4.0, Test:setup.Cabal-1.22.3.0,
Test:setup.Cabal-1.22.2.0, Test:setup.Cabal-1.22.1.1,
Test:setup.Cabal-1.22.1.0, Test:setup.Cabal-1.22.0.0,
Test:setup.Cabal-1.20.0.4, Test:setup.Cabal-1.20.0.3,
Test:setup.Cabal-1.20.0.2, Test:setup.Cabal-1.20.0.1,
Test:setup.Cabal-1.20.0.0, Test:setup.Cabal-1.18.1.7,
Test:setup.Cabal-1.18.1.6, Test:setup.Cabal-1.18.1.5,
Test:setup.Cabal-1.18.1.4, Test:setup.Cabal-1.18.1.3,
Test:setup.Cabal-1.18.1.2, Test:setup.Cabal-1.18.1.1, Test:setup.Cabal-1.18.1,
Test:setup.Cabal-1.18.0, Test:setup.Cabal-1.16.0.3, Test:setup.Cabal-1.16.0.2,
Test:setup.Cabal-1.16.0.1, Test:setup.Cabal-1.16.0, Test:setup.Cabal-1.14.0,
Test:setup.Cabal-1.12.0, Test:setup.Cabal-1.10.2.0, Test:setup.Cabal-1.10.1.0,
Test:setup.Cabal-1.10.0.0, Test:setup.Cabal-1.8.0.6, Test:setup.Cabal-1.8.0.4,
Test:setup.Cabal-1.8.0.2, Test:setup.Cabal-1.6.0.3, Test:setup.Cabal-1.6.0.2,
Test:setup.Cabal-1.6.0.1, Test:setup.Cabal-1.4.0.2, Test:setup.Cabal-1.4.0.1,
Test:setup.Cabal-1.4.0.0, Test:setup.Cabal-1.2.4.0, Test:setup.Cabal-1.2.3.0,
Test:setup.Cabal-1.2.2.0, Test:setup.Cabal-1.2.1, Test:setup.Cabal-1.1.6,
Test:setup.Cabal-1.24.1.0 (constraint from minimum version of Cabal used by
Setup.hs requires >=3.2)
[__1] fail (backjumping, conflict set: Test, Test:setup.Cabal)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: Test:setup.Cabal, Test

Compile Haskell program with third-party dependencies

I am trying to jump into some Haskell again after being away for a while. One piece of code I wrote ages ago inclues import qualified Data.MultiMap as MultiMap. Since Data.MultipMap is in the containers package, I get errors when I just run ghc program.hs. I've attempted to write a project.cabal file based on How to make a Haskell cabal project with library+executables that still run with runhaskell/ghci?. My latest attempt is
name: project
version: 1.0
executable project
main-is: project.hs
build-dependencies:
base >= 4 && <= 5
, containers
Now when I do cabal build project, I get
Resolving dependencies...
cabal.exe: Could not resolve dependencies:
[__0] trying: project-1.0 (user goal)
[__1] next goal: project:setup.Cabal (dependency of project)
[__1] rejecting: project:setup.Cabal-3.4.0.0/installed-3.4.0.0 (conflict:
project => project:setup.Cabal>=1.0 && <1.25)
[__1] skipping: project:setup.Cabal-3.4.0.0, project:setup.Cabal-3.2.1.0,
project:setup.Cabal-3.2.0.0, project:setup.Cabal-3.0.2.0,
project:setup.Cabal-3.0.1.0, project:setup.Cabal-3.0.0.0,
project:setup.Cabal-2.4.1.0, project:setup.Cabal-2.4.0.1,
project:setup.Cabal-2.4.0.0, project:setup.Cabal-2.2.0.1,
project:setup.Cabal-2.2.0.0, project:setup.Cabal-2.0.1.1,
project:setup.Cabal-2.0.1.0, project:setup.Cabal-2.0.0.2 (has the same
characteristics that caused the previous version to fail: excluded by
constraint '>=1.0 && <1.25' from 'project')
[__1] rejecting: project:setup.Cabal-1.24.2.0, project:setup.Cabal-1.24.0.0,
project:setup.Cabal-1.22.8.0, project:setup.Cabal-1.22.7.0,
project:setup.Cabal-1.22.6.0, project:setup.Cabal-1.22.5.0,
project:setup.Cabal-1.22.4.0, project:setup.Cabal-1.22.3.0,
project:setup.Cabal-1.22.2.0, project:setup.Cabal-1.22.1.1,
project:setup.Cabal-1.22.1.0, project:setup.Cabal-1.22.0.0,
project:setup.Cabal-1.20.0.4, project:setup.Cabal-1.20.0.3,
project:setup.Cabal-1.20.0.2, project:setup.Cabal-1.20.0.1,
project:setup.Cabal-1.20.0.0, project:setup.Cabal-1.18.1.7,
project:setup.Cabal-1.18.1.6, project:setup.Cabal-1.18.1.5,
project:setup.Cabal-1.18.1.4, project:setup.Cabal-1.18.1.3,
project:setup.Cabal-1.18.1.2, project:setup.Cabal-1.18.1.1,
project:setup.Cabal-1.18.1, project:setup.Cabal-1.18.0,
project:setup.Cabal-1.16.0.3, project:setup.Cabal-1.16.0.2,
project:setup.Cabal-1.16.0.1, project:setup.Cabal-1.16.0,
project:setup.Cabal-1.14.0, project:setup.Cabal-1.12.0,
project:setup.Cabal-1.10.2.0, project:setup.Cabal-1.10.1.0,
project:setup.Cabal-1.10.0.0, project:setup.Cabal-1.8.0.6,
project:setup.Cabal-1.8.0.4, project:setup.Cabal-1.8.0.2,
project:setup.Cabal-1.6.0.3, project:setup.Cabal-1.6.0.2,
project:setup.Cabal-1.6.0.1, project:setup.Cabal-1.4.0.2,
project:setup.Cabal-1.4.0.1, project:setup.Cabal-1.4.0.0,
project:setup.Cabal-1.2.4.0, project:setup.Cabal-1.2.3.0,
project:setup.Cabal-1.2.2.0, project:setup.Cabal-1.2.1,
project:setup.Cabal-1.1.6, project:setup.Cabal-1.24.1.0 (constraint from
minimum version of Cabal used by Setup.hs requires >=3.4)
[__1] fail (backjumping, conflict set: project, project:setup.Cabal)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: project:setup.Cabal, project
What am I missing to get this to work? What should I do to compile my Haskell program?
Change your project.cabal to:
cabal-version: 3.4
name: project
version: 1.0
executable project
main-is: project.hs
build-depends:
base >= 4 && <= 5
, multimap
cabal-version: 3.4 picks the latest version of the Cabal package format, which should be fine to use given that you are using Cabal 3.4 already. Left unspecified, cabal-version defaults to a very old version (as in recent versions the field is mandatory), which makes the build-type field default to Custom rather than Simple. That, in turn, leads to the error you got, as described in cabal issue #5278. In addition, I have changed build-dependencies to build-depends, and containers to multimap (as the latter package is the one that provides Data.MultiMap).

Trouble cabal installing http-conduit

When I run cabal install http-conduit, I get the following:
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: base-4.12.0.0/installed-4.1... (user goal)
[__1] trying: ghc-8.6.5/installed-8.6... (user goal)
[__2] next goal: process (user goal)
[__2] rejecting: process-1.6.7.0 (constraint from user target requires
==1.6.6.0)
[__2] rejecting: process-1.6.6.0 (conflict: ghc =>
process==1.6.5.0/installed-1.6...)
[__2] rejecting: process-1.6.5.1, process-1.6.5.0/installed-1.6...,
process-1.6.5.0, process-1.6.4.0, process-1.6.3.0, process-1.6.2.0,
process-1.6.1.0, process-1.6.0.0, process-1.5.0.0, process-1.4.3.0,
process-1.4.2.0, process-1.4.1.0, process-1.4.0.0, process-1.3.0.0,
process-1.2.3.0, process-1.2.2.0, process-1.2.1.0, process-1.2.0.0,
process-1.1.0.2, process-1.1.0.1, process-1.1.0.0, process-1.0.1.5,
process-1.0.1.4, process-1.0.1.3, process-1.0.1.2, process-1.0.1.1,
process-1.0.0.0 (constraint from user target requires ==1.6.6.0)
[__2] fail (backjumping, conflict set: ghc, process)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: process, base, ghc
I'm running cabal v3.0.0.0 and ghc v8.6.5
I'm quite new to the Haskell ecosystem, so any help I could get would be greatly appreciated. Thanks!
It looks like you have a dependency conflict, one package requires a different version than the package you are trying to install. This can be very difficult to solve for new users.
If you are new to Haskell and want to start using dependencies from Hackage, the centralized package archive for Haskell, I recommend using stack (install instructions and basic workflow. stack is a tool built on top of cabal that includes a curated list of package versions that are compatible. It should make it easier for you to get started.

Workarounds for Haskell / cabal packages with constraints with Nix and Cabal?

I recently got into developing with reflex-platform, with some extra configuration similar to what is described in the excellent reflex-project-skeleton.
Now I am having a package conflict that I am unable to resolve.
I use the same cabal script as reflex-project-skeleton, which invokes nix-shell in non-interactive mode with a cabal command.
If I try
./cabal new-build --allow-newer all
I get
these derivations will be built:
/nix/store/d6ji516i7pry5l6gv18y6hpj9k1bvgg5-heist-1.0.1.0.drv
/nix/store/zj1clks7mzq8gn91ahhwa3nvpi5rwra9-snap-1.0.0.2.drv
/nix/store/mx861972jnjabn7yxyr3y3q1yhf25jfq-snaplet-acid-state-0.2.7.drv
/nix/store/grhp4dhavmpi6bgns5a6vdzg8ny2bsf8-hoogle-local-0.1.drv
/nix/store/y3sszsj58f6ad3r06540w0mlr1pncd59-ghc-8.0.2-with-packages.drv
...
Configuring heist-1.0.1.0...
Setup: Encountered missing dependencies:
aeson >=0.6 && <1.2
builder for '/nix/store/d6ji516i7pry5l6gv18y6hpj9k1bvgg5-heist-1.0.1.0.drv' failed with exit code 1
cannot build derivation '/nix/store/y3sszsj58f6ad3r06540w0mlr1pncd59-ghc-8.0.2-with-packages.drv': 1 dependencies couldn't be built
The offending package appears to be snaplet-acid-state, so I tried installing it from inside the nix-shell:
cabal install snaplet-acid-state
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: snaplet-acid-state-0.2.7 (user goal)
trying: base-4.9.1.0/installed-4.9... (dependency of snaplet-acid-state-0.2.7)
next goal: mtl (dependency of snaplet-acid-state-0.2.7)
rejecting: mtl-2.2.1/installed-BLK... (conflict: mtl =>
transformers==0.5.2.0/installed-0.5..., snaplet-acid-state =>
transformers>=0.3.0.0 && <0.5)
trying: mtl-2.2.2
next goal: transformers (dependency of snaplet-acid-state-0.2.7)
rejecting: transformers-0.5.2.0/installed-0.5..., transformers-0.5.5.0,
transformers-0.5.4.0, transformers-0.5.2.0, transformers-0.5.1.0,
transformers-0.5.0.1, transformers-0.5.0.0 (conflict: snaplet-acid-state =>
transformers>=0.3.0.0 && <0.5)
rejecting: transformers-0.4.3.0, transformers-0.4.2.0 (conflict:
base==4.9.1.0/installed-4.9..., transformers => base>=2 && <4.9)
rejecting: transformers-0.4.1.0 (conflict: base==4.9.1.0/installed-4.9...,
transformers => base>=2 && <4.8 || >=1.0 && <2)
rejecting: transformers-0.3.0.0 (conflict: mtl => transformers>=0.4 && <0.6)
rejecting: transformers-0.2.2.1, transformers-0.2.1.0, transformers-0.2.0.0,
transformers-0.1.4.0, transformers-0.1.3.0, transformers-0.1.1.0,
transformers-0.1.0.1, transformers-0.0.1.0, transformers-0.0.0.0,
transformers-0.5.3.1, transformers-0.5.3.0, transformers-0.5.0.2 (conflict:
snaplet-acid-state => transformers>=0.3.0.0 && <0.5)
rejecting: transformers-0.4.0.0 (conflict: base==4.9.1.0/installed-4.9...,
transformers => base>=2 && <4.8 || >=1.0 && <2)
rejecting: transformers-0.2.2.0, transformers-0.1.0.0 (conflict:
snaplet-acid-state => transformers>=0.3.0.0 && <0.5)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: transformers, snap, base,
snaplet-acid-state, mtl
Tried specifying a version constraint in the cabal file, among other things, but to no effect.
Any clues? I'm not even sure what the exact issue is. Why is aeson failing to install in the first instance, and there is a conflict between snaplet-acid-state and mtl in the second?
What happens with this cabal2nix workflow is that basically the dependency solver is forced to only consider the packages that have been provided by Nixpkgs, or in this case reflex-platform + Nixpkgs. By taking away the freedom to pick one of multiple versions, the Cabal dependency solver is reduced to a dependency checker.
Now, if the version bound is too strict, you can consider what is called 'jailbreaking' in Nixpkgs: removing all version bounds from the cabal file. The other option is to change package versions.
Gabriel Gonzalez has written a good explanation of version management with Nixpkgs' Haskell infrastructure. You may also check out this thread. It's a bit verbose, but it discusses the callHackage and callCabal2nix functions that are quite helpful.

`cabal-install` refuses to solve conflicting `ghc` and `containers` versions

This repository contains a reproduction for an annoying error I got while using doctest in a test-suite.
cabal-installs solver fails to find a solution for this build-depends field using GHC 8.0.2:
build-depends:
base >= 4.7 && < 5
, doctest == 0.11.4
, containers == 0.5.10.2
Note that doctest depends transitively depends on ghc-8.0.2, which itself depends on containers-0.5.7.1, conflicting with my own constraints.
That's basically what cabal install is trying to tell me:
Resolving dependencies...
cabal.exe: Could not resolve dependencies:
next goal: containers (dependency of repro-0.1.0.0)
rejecting: containers-0.5.7.1/installed-0.5... (conflict: repro =>
containers==0.5.10.2)
trying: containers-0.5.10.2
next goal: doctest (dependency of repro-0.1.0.0)
rejecting: doctest-0.13.0, doctest-0.12.0 (conflict: repro => doctest==0.11.4)
trying: doctest-0.11.4
next goal: ghc (dependency of doctest-0.11.4)
rejecting: ghc-8.0.2/installed-8.0... (conflict: containers==0.5.10.2, ghc =>
containers==0.5.7.1/installed-0.5...)
Dependency tree exhaustively searched.
Now, what bugs me is that stack install works just fine using lts-9 and an extra-deps for the containers version.
So in theory, cabal-install could also do 'the right thing' here. How can I tell it to?

Resources