1
votes

When I have a sandbox, it seems cabal install ignores packages in $HOME/.ghc/x86_64-linux-7.8.4/package.conf.d.

How can I configure the sandbox such that these packages become visible? I am seeing a vague reference to --package-db=db in https://www.haskell.org/cabal/users-guide/installing-packages.html#sandboxes-advanced-usage but I understand neither how nor when to use it. (with sandbox init? configure? install? none seems to work - none gives any error message either.)

I know about add-source but my question refers to installed packages.

2

2 Answers

1
votes

The whole point of the sandbox is that it ignores your local package database.

If you want to share installations across many sandboxes, you may install to the global database; but then you should be very careful, as fixing the badness of a broken package is much more difficult. Keep it to really core packages that you expect to be widely shared across many, many projects -- not just the half dozen you're stressing out about right now for your job.

Alternately, you may share one sandbox between the builds of many packages; simply set the CABAL_SANDBOX_CONFIG variable to an absolute path pointing to the appropriate cabal.sandbox.config file. This is significantly safer, and much more flexible, as you can choose how widely your installed packages are shared (and in bad cases, simply nuke the sandbox and start over).

1
votes

Here is something you can try - copy (or symlink) the files from ~/.ghc/{arch-os-ghc-version}/package.conf.d to the sandbox's {arch-os-ghc-version}-packages.conf.d directory.

There is a question about the package.cache file. The following procedure seems to be a safe way to proceed:

  1. Start with an empty sandbox
  2. Copy the package.conf.d files from ~/.ghc to the sandbox (including package.cache)
  3. Add packages to the sandbox via cabal install --only-dependencies

I don't know if the package.cache file is required or if there is a way to rebuild it.

One disadvantage is that cabal install --only-deps seems to reinstall broken packages in the sandbox even if they are not required by your application. Maybe there is work-around for this.