How to build relocatable packages with cabal

Tim Cuthbertson tim at
Sun Nov 13 02:34:15 CET 2011

I'm trying to distribute cabal-built haskell libraries using
zero-install ( ). The main requirement of
0install packages is that they
 - be relocatable to arbitrary paths without modifying them (packages
are read-only and contents are verified by a manifest, so
prefix-dependant binaries are impossible)
 - be runnable without modification as long as environment variables
are correctly set up so that they can find their dependencies. I
believe $GHC_PACKAGE_PATH should be sufficient for most cabal packages

from this very old ticket ( ), I see:
> Configuring a relocatable package should be something that is done explicitly. At the moment it is done simply by configuring it in the right way, but Cabal is never aware that the user is trying to construct a relocatable package.

Are there any instructions on how to configure cabal to build a
relocatable package? I have tried setting prefix to an empty string
and "/" in the configure step, but neither of those work. My current
build process is:

set -eux
cd "$SRCDIR"
cabal configure -v --builddir="$BUILDDIR" --prefix="/"
cabal build -v --builddir="$BUILDDIR"
cabal copy --builddir="$BUILDDIR" --destdir="$DISTDIR"
cabal register --gen-pkg-config="$DISTDIR/package.conf" --builddir="$BUILDDIR"

But the created package doesn't seem valid (`ghc-pkg list` can't even
parse it, and I'm not sure what the chances of it actually working
would be).

I'm specifically trying to build hspec here, but ideally there would
be some recipe that works for all typical cabal projects. Any
assistance wooud be appreciated.

 - Tim.

More information about the cabal-devel mailing list