Does pkgs.linuxPackages_rpi3 build all required kernel modules?

I’m trying to cross build a nixos image for my rpi 3 b+.
I looked at the wiki (NixOS on ARM - NixOS Wiki) and im using binfmt on fedora and it seems to almost work.

Here is a minimal config i tried:

{ config, pkgs, lib, ... }:
{
  imports = [
    <nixpkgs/nixos/modules/installer/sd-card/sd-image-aarch64-installer.nix>
  ];

  sdImage.compressImage = false;

  system.stateVersion = lib.mkDefault "23.11";

  boot.loader.grub.enable = false;
  boot.loader.generic-extlinux-compatible.enable = true;

  boot.kernelPackages = pkgs.linuxPackages_rpi3;

  boot.kernelParams = ["cma=256M"];
}

Building like this →

nix-build '<nixpkgs/nixos>' -A config.system.build.sdImage -I nixos-config=./configuration.sdImage.nix --option sandbox false --argstr system aarch64-linux

and i added this to /etc/nix/nix.conf

extra-platforms = aarch64-linux
extra-sandbox-paths = /usr/bin/qemu-aarch64-static

And somehow this fails

kernel version is 6.1.21
root module: ahci
modprobe: FATAL: Module ahci not found in directory /nix/store/yl2pbh7ki89ysnz6cpdqv2jiayr83lqy-linux-6.1.21-1.20230405-modules/lib/modules/6.1.21
error: builder for '/nix/store/c9zns95sk29w2j6rqir6rfdac6rgz41q-linux-6.1.21-1.20230405-modules-shrunk.drv' failed with exit code 1;
       last 3 log lines:
       > kernel version is 6.1.21
       > root module: ahci
       > modprobe: FATAL: Module ahci not found in directory /nix/store/yl2pbh7ki89ysnz6cpdqv2jiayr83lqy-linux-6.1.21-1.20230405-modules/lib/modules/6.1.21
       For full logs, run 'nix log /nix/store/c9zns95sk29w2j6rqir6rfdac6rgz41q-linux-6.1.21-1.20230405-modules-shrunk.drv'.
error: 1 dependencies of derivation '/nix/store/7zklzi463qyk1i4ablnkf9a2cd1lwc7y-stage-1-init.sh.drv' failed to build
building '/nix/store/slimqbsj7j4zd5s9n30vkggs0nfwa54q-firewall-reload.drv'...
error: 1 dependencies of derivation '/nix/store/fvph9sg2z86g40h85r9zpikj05ir1m77-initrd-linux-6.1.21-1.20230405.drv' failed to build
error: 1 dependencies of derivation '/nix/store/9c84jys81nkrdi01lrihg32pfx23igqq-nixos-system-nixos-23.11pre493358.a30520bf8ea.drv' failed to build
error: 1 dependencies of derivation '/nix/store/iv2lxrbms689bmriyc6kngqh0b5ql0hy-ext4-fs.img.drv' failed to build
error: 1 dependencies of derivation '/nix/store/vhvww79j62x6diqhv5xmzqv0yvhi9qwq-nixos-sd-image-23.11pre493358.a30520bf8ea-aarch64-linux.img.drv' failed to build

Am not really sure how to continue from this or what am i missing?

I think this is a known issue. In my experience, fixable with this overlay.

1 Like

I struggled a bit to configure the overlay but this works

{ config, pkgs, lib, ... }:
{
  nixpkgs.overlays = [
    (final: super: {
      makeModulesClosure = x:
        super.makeModulesClosure (x // { allowMissing = true; });
    })
  ];
  system.stateVersion = lib.mkDefault "23.11";

  imports = [
    <nixpkgs/nixos/modules/installer/sd-card/sd-image-aarch64-installer.nix>
  ];

  sdImage.compressImage = false;

  boot.loader.grub.enable = false;
  boot.loader.generic-extlinux-compatible.enable = true;

  boot.kernelPackages = pkgs.linuxPackages_rpi3;

  # !!! Needed for the virtual console to work on the RPi 3, as the default of 16M doesn't seem to be enough.
  # If X.org behaves weirdly (I only saw the cursor) then try increasing this to 256M.
  # On a Raspberry Pi 4 with 4 GB, you should either disable this parameter or increase to at least 64M if you want the USB ports to work.
  boot.kernelParams = ["cma=256M"];
}
2 Likes