State of Haskell cross compilation

22.11.598.2d10e73416e (Raccoon)

So, I’ve been playing a bit with Haskell cross compilation on Nix since I’d like to target the RPi 3.
As a start, I’ve only tried:

nix-build \
-E '(import <nixpkgs> {}).pkgsCross.raspberryPi.haskellPackages.hello'

I’ve tried building several packages thus far.

It seems that every time I do, the build finally (after several minutes on a powerful setup) stops with

make: *** [Makefile:128: all] Error 2
error: builder for '/nix/store/cnclwhldzwhg7ns705n981m3p4bgy9kd-armv6l-unknown-linux-gnueabihf-ghc-9.0.2.drv' failed with exit code 2;
       last 10 log lines:
       > make[1]: *** Waiting for unfinished jobs....
       > <<ghc: 2940610848 bytes, 140 GCs, 21780236/73628784 avg/max bytes residency (7 samples), 155M in use, 0.000 INIT (0.000 elapsed), 1.410 MUT (5.387 elapsed), 0.619 GC (0.619 elapsed) :ghc>>
       > <<ghc: 998376256 bytes, 69 GCs, 21060180/61663088 avg/max bytes residency (6 samples), 133M in use, 0.000 INIT (0.000 elapsed), 0.607 MUT (2.924 elapsed), 0.493 GC (0.495 elapsed) :ghc>>
       > <<ghc: 8086654016 bytes, 596 GCs, 28987734/59064072 avg/max bytes residency (11 samples), 163M in use, 0.000 INIT (0.000 elapsed), 3.950 MUT (18.648 elapsed), 1.890 GC (1.893 elapsed) :ghc>>
       > <<ghc: 2030551904 bytes, 102 GCs, 21090424/70561856 avg/max bytes residency (7 samples), 150M in use, 0.000 INIT (0.000 elapsed), 1.240 MUT (4.066 elapsed), 0.657 GC (0.657 elapsed) :ghc>>
       > <<ghc: 5098455648 bytes, 369 GCs, 35513670/75742528 avg/max bytes residency (10 samples), 209M in use, 0.000 INIT (0.000 elapsed), 2.538 MUT (8.835 elapsed), 1.823 GC (1.828 elapsed) :ghc>>
       > <<ghc: 5610203480 bytes, 256 GCs, 29059053/88485624 avg/max bytes residency (8 samples), 206M in use, 0.000 INIT (0.000 elapsed), 3.070 MUT (10.614 elapsed), 1.659 GC (1.660 elapsed) :ghc>>
       > <<ghc: 11136763832 bytes, 365 GCs, 55362360/107386712 avg/max bytes residency (13 samples), 298M in use, 0.000 INIT (0.000 elapsed), 5.593 MUT (20.099 elapsed), 2.829 GC (2.830 elapsed) :ghc>>
       > <<ghc: 85529887200 bytes, 3645 GCs, 216536361/396925752 avg/max bytes residency (54 samples), 1075M in use, 0.000 INIT (0.001 elapsed), 36.005 MUT (180.285 elapsed), 43.307 GC (43.401 elapsed) :ghc>>
       > make: *** [Makefile:128: all] Error 2

(Full log file)

I’d say this is the simplest cross compilation example I could find for Haskell.

Am I doing something wrong?

I can confirm the same works with

  owner: NixOS
  sha256: 0wi8641v4345jcqk7myq3dknczps1gbsf48q314wavl5kga8r67f
  rev: 4b6bfecc0bd

Looks like Hydra hasn’t been able to successfully cross compile Haskell for armv6l in quite a while. Some kind of linker error relating to atomics?

armv6l isn’t a well supported platform in nixpkgs anyway, and the RPi3 supports aarch64, so try cross compiling for that with pkgsCross.aarch64-multiplatform maybe? As long as your OS can do aarch64 (which NixOS can).


After a ton of research into this (and cross compilation using Nix), it doesn’t seem reasonably reliable to cross compile Haskell to aarch64 from a different host platform, specifically owing to TH.
Given this is a serious constraint in a project I’m considering, I’d like to know what options exist to stick with Haskell and target aarch64.
One of the considerations is to fire up an AWS aarch64 instance and (natively) compile on it as part of your CI/CD.

But I’d also like to consider a local solution: eg. own hardware powerful enough to do this for me.

I’m trying to compile for Raspberry Pi and for any non-trivial project, compiling on a Pi is simply not feasible.

Obelisk supports cross compiling for mobile, and IIRC it has some hacks for template haskell.

Thanks, I’ll take a look.
I’m not very sure if I have the bandwidth to replicate that for an aarch64 though, but it might be useful for learning.