!ayCRiZriCVtuCUpeLp:nixos.org

Nix Cross Compiling

550 Members
116 Servers

Load older messages


SenderMessageTime
24 Nov 2025
@szlend:matrix.orgszlend Alyssa Ross: there's one more libcap issue that I fixed here: https://github.com/NixOS/nixpkgs/pull/461685 20:31:16
@szlend:matrix.orgszlendcross was fixed but not from darwin20:31:22
@qyliss:fairydust.spaceAlyssa Rossah, I see20:32:04
@qyliss:fairydust.spaceAlyssa RossI might not have a minute this week I'm afraid20:32:12
@szlend:matrix.orgszlendgot it to build manually but I can't confirm with nixpkgs-review :D 20:32:13
@limwa:matrix.orgAndré Lima set a profile picture.21:10:24
25 Nov 2025
@ebnull:matrix.orgeb joined the room.18:21:36
@ebnull:matrix.orgeb

Hey all, I'm just starting to get into cross compiling (x68 -> aarch64 for rpi 4b), and have some questions about how to best approach this. I'll start with my understanding and situation to make sure I didn't make a mistake:

  • I'm using flakes, which don't exactly have first class support for cross compilation.
  • I'm manually creating my pi's nixosConfigurations key and making my own nixpkgs.pkgs for it.
  • It seems like for this pkgs argument, I have two options: The first, is create it with localSystem == crossSystem == "aarch64-linux". If I do this, I'd need to rely on binmft style emulation to build from my x86 machine. The second, is create it with localSystem = x86-linux; crossSystem = "aarch64-linux". If I do this, I'm doing real cross compilation.
  • With the former I can use cache.nixos.org to grab the aarch64 components, but I'd need to emulate-build everything else.
  • With the latter I can't use the cache at all, so I need to build everything.

Ideally I could use the cache and cross compile only if needed, but it looks like I can't do that without manually choosing specific packages to be cross compiled with pkgsCross attributes in the first method, right? And if I did want this, then my buildSystem would need to support emulation, right?

My buildSystem is currently Ubuntu, so I can't just flip the nixos switch for binfmt emulation. I could probably apply the binfmt config manually if I want to go the emulation route, right?

I suppose I might just be frustrated that I can't default crossSystem and opportunistically grab the non-cross packages from the aarch64 cache, though I know the technical reason why (store paths are functions of all inputs, and crossSystem is an input). I'm guessing this is currently an unsolved issue?

Thanks!

18:32:34
@artturin:matrix.orgArtturinNixOS system cross is the exact same with flakes as it is without18:33:32
@ebnull:matrix.orgebI get that; flakes are not my main issue on this. I'm just providing context there.18:35:43
@artturin:matrix.orgArtturin

With the latter I can't use the cache at all, so I need to build everything.

There's some packages cached https://github.com/NixOS/nixpkgs/blob/75c025c6135ca219cded2592343bef3daa4b39b9/pkgs/top-level/release-cross.nix#L239
https://github.com/NixOS/nixpkgs/blob/75c025c6135ca219cded2592343bef3daa4b39b9/pkgs/top-level/release-cross.nix#L78-L105

18:37:22
@artturin:matrix.orgArtturin

My buildSystem is currently Ubuntu, so I can't just flip the nixos switch for binfmt emulation. I could probably apply the binfmt config manually if I want to go the emulation route, right?

Yup binfmt is possible to setup on all distros

18:38:09
@artturin:matrix.orgArtturin

Ideally I could use the cache and cross compile only if needed, but it looks like I can't do that without manually choosing specific packages to be cross compiled with pkgsCross attributes in the first method, right? And if I did want this, then my buildSystem would need to support emulation, right?

Can't automatically pick the packages to get from the cache and which to cross-compile. You can however make a second native nixpkgs instance to pick packages from

18:40:19
@artturin:matrix.orgArtturin *

Ideally I could use the cache and cross compile only if needed, but it looks like I can't do that without manually choosing specific packages to be cross compiled with pkgsCross attributes in the first method, right? And if I did want this, then my buildSystem would need to support emulation, right?

Can't automatically pick the packages to get from the cache and which to cross-compile. You can however make a second native nixpkgs instance to pick packages from, you could even overlay them.

18:40:29
@ebnull:matrix.orgeb

Can't automatically pick the packages to get from the cache and which to cross-compile.

Could I introspect the cache somehow (outside of nix, ahead of time) and add a nixpkgs overlay based on pname to select between ( native | cross ), hoping that the hashes will then match?

18:43:18
@ebnull:matrix.orgeb

You can however make a second native nixpkgs instance to pick packages from, you could even overlay them.

If I do set up binfmt emulation, and I'm using a stable nixos branch that hydra has cached, and not building custom packages, should I expect a 99% cache hit rate, and then the last bit is essentially making the sdcard images which I'd need to do locally?

18:44:51
@ebnull:matrix.orgeb(also I haven't said this yet - thank you for your help!)18:45:24
@artturin:matrix.orgArtturinnix-forecast for a specific installable status https://github.com/getchoo/nix-forecast hydra-check for general status https://github.com/nix-community/hydra-check18:46:20
@artturin:matrix.orgArtturinCould probably make something with those18:46:29
@artturin:matrix.orgArtturin The pkgs instance of a config can be accessed like this nixosConfigurations.ArtDesktop.pkgs.hello 18:48:06
@ebnull:matrix.orgeb

nix-forecast

Very nice, looks like something that will be very useful for a/b comparisons. Thanks for the pointer!

hydra-check

Good to know, but probably more useful for those actively hacking on nixpkgs

18:49:03
@artturin:matrix.orgArtturinaarch64-linux is pretty well supported so I guess so18:51:17
@artturin:matrix.orgArtturinhttps://hydra.nixos.org/job/nixos/trunk-combined/tested#tabs-constituents18:51:24
@artturin:matrix.orgArtturinx86_64-linux and aarch64-linux stuff tested there18:51:36
@artturin:matrix.orgArtturinI cross compile to my raspis but when I've done a nix shell on them I haven't needed to compile packages18:52:15
@artturin:matrix.orgArtturinIf you do hack something up then let us know, I'm interested18:53:04
@ebnull:matrix.orgeb per nix-forcast, if I do emulation I get a 99.64% cache hit, but with cross I get a 63.74% hit rate. Interesting, and probably supports that setting up binfmt on this ubuntu machine is worth it 18:53:25
@ebnull:matrix.orgebInteresting, I suppose it makes sense that a nix shell wouldn't need to compile - but I guess you still need to download to the store (since locally you have the crosscompiled version)18:54:47
@artturin:matrix.orgArtturin 69.87% of paths available (1746 out of 2499) 18:54:52
@artturin:matrix.orgArtturinHadn't used that before18:55:13

Show newer messages


Back to Room ListRoom Version: 6