EDIT FOR FUTURE SOULS STUMBLING ONTO THIS:
It would be unwise to copy any of my commands below, do not execute them. Just check out Zeta's answer for why I was approaching this incorrectly.
ORIGINAL QUESTION
My sandbox seems to be getting caught on a global version of some packages rather than using the sandbox versions. I've looked around on SO for answers to this, and many of the questions are answered without specific instructions to resolve this, or were slightly different, so I can't seem to get my setup running. Here's what I have:
1. Version of cabal is old:
$ cabal --v
cabal-install version 1.16.0.2
using version 1.16.0 of the Cabal library
Oh dear, this is old and won't run sandbox.
2. Install cabal with cabal
$ cabal install cabal
Resolving dependencies...
Downloading Cabal-1.22.6.0...
...lots of stuf...
Registering Cabal-1.22.6.0...
Installed Cabal-1.22.6.0
Looks good.
3. Try it out:
$ cabal sandbox init
cabal: unrecognised command: sandbox (try --help)
Hmm.
$ which cabal
/usr/bin/cabal
Ahh.
$ ${HOME}/.cabal/bin/cabal --version
cabal-install version 1.22.2.0
using version 1.22.2.0 of the Cabal library
Aha.
$ export PATH="${HOME}/.cabal/bin/:$PATH"
$ export PATH="${HOME}/.cabal/libs/:$PATH"
$ cabal --v
cabal-install version 1.22.2.0
Great.
4. Try it out again:
$ cabal sandbox init
Writing a default package environment file to
.../cabal.sandbox.config
Creating a new sandbox at .../.cabal-sandbox
$ cabal install Frames
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: Frames-0.1.2.1 (user goal)
next goal: base (dependency of Frames-0.1.2.1)
rejecting: base-4.6.0.1/installed-8aa... (conflict: Frames => base>=4.7 &&
<4.9)
rejecting: base-4.8.2.0, 4.8.1.0, 4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0, 4.6.0.1,
4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0, 4.3.0.0, 4.2.0.2,
4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global constraint
requires installed instance)
Dependency tree exhaustively searched.
Note: when using a sandbox, all packages are required to have consistent
dependencies. Try reinstalling/unregistering the offending packages or
recreating the sandbox.
Huh, so base is not compatible, OK.
$ cabal install base --reinstall
Resolving dependencies...
cabal: Could not resolve dependencies:
next goal: base (user goal)
rejecting: base-4.8.2.0, 4.8.1.0, 4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0, 4.6.0.1,
4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0, 4.3.0.0, 4.2.0.2,
4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0 (only already installed instances can be
used)
rejecting: base-3.0.3.2 (conflict: base => base>=4.0 && <4.3)
rejecting: base-3.0.3.1 (conflict: base => base>=4.0 && <4.2)
Dependency tree exhaustively searched.
Note: when using a sandbox, all packages are required to have consistent
dependencies. Try reinstalling/unregistering the offending packages or
recreating the sandbox.
Huh, what about all dependencies?
$ cabal install --upgrade-dependencies
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: Frames-0.1.2.1 (user goal)
next goal: base (dependency of Frames-0.1.2.1)
rejecting: base-4.8.2.0, 4.8.1.0, 4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0 (global
constraint requires installed instance)
rejecting: base-4.6.0.1/installed-8aa... (conflict: Frames => base>=4.7 &&
<4.9)
rejecting: base-4.6.0.1, 4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0,
4.3.0.0, 4.2.0.2, 4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global
constraint requires installed instance)
Dependency tree exhaustively searched.
Note: when using a sandbox, all packages are required to have consistent
dependencies. Try reinstalling/unregistering the offending packages or
recreating the sandbox.
Seems I cannot reinstall/unregister the offending packages. I wish the error message would give me a little more on how to do this, because the "--reinstall" flag was my best shot.
Well, it offered 2 solutions, so let's try the other, to recreate the sandbox.
$ cabal sandbox delete
Deleting the sandbox located at .../.cabal-sandbox
$ cabal sandbox init
Writing a default package environment file to
.../cabal.sandbox.config
Creating a new sandbox at .../.cabal-sandbox
$ cabal install --upgrade-dependencies
Resolving dependencies...
cabal: Could not resolve dependencies:
trying: Frames-0.1.2.1 (user goal)
next goal: base (dependency of Frames-0.1.2.1)
rejecting: base-4.8.2.0, 4.8.1.0, 4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0 (global
constraint requires installed instance)
rejecting: base-4.6.0.1/installed-8aa... (conflict: Frames => base>=4.7 &&
<4.9)
rejecting: base-4.6.0.1, 4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0,
4.3.0.0, 4.2.0.2, 4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global
constraint requires installed instance)
Dependency tree exhaustively searched.
Note: when using a sandbox, all packages are required to have consistent
dependencies. Try reinstalling/unregistering the offending packages or
recreating the sandbox.
This also did not help. Fresh out of ideas. How do I use sandbox? My read here is there is a global something that is causing a problem. A sandbox should not be bothered by that by design of sandboxing, right?
If it helps context, I'm just trying to run the demo for Frames:
https://github.com/acowley/Frames
...which is:
$ cabal sandbox init
$ cabal install --dependencies-only -f demos # <-- here
I see there's a closed issue on this step, but that seems like a different issue.
A look behind the stage (or: What is special about base)
The version of
baseis tightly coupled to a GHC version. For example,base-4.6.0.1ships with GHC 7.6.3. You cannot use another version of base with an incompatible GHC version. In order to usebase-4.7.0.x, you need GHC 7.8.x.Therefore, you cannot use a local sandbox for
base. It's one of the (very few) packages that cannot get sandboxed.Sandboxes need a strong base
If we take the figuratively notion of a sandbox, we'll see soon that a sandbox needs some kind of foundation. And that's exactly
base. Everything else can live in the sandbox, and should work:You use the sandbox correctly, but you don't have the right compiler/base installed.
Again, Cabal isn't in an inconsistent state.
Framesrestricts the minimal base version to4.7, which usually means that it uses GHC features that were introduced with GHC 7.8. Even if you were able to installbase-4.7.x.y, you would still miss those GHC features.However, it isn't recommended to use recent versions of Cabal with old versions of GHC.
Trying other lower bounds
However, sometimes a library has a too strict lower bound. Maybe
Framesdoes work with GHC 7.6. You can check this locally:If this works, the lower bound on
basein Frames is actually too high and you can file a pull-request on the library.Getting new stuff in old distributions
There are now four ways for this. In decreasing order of difficulty:
apt-geton LTS distributions).stack setup(easiest one).I'll focus on the MinGHC and the Stack one, since those provide easy methods to install several GHC versions along each other.
MinGHC installation (Linux specific)
Basically follow the instructions on this site. On Ubuntu you have to add a third party source to your
aptsources and install a specific version of Cabal and GHC. Note that this will install GHC and Cabal to/opt/, so you have to add some directories to your path:This enables you to install other versions of cabal and GHC rather easy with
and then change your
PATHvariable. Afterwards, you can use thecabal sandbox *commands.I also suggest you to read Stephen Diel's notes on Cabal. They provide great insight on some commonly used features.
Using stack
Again, follow the instructions on this site. It's basically the same: you add external sources and tell your distribution to trust those sources:
Afterwards, you have to use
stack initin an already existing Cabal project, orstack newto install a new project, followed bystack setup, which will install a fairly recent version of GHC:Note that
stackinstalls all dependencies in a "sane" way. It uses an internal LTS system, you don't have to use cabal sandboxes. However, you cannot use Cabal commands anymore, instead you have to usestack buildorstack ghc.If you don't use a package, something like
is possible. However, documenting every feature of stack would break the scope of this answer and get out of date soon, so have a look at the documentation.