Skip to content

haskellPackages: fix pkgsStatic on aarch64-darwin#484571

Merged
wolfgangwalther merged 2 commits intoNixOS:haskell-updatesfrom
alexfmpe:haskell-darwin-static
Jan 28, 2026
Merged

haskellPackages: fix pkgsStatic on aarch64-darwin#484571
wolfgangwalther merged 2 commits intoNixOS:haskell-updatesfrom
alexfmpe:haskell-darwin-static

Conversation

@alexfmpe
Copy link
Member

No clue why this was fine for x86_64-linux, but on aarch64-darwin, I got

$ nix-build -A pkgsStatic.haskell.packages.ghc910.ghc
configure: error: in `/nix/var/nix/builds/nix-16170-2790439639/ghc-9.10.3-source/_build/stage1/libraries/terminfo/build':
configure: error: curses library not found, so this package cannot be built

and after fixing that, in installPhase

# Fix the mode, in case umask is set
chmod 644 '/nix/store/07mbxqfbiim3chmrk5iy1qig8449rl1m-arm64-apple-darwin-ghc-9.10.3/lib/ghc-9.10.3/lib/package.conf.d/binary-0.8.9.3-3d56.conf'
'/nix/store/07mbxqfbiim3chmrk5iy1qig8449rl1m-arm64-apple-darwin-ghc-9.10.3/lib/ghc-9.10.3/bin/ghc-pkg' --global-package-db "/nix/store/07mbxqfbiim3chmrk5iy1qig8449rl1m-arm64-apple-darwin-ghc-9.10.3/lib/ghc-9.10.3/lib/package.conf.d" recache
if [ -d docs-utils ]; then \
	/nix/store/hf6y9njhfwvigr25kzrwmsvmv6jpni5n-coreutils-9.9/bin/install -c -m 755 -d "/nix/store/1503p0agvzgr8hcrgcv1f9cm344cxjfd-arm64-apple-darwin-ghc-9.10.3-doc/share/doc/arm64-apple-darwin-ghc/html/libraries/"; \
	/nix/store/hf6y9njhfwvigr25kzrwmsvmv6jpni5n-coreutils-9.9/bin/install -c -m 644 docs-utils/prologue.txt "/nix/store/1503p0agvzgr8hcrgcv1f9cm344cxjfd-arm64-apple-darwin-ghc-9.10.3-doc/share/doc/arm64-apple-darwin-ghc/html/libraries/"; \
	/nix/store/hf6y9njhfwvigr25kzrwmsvmv6jpni5n-coreutils-9.9/bin/install -c -m 755 docs-utils/gen_contents_index "/nix/store/1503p0agvzgr8hcrgcv1f9cm344cxjfd-arm64-apple-darwin-ghc-9.10.3-doc/share/doc/arm64-apple-darwin-ghc/html/libraries/"; \
fi
/nix/var/nix/builds/nix-51825-2701879890/ghc-9.10.3-source
ghc-settings-edit: /nix/store/07mbxqfbiim3chmrk5iy1qig8449rl1m-arm64-apple-darwin-ghc-9.10.3/lib/arm64-apple-darwin-ghc-9.10.3/lib/settings: openFile: does not exist (No such file or directory)

Notice the lines before the last refer to lib/ghc-9.10.3/ while settings is searched for in lib/arm64-apple-darwin-ghc-9.10.3

These issues are due to the discrepancies pointed out in #383165.
We have at least 3 layers to think about regarding what counts as "native" builds:

  1. hostPlatform.canExecute targetPlatform
  2. hostPlatform.config == targetPlatform.config
  3. hostPlatform == targetPlatform

AFAICT, 3 implies 2 implies 1. We've mostly looked at 3, while ghc mostly looked at 2.
We might need to re-think things some in general, but changing common-hadrian.nix to use 2 instead of 3 in these places seems to be an improvement as it fixes pkgsStatic. Was able to build and run pkgsStatic.haskell.packages.ghc910.hello

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

@alexfmpe alexfmpe requested review from sternenseemann and wolfgangwalther and removed request for wolfgangwalther January 27, 2026 23:14
@nixpkgs-ci nixpkgs-ci bot requested a review from maralorn January 27, 2026 23:26
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Jan 27, 2026
@alexfmpe alexfmpe force-pushed the haskell-darwin-static branch from 955d0d3 to c83edba Compare January 28, 2026 00:25
@nixpkgs-ci nixpkgs-ci bot added the 6.topic: haskell General-purpose, statically typed, purely functional programming language label Jan 28, 2026
@wolfgangwalther wolfgangwalther changed the title haskellPackages: fix pkgsStatic haskellPackages: fix pkgsStatic on aarch64-darwin Jan 28, 2026
Copy link
Contributor

@wolfgangwalther wolfgangwalther left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have similar changes on my local branch for darwin static support, but I have more changes in generic-builder, too. I believe there are more places where our builder differs from GHC in its judgement about "are we cross".

We might need more of these to build other packages than just hello, but we can do that later.

Will kick off another build here before merging.

@wolfgangwalther
Copy link
Contributor

No clue why this was fine for x86_64-linux, but on aarch64-darwin,

It works for x86_64-linux, because the triple is not the same there - pkgsStatic uses musl, not glibc. You can get the same failure modes on x86_64-linux for pkgsMusl.pkgsStatic, which does musl native -> musl static cross.

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jan 28, 2026
@wolfgangwalther wolfgangwalther added this pull request to the merge queue Jan 28, 2026
@wolfgangwalther
Copy link
Contributor

This fixes basic pkgsStatic on darwin, which works fine. Doing TemplateHaskell on darwin in the sandbox is still not working, but that's for later. We'll just need to allow local networking, I guess - it errors with:

iserv-proxy: Uncaught exception ghc-internal:GHC.Internal.IO.Exception.IOException:

Network.Socket.connect: <socket: 12>: permission denied (Operation not permitted)

Merged via the queue into NixOS:haskell-updates with commit 672bdf5 Jan 28, 2026
32 of 34 checks passed
@alexfmpe
Copy link
Member Author

We'll just need to allow local networking, I guess

Annoyingly, I couldn't simply __darwinAllowLocalNetworking = true on iserv-proxy. It's the derivation that's ran that needs it, but since we don't know at eval time what needs TemplateHaskell, we'd always need to enable it for at least pkgsStatic on darwin.

Maybe I can relax that requirement via #445672 (comment). It wouldn't work for wine but don't think we need it there anyway.

@alexfmpe
Copy link
Member Author

alexfmpe commented Jan 28, 2026

We might need more of these to build other packages than just hello, but we can do that later.

A lot of packages build with this change, including ones needing template-haskell.
Though some hit Failed to load dynamic interface file for <import>.
For instance, language-nix

[1 of 4] Compiling Language.Nix.Identifier ( src/Language/Nix/Identifier.hs, dist/build/Language/Nix/Identifier.o, dist/build/Language/Nix/Identifier.dyn_o )
src/Language/Nix/Identifier.hs:20:1: error: [GHC-47808]
    Failed to load dynamic interface file for Control.Lens:

Haven't noticed any other failures specific to "static cross" yet, but I'll wait for your local fixes until I poke around these parts again.
FYI building haskell-language-server is a pretty decent stress test as it has ~250 deps

@wolfgangwalther
Copy link
Contributor

Haven't noticed any other failures specific to "static cross" yet, but I'll wait for your local fixes until I poke around these parts again.

Mine are not done and I haven't worked on them in a while, so don't wait for them. This was mostly taken out of #383165. I don't remember anymore where I hit other things exactly, they have possibly been fixed in the meantime in better ways or so.

If a lot of stuff is building, except for TH due to networking, that is a great sign.

@sternenseemann
Copy link
Member

As I've stated before, in general, I'm not in favor of appeasing build systems in this manner. With the external interpreter, we did find a solution that, in particular, did not involve making hadrian believe we were natively compiling in order to get pkgsStatic to work, so we should really try to continue in this direction.

Especially matching on the config alone is an ugly hack that breaks the expectations of Nixpkgs users.

@alexfmpe
Copy link
Member Author

we should really try to continue in this direction.

Fair enough, but how?
Are you saying we should instead backport the terminfo patch and unconditionally enable the target prefix?

@wolfgangwalther
Copy link
Contributor

wolfgangwalther commented Jan 31, 2026

As I've stated before, in general, I'm not in favor of appeasing build systems in this manner.

I assume that was in #383165 - but the change proposed there was a lot different. That PR actually pretended native for the cross case, which is not the case here.

This PR has two changes:

  • The change to the default value for enableTerminfo. The user can always override this. This also only extends the already existing hack, which has been fixed upstream for later versions - so this is going to go away in the future anyway.
  • The change to targetPrefix. We already have a TODO there to make this unconditional. This means that any change that uses the targetPrefix in more cases than before is actually the right direction. (Edit: This logic is flawed, because this change actually uses the target prefix in fewer cases)

Thus, I think this PR is entirely fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: haskell General-purpose, statically typed, purely functional programming language 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants