Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Building elm-lang on OpenBSD

Building elm-lang on OpenBSD

Requirements

  • haskell-platform
  • elm-lang BuildFromSource.hs script

Overview - OpenBSD considerations

Recent versions of OpenBSD enforce W^X. elm-lang is one of many programs that will not run unless executed from a mount point that explicitly allows code to violate W^X. /usr/local typically has the mount privilige wxallowed. This means building elm-lang from your home directory or /usr/ports will also fail since those mount points don't have wxallowed set. There are a couple strategies for working around this problem.

  1. Set wxallowed on /home
  2. Build in /usr/local
  3. Build on mount point that has wxallowed set and move the resulting binaries to /usr/local/bin

The following instructions document the first approach.

Setup the elm-lang Build Environment

Get the BuildFromSource.hs script and read

$ mkdir -p $HOME/dev/elm-lang
$ cd $HOME/dev/elm-lang
$ curl -LO https://raw.githubusercontent.com/elm-lang/elm-platform/master/installers/BuildFromSource.hs
$ less BuildFromSource.hs

Add the cabal-sandbox/bin dir to your PATH

$ export PATH=$PATH:$HOME/dev/elm-lang/Elm-Platform/0.18/.cabal-sandbox/bin

Make sure your /tmp dir has mount privilege wxallowed

By default Cabal builds all objects in /tmp. Many of the packages elm-lang depends on need to execute code, which also requires wxallowed. For this to work you must add wxallowed to /tmp:

$ doas mount -uo wxallowed /tmp

If you don't want to add wxallowed to /tmp you can specify the temp dir in the environment. Ensure it has wxallowed set:

# Use WORKOBJDIR which is usually set to /usr/obj (see /etc/mk.conf)2
$ doas mount -uo wxallowed /usr/obj

Building elm-lang

$ # Build with /tmp
$ runhaskell BuildFromSource.hs 0.18
$
$ # Build with a different temp dir
$ TMPDIR=/usr/obj runhaskell BuildFromSource.hs 0.18

Running elm-lang

Ensure elm binaries run from a share with wxallowed set

$ # $HOME/dev/elm-lang/Elm-Platform/0.18/.cabal-sandbox/bin
$ doas -uo wxallowed /home

Next Steps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment