A clean Haskell+Cabal setup for Fedora

2019-11-04

Remove all current installs of GHC/Cabal/stack

I imagine you are frustrated with your haskell setup at this point. So, nuke it.

sudo dnf remove ghc cabal-install
rm -rf ~/.ghc ~/.cabal ~/.stack

Download a recent haskell binary distribution

Base URL: https://downloads.haskell.org/~ghc/ Version 8.8.1 (Latest as of this post) https://downloads.haskell.org/~ghc/8.8.1/ For Fedora: https://downloads.haskell.org/~ghc/8.8.1/ghc-8.8.1-x86_64-fedora27-linux.tar.xz

Install GHC

mkdir ~/ghc-installs
cd ~/ghc-installs
mkdir bindists
mkdir tarballs

# Change these as per your params
version=8.8.1
architecture=x86_64
os=fedora27-linux

mv /path/to/ghc-$version-$architecture-$os.tar.xz tarballs
cd bindists
tar -xf ../tarballs/ghc-$version-$architecture-$os.tar.gz
cd ghc-<version>
./configure --prefix=~/ghc-installs/ghc-$version
make-install

Install a recent cabal

Base URL: https://www.haskell.org/cabal/download.html For any x86~64~ Linux: https://downloads.haskell.org/~cabal/cabal-install-latest/cabal-install-3.0.0.0-x86_64-unknown-linux.tar.xz

mkdir -p ~/.cabal/bin
cd ~/.cabal/bin
tar -xf /path/to/cabal-install-3.0.0.0-x86_64-unknown-linux.tar.xz cabal

Add Cabal to $PATH

add the following line to your ~/.bashrc

export PATH=~/.cabal/bin:$PATH

Get an up-to-date cabal package list

cabal update # Note we still haven't added any ghc to $PATH

Try working with a new haskell package now :)

version=8.8.1
mkdir test-ghc881
cd test-ghc881

# Create project layout and test-ghc881.cabal
cabal init -w ~/ghc-installs/ghc-$version/bin/ghc

# Create cabal.project.local and fix ghc to it
cabal configure -w ~/ghc-installs/ghc-$version/bin/ghc

# From now on cabal will automatically pick our GHC - not we haven't
# relied on GHC being in $PATH till now. We might just as well use
# another GHC install in ~/ghc-installs/ghc-$otherversion/ for another
# project

cabal build

cabal run # Prints Hello, Haskell!

But wait - it gets better

You can build with another GHC half-way through and cabal maintains separation of build directories for each compiler version

otherversion=8.6.5 # I assume you install it just like you installed ghc-8.8.1
cabal build -w ~/ghc-installs/ghc-$otherversion/bin/ghc
cabal run -w ~/ghc-installs/ghc-$otherversion/bin/ghc

# you can see/run both your builds:
dist-newstyle/build/x86_64-linux/ghc-$version/$proj-$ver/x/$proj/build/$proj/$proj
dist-newstyle/build/x86_64-linux/ghc-$otherversion/$proj-$ver/x/$proj/build/$proj/$proj