With stacks ghc version 8.2.2 it is not easy to install ghc-mod with stack. The reason are not matched dependencies. With a small trick we can install ghc-mod by building it ourselves. In this blog post you will learn how to do so. Let's get started.
First of all, where can we find ghc-mod sources? The right repository for this is the ghc-mod repository on GitHub. In this blog post we will clone it, adapt a stack.yaml file and then build and install the ghc-mod binary.
Let's prepare our build. Since we don't want to keep the source (if you would like to do different, feel free to copy the files anywehere you like), we will create a temporary folder and switch to it:
mkdir -p /tmp/build
cd /tmp/build
For the second step, let's checkout the repository with the correct sources and change the directory:
git clone https://github.com/DanielG/ghc-mod.git -b ghc802
git clone https://github.com/DanielG/cabal-helper.git
cd ghc-mod
To build the ghc-mod with stack we need a valid **stack.yaml** file. We can create this with the following contents:
resolver: lts-11.6 # current resolver
packages:
- location: .
- location: ./core # seems like ghc-mod-core got integrated
- location: ../cabal-helper
extra-dep: true
extra-deps:
- extra-1.6.6 # escapeJSON was missing with 1.5.3
- monad-journal-0.7.2
- optparse-applicative-0.13.2.0
- unix-compat-0.4.3.1
- either-4.4.1.1
flags: {}
extra-package-dbs: []
allow-newer: true # so it builds / too lazy to pinpoint exact versions
As you can see we are allowing newer dependencies (so cabal 2 is allowed and will pass through the build process).
With the correct sources and the correct stack.yaml file (attention, it's not .yml, it is really .yaml) we can build ghc-mod executables:
stack install
At the end of this command you should see a message telling that the following executables were installed successfully:
- ghc-mod
- ghc-modi
With the executables created, we can now add those executables to our bin path
sudo cp /home/{{you username}}/.local/bin/ghc-mod /usr/local/bin/
sudo cp /home/{{you username}}/.local/bin/ghc-modi /usr/local/bin/
(Alternatively you can just add the ghc-mod executables to your bin path).
Check your installation:
ghc-mod --version
If everything was build an copied correctly you should see a message similar to this:
ghc-mod version 5.9.0.0 compiled by GHC 8.2.2
I hope this blog post saved you a couple of minutes during the installation of ghc-mod.
Thank you for reading this far! Let’s connect. You can @ me on X (@debilofant) with comments, or feel free to follow. Please like/share this article so that it reaches others as well.