3

How can I move the GHC and cabal installed packages to a different user? I've copied the directories but I'm getting error messages like:

ConfigParser.hs:15:8:
    Could not find module `Data.ByteString.Char8'
    There are files missing in the `bytestring-0.10.2.0' package,
    try running 'ghc-pkg check'.
    Use -v to see a list of the files searched for.

ghc-pkg check shows that any file for any package is missing. How can I resolve this?

Note: This question intentionally does not show research effort, because it was answered Q&A-style.

Uli Köhler
  • 13,012
  • 16
  • 70
  • 120

1 Answers1

4

First, you obviously need to copy .ghc and .cabal. These contain the binary files and configurations.

For simplicity, we will assume moving from user foo to user bar. Note that moving between architectures is not possible, as the binaries produced by GHC are not platform-independent.

After copying the aforementioned directories, there are paths like /home/foo remaining in different locations. We will use sed to replace those (run this as bar):

sed -i -e "s/foo/bar/g" ~/.cabal/config
sed -i -e "s/foo/bar/g" ~/.ghc/*-*/package.conf.d/*.conf

However, the file ~/.ghc/*-*/package.conf.d/package.cache still contains file references containing the username. We can't simply use sed to replace, however, because it's a binary file and it might destroy the package cache.

You can use ghc-pkg recache --user to re-cache all packages.

After performing these steps, you should be able to use the cabal packages as expected.

Uli Köhler
  • 13,012
  • 16
  • 70
  • 120