• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language
    Shell
  • Created about 5 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Docker image with GHC+musl for static executables

ghc-musl

This repository provides Docker images with GHC compiled with musl; therefore can be used to create fully static Haskell binaries without glibc dependency on any platform which can run Docker (x86_64). Powered by ghcup.

Images come with ghc and cabal executables alongside with commonly used libraries and build tools. They can also be used with the stack build tool using its Docker integration.

Here are the latest images currently published in Docker Hub:

  • utdemir/ghc-musl:v25-ghc944
  • utdemir/ghc-musl:v25-ghc925
  • utdemir/ghc-musl:v25-ghc902
  • utdemir/ghc-musl:v25-ghc8107
  • utdemir/ghc-musl:v25-ghc884

Usage

cabal-install

Mount the project directory to the container, and use cabal-install with --enable-executable-static flag inside the container:

$ cd myproject/
$ docker run -itv $PWD:/mnt utdemir/ghc-musl:v25-ghc944
sh$ cd /mnt
sh$ cabal new-update
sh$ cabal new-build --enable-executable-static

You can also set executable-static option on your cabal.project file.

stack

Use below arguments, or set the relevant options on your stack.yaml:

stack build \
  --ghc-options ' -static -optl-static -optl-pthread -fPIC' \
  --docker --docker-image "utdemir/ghc-musl:v25-ghc944" \
  --no-nix

Make sure to pick an image with the GHC version compatible with the Stackage resolver you are using.

Follow commercialhaskell/stack#3420 for more details on static compilation using the Stack build tool.

Example session with GHC

Below shell session shows how to start a pre-compiled docker container and compile a simple Hello.hs as a static executable:

$ docker run -itv $PWD:/mnt utdemir/ghc-musl:v25-ghc944
bash-4.4# cd /mnt/
bash-4.4# cat Hello.hs
main = putStrLn "Hello"
bash-4.4# ghc --make -optl-static -optl-pthread Hello.hs
[1 of 1] Compiling Main             ( Hello.hs, Hello.o )
Linking Hello ...
bash-4.4# ls -al Hello
-rwxr-xr-x 1 root root 1185056 Aug 11 16:55 Hello
bash-4.4# file Hello
Hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped
bash-4.4# ldd ./Hello
ldd: ./Hello: Not a valid dynamic program

The result can be executed on different Linux systems:

$ docker run -itv $PWD:/mnt alpine
# /mnt/Hello
Hello
$ docker run -itv $PWD:/mnt centos
[root@94eb29dcdfe6 /]# /mnt/Hello
Hello

Development

Feel free to open an issue or send a PR to add a library or support a newer compiler version.

The build process is orchestrated using Earthly. Once it is installed (or obtained via "nix-shell -p earthly"), you can use below command to build and test all images:

earthly --allow-privileged +all

Note: --allow-privileged is only necessary because we use Docker-in-Docker project to test if the generated images work with stack's Docker support. You can use the following command to disable Stack tests so that --allow-privileged is not necessary:

earthly --build-arg TEST_STACK=0 +all

The following command updates README.md:

earthly --artifact +readme/README.md

Related

More Repositories

1

nix-tree

Interactively browse dependency graphs of Nix derivations.
Haskell
632
star
2

distributed-dataset

A distributed data processing framework in Haskell.
Haskell
114
star
3

hs-nix-template

A Haskell project template that uses Nix and comes with cabal-install, ghcid, ormolu, haskell-language-server and more.
Nix
102
star
4

dotfiles-nix

Comprehensive configurations of my NixOS workstations and home server.
Nix
84
star
5

nixlisp

Nix
59
star
6

bencoder

A simple bencode decoder-encoder library in pure Python.
Python
32
star
7

qualified-imports-plugin

Haskell
16
star
8

composable-indexes

Index arbitrary JavaScript objects with multiple dimensions.
TypeScript
9
star
9

hs-pivotal-tracker

A Haskell library and a CLI tool for interacting with Pivotal Tracker
Haskell
5
star
10

recursive-let-plugin

An experiment to implement something similar to RecursiveLet proposal using GHC plugins.
Haskell
4
star
11

zsh-up

ZSH integration for the Ultimate Plumber
Shell
4
star
12

utdemir.com

Source and build scripts for my personal website.
JavaScript
4
star
13

handsy

[DEPRECATED] A Haskell DSL to describe common shell operations and interpeters for running them locally and remotely.
Haskell
4
star
14

bar

Configurable progress bars/status monitors for Python console applications.
Python
4
star
15

midye

Haskell
4
star
16

emacs-with-config

A Nix function for customizing Emacs
Emacs Lisp
4
star
17

thlpe

Haskell implementation of "The Hardest Logic Puzzle Ever"
Haskell
2
star
18

hamza

Haskell
2
star
19

dotfiles

Dotfiles for my Macbook
Shell
2
star
20

qrpush

Simple application for transferring files to a smart phone.
Ruby
2
star
21

talks

Nix
2
star
22

serverless-hs

A Haskell web framework that runs on AWS Lambda. Currently incomplete, large parts are missing, nothing is working.
Haskell
2
star
23

aoc2022

Haskell
1
star
24

network-transport-websockets

A websocket transport implementing network-transport API
Haskell
1
star
25

trying-yi

Haskell
1
star
26

allrgb

Scala
1
star
27

lmdb-safe

A bit safer lmdb binding for Haskell.
Haskell
1
star
28

apidoc-hs

Generate Haskell data types from Apidoc schemas using Template Haskell.
Haskell
1
star
29

gcal-i-am-busy

Nix
1
star
30

furby

A simplified rawdog clone, in Ruby
HTML
1
star
31

cookiecutter-haskell

Nix
1
star