!ayCRiZriCVtuCUpeLp:nixos.org

Nix Cross Compiling

538 Members
110 Servers

Load older messages


SenderMessageTime
25 Nov 2025
@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
@artturin:matrix.orgArtturincool18:55:16
@ebnull:matrix.orgeb

I cross compile to my raspis

What configuration settings do you use here? I'm new to this one too, and I see I can choose (mainline | proprietary) kernel, (nixpkgs stable | nix-hardware | raspberry-pi-nix) for hardware support.

18:58:52
@ebnull:matrix.orgebThis particular pi is a 4b and will be headless, so I don't need to have much desktopy stuff on it18:59:20
@artturin:matrix.orgArtturinThe biggest obstacle to making it all automatic with nix-forecast and a script is nested attrs but just changing the top-level attrs will increase the cache hits by a lot18:59:45
@artturin:matrix.orgArtturin
  boot = {
    supportedFilesystems = {
      btrfs = lib.mkForce false;
      cifs = lib.mkForce false;
      f2fs = lib.mkForce false;
      ntfs = lib.mkForce false;
      xfs = lib.mkForce false;
      zfs = lib.mkForce false;
    };
    # Make the kernel much lighter to build, otherwise needs 30G+ ram
    kernelPatches = [
      {
        name = "disable-bpf";
        patch = null;
        extraConfig = ''
          DEBUG_INFO_BTF n
          CONFIG_DEBUG_INFO_BTF n
        '';
      }
    ];
    initrd.allowMissingModules = true;

    tmp.useTmpfs = true;
  };

Didn't change the kernel

19:00:42
@ebnull:matrix.orgeb

obstacle to making it all automatic with nix-forecast

I figured the biggest issue would be that it's not easy to map cached store paths back to attr / package names

19:01:01
@artturin:matrix.orgArtturin

Also got these to not compile gtk

  nixpkgs.overlays = [
    (final: prev: {
      stoken = prev.stoken.override { withGTK3 = false; };
      alsa-utils = prev.alsa-utils.override {
        withPipewireLib = false;
        fftw = null;
      };
      alsa-plugins = prev.alsa-plugins.override {
        libpulseaudio = null;
        speexdsp = null;
      };
      sdl2 = prev.sdl2.override {
        pipewireSupport = false;
        pulseaudioSupport = false;
        x11Support = false;
        jackSupport = false;
      };
      ffmpeg = prev.ffmpeg_7-headless.override {
        withSpeex = false;
        withOpenmpt = false;
      };
    })
  ];
19:01:04
@artturin:matrix.orgArtturin *

Also got these to not compile gtk and some other packages

  nixpkgs.overlays = [
    (final: prev: {
      stoken = prev.stoken.override { withGTK3 = false; };
      alsa-utils = prev.alsa-utils.override {
        withPipewireLib = false;
        fftw = null;
      };
      alsa-plugins = prev.alsa-plugins.override {
        libpulseaudio = null;
        speexdsp = null;
      };
      sdl2 = prev.sdl2.override {
        pipewireSupport = false;
        pulseaudioSupport = false;
        x11Support = false;
        jackSupport = false;
      };
      ffmpeg = prev.ffmpeg_7-headless.override {
        withSpeex = false;
        withOpenmpt = false;
      };
    })
  ];
19:01:10
@artturin:matrix.orgArtturin And I import (modulesPath + "/profiles/minimal.nix") 19:02:51
@artturin:matrix.orgArtturinJust updated my raspi and took me 1H to compile everything on r5 5900x19:03:35
@artturin:matrix.orgArtturin* Just updated my raspi and took me 1H to compile everything on r9 5900x19:03:42
@ebnull:matrix.orgebThanks for all the info!19:06:35

There are no newer messages yet.


Back to Room ListRoom Version: 6