Skip to content

Can we build static x86_64-linux musl bindings through pkgsStatic instead of pkgsCross.musl64? #2421

@JackKelly-Bellroy

Description

@JackKelly-Bellroy

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:

https://github.com/NixOS/nixpkgs/blob/83b5b5302b3fb32038f4815639d360031b0ce2bb/pkgs/stdenv/cross/default.nix#L53

https://github.com/NixOS/nixpkgs/blob/83b5b5302b3fb32038f4815639d360031b0ce2bb/pkgs/stdenv/adapters.nix#L216-L229

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 as pkgsStatic.haskell.packages.ghc984.ghc, i.e. the 9.8 compiler we use for building Haskell packages in pkgsStatic).

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions