Skip to content

haskellPackages: allow configuring gmp when cross compiling#481162

Merged
wolfgangwalther merged 1 commit intoNixOS:haskell-updatesfrom
alexfmpe:template-haskell-cross-gmp
Feb 2, 2026
Merged

haskellPackages: allow configuring gmp when cross compiling#481162
wolfgangwalther merged 1 commit intoNixOS:haskell-updatesfrom
alexfmpe:template-haskell-cross-gmp

Conversation

@alexfmpe
Copy link
Member

@alexfmpe alexfmpe commented Jan 17, 2026

Fixed

$ nix-build -A pkgsStatic.haskell.packages.ghc910.th-orphans 
/nix/store/5y2qffwjsidcdpvs2jk8y4g2afl7kzcx-th-orphans-static-x86_64-unknown-linux-musl-0.13.16

$ nix-build -A pkgsCross.aarch64-multiplatform.pkgsStatic.haskell.packages.ghc910.th-orphans
/nix/store/n89y2gf1skypdigmprh0ph0jwda8bvni-th-orphans-static-aarch64-unknown-linux-musl-0.13.16

Triggers rebuild for

$ nix-build -A pkgsCross.aarch64-multiplatform.haskell.packages.ghc910.th-orphans
/nix/store/c4m6srj4nn12n70lwqc6jlg3af8i35wc-th-orphans-aarch64-unknown-linux-gnu-0.13.16

Not sure why pkgsCross.aarch64-multiplatform worked before as this is needed for integer-gmp flavour in #479902 as I would expect.

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.

Add a 👍 reaction to pull requests you find important.

@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. 6.topic: haskell General-purpose, statically typed, purely functional programming language labels Jan 17, 2026
@ofborg ofborg bot added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Jan 17, 2026
Copy link
Member

@sternenseemann sternenseemann left a comment

Choose a reason for hiding this comment

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

What problem are you attempting to solve here, exactly?

!(lib.meta.availableOn stdenv.hostPlatform gmp && lib.meta.availableOn stdenv.targetPlatform gmp)
!(lib.meta.availableOn stdenv.hostPlatform gmp)
|| !(lib.meta.availableOn stdenv.targetPlatform gmp)
|| stdenv.targetPlatform.isStatic
Copy link
Member

Choose a reason for hiding this comment

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

This is a bad change. It is possible to build statically with GMP enabled and this may even be useful sometimes. It is also not a problem legally per se, you just have to ensure that it is possible for users to relink the resulting executable with another version of GMP. This is ostensibly possible when providing the user with the Nix expressions via overriding etc.

Copy link
Member Author

@alexfmpe alexfmpe Jan 18, 2026

Choose a reason for hiding this comment

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

I don't have a strong opinion myself. I did it this way based on #445672 (comment) but whatever consensus you guys reach works for me.
Current status is that we don't allow gmp for static builds because they're considered cross. More specifically, we allow enableNativeBignum but then skip the --with-gmp flags, so this seemed like the smallest relaxing of constraints that made it consistent and caused static TH to build

@@ -311,6 +313,7 @@
enableUnregisterised ? false,
}:

assert !enableNativeBignum -> !stdenv.targetPlatform.isStatic;
Copy link
Member

Choose a reason for hiding this comment

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

As expressed, we shouldn't enforce this.

@alexfmpe
Copy link
Member Author

What problem are you attempting to solve here, exactly?

Currently, cross-compilation usually fails unless native-bignum is used, except for aarch64-multiplatform for some reason.

@sternenseemann
Copy link
Member

I think if we are going to flip the default for any platforms we'll need to add another subset next to native-bignum, so the gmp code path can still be accessed in a reasonable way.

@wolfgangwalther
Copy link
Contributor

I think if we are going to flip the default for any platforms we'll need to add another subset next to native-bignum, so the gmp code path can still be accessed in a reasonable way.

Yeah, I think that makes a lot of sense.

@alexfmpe
Copy link
Member Author

alexfmpe commented Jan 22, 2026

If we're ok with gmp on static builds, how about leaving the default unchanged (maybe flatten into || list) and going back to

- ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [
+ ++ lib.optionals (!enableNativeBignum)

@wolfgangwalther
Copy link
Contributor

Yeah, that makes sense to me.

Fixes error:
  linux: iserv-proxy-interpreter: Failed to lookup symbol: __gmpn_cmp
@alexfmpe alexfmpe force-pushed the template-haskell-cross-gmp branch from 8e5e347 to b6af0dc Compare January 31, 2026 02:10
@alexfmpe alexfmpe changed the title haskellPackages: allow configuring gmp when cross compiling to a different triple haskellPackages: allow configuring gmp when cross compiling Jan 31, 2026
Copy link
Member

@sternenseemann sternenseemann left a comment

Choose a reason for hiding this comment

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

LGTM, but unsure whether this could cause any regressions.

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jan 31, 2026
@alexfmpe
Copy link
Member Author

LGTM, but unsure whether this could cause any regressions.

I've been cherry-picking this into my other local branches to avoid needing to use native-bignum and haven't spotted problems yet.
Any particular host/target combinations you'd like tested?

@sternenseemann
Copy link
Member

If you've tested it, it's probably fine.

@wolfgangwalther wolfgangwalther added this pull request to the merge queue Feb 2, 2026
Merged via the queue into NixOS:haskell-updates with commit ca96121 Feb 2, 2026
31 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: cross-compilation Building packages on a different platform than they will be used on 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