Elm on FreeBSD

Elm is a purely functional, strongly typed language for building web-apps. I recently started playing with elm1 and so far love it!

There was a small bit of trouble though, Elm doesnt officially support FreeBSD. The compiler is written in Haskell and couple of people have made it work on freebsd by compiling from source.

That’s where I started, and soon gave up because compiling elm 0.19 needs ghc-8.2.2. That particular ghc version is no longer in binary packages. Stack ghcs are still broken on FreeBSD to try that route. All of the solutions I encountered builds ghc from source and that was going take an eternity on my thinkpad.

Luckily elm project provides binaries for Linux - and FreeBSD can pretend to be linux pretty well. Thats what I ended up doing!

  1. Load the kernel module for linux emulation.
kldload linux64.ko
  1. Get elm linux binary from github.
wget https://github.com/elm/compiler/releases/download/0.19.0/binaries-for-linux.tar.gz
tar xf binaries-for-linux.tar.gz
  1. Then brand the ELF binary as type Linux. Kernel uses this information check decide runtime to use, in our case Linux emulation.
brandelf -t Linux ./elm

..and there we have it

$ file elm
elm: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux),
statically linked, with debug_info, not stripped

$ ./elm
Hi, thank you for trying out Elm 0.19.0. I hope you like it!

  1. Shout-out to Tenor and Liz for introducing me to Elm.↩︎