Getting your Haskell executable statically linked with Nix


Nice! I like to use file to tell if a binary is executable, viz.

$ file $(which ja)
/home/vanessa/.local/bin/ja: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=224fa312cf92297cbd4ed8fe488f77155434ac6f, stripped

I’ve also had success using the Cabal flag --enable-executable-static in place of --ghc-option=-optl=-static.

According to the docs, it passes -optl=-static and -static to GHC.

1 Like

That used to be broken on install (as opposed to build).

It was fixed here: Apply local configuration to install targets by alt-romes · Pull Request #9697 · haskell/cabal · GitHub

But I don’t know if that made it into a release yet.

You can use the gchup cabal prerelease ghcup-metadata/ghcup-prereleases-0.0.8.yaml at develop · haskell/ghcup-metadata · GitHub

ghcup config add-release-channel
ghcup install cabal latest-prerelease
1 Like