If I create a cabal sandbox with cabal sandbox init, I can use cabal repl or cabal exec ghc(i) to work with those packages without creating a project:
$ mkdir /tmp/example && cd /tmp/example
$ cabal sandbox init
$ cabal install QuickCheck
$ cabal exec ghci
Prelude> :m Test.QuickCheck
Prelude Test.QuickCheck>
However, if I change the path to something else, even to a subdirectory, I cannot access the packages anymore:
$ mkdir -p /tmp/example/sub && cd /tmp/example/sub
$ cabal exec ghci
Prelude> :m Test.QuickCheck
<no location info>:
Could not find module ‘Test.QuickCheck’
It is not a module in the current program, or in any known package.
Is there any way to use the contents from the sandbox, without copying its content?
The problem is that
cabalwill only respect sandboxes in the current working directory. However, there are several options where you can specify a sandbox location for cabal or the package databse for GHC.Using cabal features
You can use
cabal's--sandbox-config-fileoption to specify a sandbox configuration, e.g.This also enables you to change the sandbox from other places, which comes in handy if you just want to install random stuff into a temporary place:
Since this gets cumbersome after a while, you should probably add an alias
Using
ghc -package-dbAlternatively, you can directly specify the package database when you use GHC with
-package-db:The
<ARCH>depends on your system and the used GHC, e.g. on a 64bit Linux and GHC 7.10.3 it'sx86_64-linux-ghc-7.10.3-packages.conf.d. You can then use all packages in that database:Again, an alias should come in handy.
Using
GHC_PACKAGE_PATHLast, but not least, you can adjust an environment variable. However, if the environment variable
GHC_PACKAGE_PATHexists, it will overwrite GHC's usual package databases, so you either need to checkghc-pkg listand add them tooor use
-global-package-dband-user-package-dbto reenable them: