Haskell on Alpine Linux

April 5, 2017

How to run Haskell on Alpine Linux, a Linux distribution built on musc libc and busybox, and which requires only 8 MB of storage for a container and 130 MB of storage for a minimal installation to disk.

Village nestled in valley between beautiful mountain peaks. class=
© 2016 Jace Grandinetti for Unsplash

Tools used in this tutorial:

  1. Stack 1.3.2
  2. Alpine Linux, 3.5.2, Standard x86_64
  3. Virtual Box, 5.1.18

Create a Virtual Server

  1. Download Alpine Linux ISO (78 MB).
  2. Create new Virtual Box of type “Linux” and version “Other Linux (64-bit)”. I gave mine 8 GB of disk used the default VDI disk type.
  3. In “Storage” section of your new Virtual Box, click the text “[Optical Drive] Empty”, and choose the disk image (the ISO) that you just downloaded.
  4. Click start.

Setup Alpine

  1. Login as root (no password).
  2. At prompt, type setup-alpine
  3. Answer prompts. Here are my answers:
    • keyboard: us
    • hostname: beets
    • networking: eth0, dhcp, no manual config
    • root password: root
    • timezone: US/Eastern
    • proxy: none
    • mirror: f (find fastest, takes a minute or two)
    • ssh server: openssh
    • ntp client: chrony
    • disk: sda, sys, y

When disk is done, you should see “Installation is complete. Please reboot.”

Remove ISO from CD drive (force unmount) and then type reboot.

If the clock on your Virtual Box is way off, add the line makestep 1 -1 to /etc/chrony/chrony.conf. This allows chronyd to make big changes to the clock quickly.

Install ghc and stack

Currently the ghc package is only in “edge”, which is the Alpine Linux development tree.

  1. login as root
  2. vi /etc/apk/repositories
  3. comment the v3.5 line and uncomment the three “edge” lines
  4. apk upgrade --update-cache --available
  5. apk add ghc
  6. apk add curl musl-dev zlib-dev
  7. curl -sSL https://get.haskellstack.org/ | sh

Note: you must use the --system-ghc option with stack, as they currently do not provide a binary ghc for Alpine Linux.

Notes

  • Alpine Linux seems to be a favorite base for Docker containers (because of small size).
  • Once Haskell is compiled, executable should run on x86_64 Alpine Linux without ghc and thus with stable packages.
  • Simple, “old-fashioned” Linux: no systemd!
  • You need to install man pages, don’t come by default.
  • Startup and shutdown of Virtual Box with Alpine Linux is very fast.

Tags: haskell alpine