Cross-compiling to arm


Hey, I am trying to cross compile something for arm on my x86 NixOS right now, but can’t manage to get the proper toolchain in my environment.

Basically, I only need arm-linux-gnueabihf-gcc, etc. in a nix-env or nix-shell, but cannot seem to figure out how to do this.
I found some stuff on the nixpkgs bugtracker, but that was mainly about derivations using crossSystem, which is not what I need.

This seems quite trivial, but I just cannot find a proper package or way to achieve this.


I believe you don’t want to differ much from regular cross-builds. I would go as if writing an expression for nix-build, in the respect of setting those cross parameters and specifying (native) build inputs (no need for source, build scripts, etc.) – and put that expression into a shell.nix in your development directory.


Yeah I think you’re wanting something like:

nix-env -iA --arg crossSystem '{ config = "arm-linux-gnueabihf"; }'


My Raspberry Pi wants to build llvm for some reason. Since it would take ages on the little chip I thought I might cross-compile it on my desktop. I tried nix-env -iA nixos.llvm_6 --arg crossSystem '{ config = "arm-linux-gnueabihf"; }' but it fails with error: missing kernelArch. How might I fix this?


You need to pass a platform attribute. You can do that with:

nix-env -iA nixos.llvm_6 --arg crossSystem '{ config = "arm-linux-gnueabihf"; platform = (import <nixos/lib>).systems.platforms.raspberrypi; }'


Might be a good place to bring up how timeouts in aarch64 seems to be making me compile llvm_6 and gfortran myself. gfortran has been timing out for quite a while on hydra and llvm_6 only seems to be a problem for staging-next even though everything seems to finish fine but just times out.


I tried this but it ends at 17 % with an error of

[ 17%] Built target LLVMDebugInfoPDB
make: *** [Makefile:152: all] Error 2
builder for '/nix/store/2l3slvk0dpsjf73w6i1yyy9d4whjgci1-llvm-6.0.1-arm-linux-gnueabihf.drv' failed with exit code 2
error: build of '/nix/store/2l3slvk0dpsjf73w6i1yyy9d4whjgci1-llvm-6.0.1-arm-linux-gnueabihf.drv' failed


Well, yes, we’ll need to do something systematic about these aarch64 timeouts on Hydra, but that’s actually not a practical problem with cross-compilation, as x86 builders seem fast enough not to suffer from this.