Haskell with VsCode DevContainers on M1.
Setup a Haskell dev container on M1
I’ve been interested in haskell for quite sometime and decided to pick it up finally. So the first thing I needed to do was setup my development environment. Looking for a good dev environment setup on M1 is a bit difficult. After a few hurdles, I was able to come up with a minimal setup.
I’m quite used to VsCode remote containers and I wanted to do the same here and configured the following in the dev container:
- Haskell vscode enxtension: Adds language support for haskell powered by haskell-language-server
- GHCup: Configure the haskell extension to use it while installing the toolchain.
Following the official haskell dev-container documentation from microsoft, the first step is to create a project directory and
.devcontainer directory under it. Then create the following files with their respective contents:
Once I had the basic setup, I needed to update the
.devcontainer.json file and add the following settings. I’ve used the
haskell.manageHLS to specify that I’ll manage my own installation of
GHCup because the extension doesn’t come with
GHCup and I needed it for the toolchain installation. You can read more in the documentation here.
I also needed to extend the
Dockerfile and add a few dependencies for the haskell vscode extension to install the toolchain.
At this point, I had the basic environment setup that I was able use to initialise a haskell app and get started. I’ve loaded the directory onto vscode. If you have it already open, you can reload the window and it’ll rebuild the dev container which will take a few minutes.
Once that’s done, and the project is successfully loaded onto vscode, I needed to open the terminal inside vscode (i.e the session from within the container, if you prefer to use a separate terminal window, you’ll need to attach it to the running haskell dev container.) and run the following commands.
cabal init # Create app
ghci :l app/Main # load main module
main #call main function which will print "Hello, Haskell!"
Here’s the complete repo.