pkgsStatic.haskellPackages
is mostly usable just like the normal (non-static) Nixpkgs Haskell package set. Here’s a small example of using it (assuming you’re already familiar with Nix):
First, get into a repl with a recent Nixpkgs. For example, here’s the nixpkgs-unstable
channel from today. I think 22.05 would probably work as well:
$ nxi repl 'https://github.com/NixOS/nixpkgs/archive/52dd719bbd13d9f0974e5c3c29c74aa249e5b091.tar.gz'
Then, build any Haskell executable from pkgsStatic
. For example, here’s hlint
compiled statically:
nix-repl> :b pkgsStatic.haskellPackages.hlint
This derivation produced the following outputs:
data -> /nix/store/2d4gbwkb577wsj46bqqf9738wf2l0r18-hlint-static-x86_64-unknown-linux-musl-3.3.6-data
out -> /nix/store/8xjirxkl8n2lxz1qikdap6bvpmxrgdq0-hlint-static-x86_64-unknown-linux-musl-3.3.6
Checkout that it is actually statically-linked:
$ file /nix/store/8xjirxkl8n2lxz1qikdap6bvpmxrgdq0-hlint-static-x86_64-unknown-linux-musl-3.3.6/bin/hlint
/nix/store/8xjirxkl8n2lxz1qikdap6bvpmxrgdq0-hlint-static-x86_64-unknown-linux-musl-3.3.6/bin/hlint: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
Then run it:
$ /nix/store/8xjirxkl8n2lxz1qikdap6bvpmxrgdq0-hlint-static-x86_64-unknown-linux-musl-3.3.6/bin/hlint --version
HLint v3.3.6, (C) Neil Mitchell 2006-2021
If you’re not able to build your library statically (due to system library dependencies that can’t be built statically?), there are a couple other options:
- for simple executables, manually rewrite library paths with
patchelf
. For more complicated executables, use some sort of bundler like exodus
- a user_namespaces-based bundler like
nix bundle