muhuk's blog

Nature, to Be Commanded, Must Be Obeyed

July 24, 2016

Installing Elm with Stack

I am quite conservative with what I install on my computer. Even more so when it comes to installing package some package manager just to be able to use one package hosted. I have been meaning to play with Elm for some time and it was disappointing to see the requirement of npm, in addition to a source install, to use it on GNU/Linux. Of course I have been misreading the following statement:

Second, if you are on some linux OS and just want to use Elm, use the npm installer.

You can either use the npm package, or you can build from source. But I read this as you need both. And then tweeted this:

Then I have stumbled upon this post describing how to build Elm with Stack. I followed the instructions there and managed to install Elm. This post contains slightly modified instructions to build Elm 0.17.1.

I assume you have stack installed.

1. Prepare Stack Project

Create an elm directory, but don’t run stack new ...:

mkdir elm
cd elm

Clone elm-platform‘s components:

git clone -b 0.17.1 https://github.com/elm-lang/elm-compiler.git
git clone -b 0.17.1 https://github.com/elm-lang/elm-package.git
git clone -b 0.17.1 https://github.com/elm-lang/elm-make.git
git clone -b 0.17.1 https://github.com/elm-lang/elm-reactor.git
git clone -b 0.17.1 https://github.com/elm-lang/elm-repl.git

Now we can create our stack project:

stack init --resolver ghc-7.10.2

2. Patch aeson-pretty Dependency

According to this pull request we need to edit elm-compiler/elm-compiler.cabal file’s Build-depends: section to require aeson-pretty as such:

aeson-pretty < 0.8,

And after that we need to update our stack.yaml:

stack solver --update-config

3. Build Platform

stack install elm-{compiler,make,package,repl}
stack install elm-reactor

If these commands fail, retrying should help. You would know to give up when the count of remaining builds stop decreasing.

4. Bonus: elm-format

If you have successfully built elm-platform using the instructions above installing elm-format should be easy. Here are the commands I have used to build on my machine:

git clone git@github.com:avh4/elm-format.git
cd elm-format
stack init --resolver ghc-7.10.3
stack install elm-format

I ended up elm-format-0.16 & elm-format-0.17 binaries in my ~/bin. But elm-mode needs a elm-format executable:

cd ~/bin
ln -s elm-format-0.17 elm-format

Everything should be ready for some Elm hacking now.

If you have any questions, suggestions or corrections feel free to drop me a line.