Cabal on NFS

Note to myself, like most other things in this site:

Suppose your home directory is on NFS or some such. Now suppose you're sharing your ~/.cabal files with several machines across the network. Some of them are x86, some are x86\_64, etc. All of them are running the same version of RHEL or some such.

When this is the case, and when you hop from terminal to terminal, Cabal won't be happy with the default configuration; and your finely tuned XMonad will break. You certainly don't want to nuke your ~/.cabal and ~/.ghc and rebuild everything every time you use a different computer.

I asked the friendly folks in #haskell (this was a while ago, so memory lapses are all mine), and was pleased to learn that there is indeed a solution to this particular nerd-world problem: change the ~/.cabal/config slightly, like so:

install-dirs user
  prefix: /home/sajith/.cabal/$arch
  bindir: $prefix/bin
  libdir: $prefix/lib
  libsubdir: $pkgid/$compiler
  libexecdir: $prefix/libexec
  datadir: $prefix/share
  datasubdir: $pkgid
  docdir: $datadir/doc/$pkgid
  htmldir: $docdir/html
  haddockdir: $htmldir

Adding $arch to prefix does the trick. I suppose you can also use $os and $compiler if you're the kind of person that runs twelve different versions of GHC on your Amiga-based NetBSD Beowulf cluster.

If you want to find these variables quickly, do a cabal help install or see Cabal docs.

If you use a non-hipster shell, adding this to ~/.profile might be useful:

if [ -d $HOME/.cabal/$(uname -m)/bin ]; then
    PATH=$HOME/.cabal/$(uname -m)/bin:$PATH

export PATH

(On Debian, "uname -i" and "uname -p" prints "unknown", because, to cite uname documentation, "the kernel does not make this information easily available, as is the case with Linux kernels". Hey Linux kernel on Debian, behave yourself.)