-
Notifications
You must be signed in to change notification settings - Fork 250
Description
I would like to be able to build statically linked binaries using musl libc, satisfying native dependencies using the pkgsStatic
set in nixpkgs. The way I'd hope to be able to do this is by invoking pkgsStatic.haskell-nix.cabalProject
or similar. I want this because native dependencies are more likely to build correctly through pkgsStatic
than through pkgsCross.musl64
.
This is because the pkgsStatic
set will set isStatic = true;
for stdenv, which runs the makeStatic
adapter:
The haskell.nix docs recommend that to build static executables with musl libc, one should use pkgsCross.musl64
. Unfortunately, static building through pkgsCross.musl64
is often harder than it needs to be: because it's a non-static stdenv
, haskell.nix has to maintain its own overlay of tweaks to get packages to build statically.
This means nixpkgs releases can sometimes change the set of packages that can be used in static executables. For example, on recent nixpkgs (e.g. NixOS/nixpkgs@f01fe91 ), I can successfully build #legacyPackages.x86_64-linux.pkgsStatic.postgresql
but not #legacyPackages.x86_64-linux.pkgsCross.musl64.postgresql
, which used to be buildable under nixpkgs
25.04.
Unfortunately, it is not possible to get a modern GHC from pkgsStatic
: a nixpkgs
with the haskell.nix
overlay will fail to build (the RTS fails to link during stage1
, IIRC); and an assertion stops us from even trying in non-overlayed nixpkgs
for GHC > 9.4.8. I found NixOS/nixpkgs#382735 which says that building a fully-static GHC is hard, and that for what I want, using pkgsStatic.haskell.compiler.*
is not the right thing. Instead, @sternenseemann says:
You likely want to have a look at
pkgsStatic.buildPackages.haskell.compiler.ghc984
(which is the same aspkgsStatic.haskell.packages.ghc984.ghc
, i.e. the 9.8 compiler we use for building Haskell packages inpkgsStatic
).
Am I doing something wrong? This doesn't seem conceptually unreasonable, though I'm not sure how easy it is to change under haskell.nix
's current architecture.