The goal of hs-static-bin is to build easily Haskell static binaries through an adhoc Docker container, without never to have to login into it. The Haskell binary artifacts are delivered on the localhost with the right ownership. No localhost installation of Haskell build environment needed. Can run in a CI/CD workflow (tested with Github Actions).
[user@box ~] $ make
Usage:
show-env-vars Show hs-static-bin environment variables settings
envrc Create a .envrc for hs-static-bin environment variables
image Build hs-static-bin Docker image
pull-image Get pre-built hs-static-bin Docker image
binary Build an Haskell static binary
clean Remove static-bin/ where Haskell binary artifacts are delivered
docker-clean Remove hs-static-bin image and containers from Docker
clean-all Clean and docker-clean combined
help Show this usage notice
Copyright (c) 2025 Michel Boucey (github.com/MichelBoucey/hs-static-bin)
You have to set and export those env vars before running commands:
HASKELL_GHC_VERSION: theGHCversion to embed into the Docker imageHASKELL_CABAL_VERSION: theCabalversion to embed into the Docker imageHASKELL_GIT_REPO_URL: the URL of an Haskell Git repo capable of building executable(s) just by running acabal install-like command inside it
[user@box ~] $ export HASKELL_CABAL_VERSION=3.16.0.0
[user@box ~] $ export HASKELL_GHC_VERSION=9.8.2
[user@box ~] $ export HASKELL_GIT_REPO_URL=https://github.com/ndmitchell/ghcid
N.B.: GHC and Cabal versions are those supported by GHCup at build time.
You can check the hs-static-bin environment:
[user@box hs-static-bin] $ make show-env-vars
HASKELL_CABAL_VERSION=3.16.0.0
HASKELL_GHC_VERSION=9.8.2
HASKELL_GIT_REPO_URL=https://github.com/ndmitchell/ghcid
Optionally, based upon the hs-static-bin env vars currently exported, one can create a corresponding .envrc file.
[user@box hs-static-bin] $ make envrc
[user@box hs-static-bin] $ cat .envrc
export HASKELL_CABAL_VERSION=3.16.0.0
export HASKELL_GHC_VERSION=9.8.2
export HASKELL_GIT_REPO_URL=https://github.com/ndmitchell/ghcid
- You can build by yourself this Docker image or pull a pre-built one.
hs-static-binDocker images are tagged with the GHC version embedded, likehs-static-bin:ghc-9.8.2- You won't need to login into
hs-static-bincontainers. They normally stop onexit 0and cleared just after from Docker
Get the pre-built hs-static-bin Docker image you need from hs-static-bin package.
[user@box hs-static-bin] $ make pull-image
N.B.: if the hs-static-bin Docker image you need is missing, open an issue.
- Docker CLI plugin buildx is needed
- A single build is enough for the intended usage
[user@box hs-static-bin] $ make image
[user@box hs-static-bin] $ make binary
Once the build process is finished, one can find the Haskell stripped binary artifact in static-bin/ folder with the right ownership.
[user@box hs-static-bin] $ ls static-bin/
ghcid
N.B. : If needed, between your tries to get a build success, you can tweak and edit the script/build.sh. You won't have to rebuild the hs-static-bin Docker image with make image, because the build.sh script is dynamically mounted during the running of a hs-static-bin container, so that it can be rewritten between tries.
[user@box hs-static-bin] $ make docker-clean
N.B.: Cleans only objects with the current GHC version tag.
- Clone this repo
- Set properly and export
HASKELL_CABAL_VERSION,HASKELL_GHC_VERSIONandHASKELL_GIT_REPO_URL - Run
make pull-imageormake image - Run
make binary - Run
lddagainst the just-built binary artifact delivered instatic-bin/to check and ensure that it has no library dependencies. - Run the just-built binary artifact to check that the command is usable.