Skip to content

Instantly share code, notes, and snippets.

@akpoff
Last active April 2, 2024 20:17
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akpoff/a9fe8774d34021af2ac71c2b5b9e4b44 to your computer and use it in GitHub Desktop.
Save akpoff/a9fe8774d34021af2ac71c2b5b9e4b44 to your computer and use it in GitHub Desktop.
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