Compiling rpi4 kernel in on x86_64 nixos-hardware slow

Why are you generating a new pkgs instance? Wouldn’t pkgs already provide pkgsCross.aarch64-multiplatform?

Thank you! Indeed, neither nixpkgs or nixos-hardware were being passed to pkgsCrossAarch64.callPackage "${nixos-hardware}/raspberry-pi/common/kernel.nix" { rpiVersion = 4; }, so it had nothing to refer to when trying to do the substitution.

@eblechschmidt I’m not sure, my Nix is not great, so I’m really just following in the steps of @Tert0 here.

I did not end up cross compiling because for me the main line kernel worked perfectly fine.

I think that solution assumes you are using nixos-hardware. And probably does require passing it via specialArgs as per @Tert0 previous post.

I think that was more a question for @Tert0 here. I imagine the answer is that he found something that worked, and did not try to optimize it.

In which case this probably should work fine also (I have not tested any of this!):slight_smile:

let
  pkgsCrossAarch64 = pkgs.pkgsCross.aarch64-multiplatform;
in
{
  boot.kernelPackages = pkgsCrossAarch64.linuxPackagesFor (
    pkgsCrossAarch64.callPackage "${nixos-hardware}/raspberry-pi/common/kernel.nix" { rpiVersion = 4; }
  );
}

In which case, only nixos-hardware needs to be added to specialArgs.

mainline kernel, if that works, is the best solution. But this wont work (at least not that I have worked out how) if using non-standard hardware, e.g. DSI based touch screen.

No, I first tried it like this and then later added the separate nixpkgs instantiation with system = "x86_64-linux".

The existing pkgs instance has system = "aarch64-linux" so when using pkgs.pkgsCross.aarch64-multiplatform nixpkgs tries to cross-compile for aarch64-linux from aarch64-linux (and still uses qemu due to the host being x86_64-linux).

You are absolutely right, I completely missed that this is of course inside the aarch64-linux instance of pkgs.

You are right. If you are using special hardware features the main line kernel does not work.

Is it necessary to migrate to UEFI to use generic kernel?
How can I migrate to UEFI?
Are there any tutorials?

I see you have added 1 drives in your config (/dev/disk/by-uuid/BE86-6532). What is that? Is the original 30M FIRMWARE partition not used anymore? appreciated for help

The generic kernel wasn’t been loaded properly with uboot so I had to repartition my drive. I’ve added sn EFI partition which is formatted to FAT32. It is called boot partition in the manual NixOS Manual

You may need to update EEPROM before migrating because UEFI is supported by newer firmwares. See NixOS on ARM/Raspberry Pi - Official NixOS Wiki Operational Notes → EEPROM Updates section and mentioned https://www.raspberrypi.com/documentation/computers/configuration.html#update-bootloader-version

Unfortunately, one of the limitations/features of uboot is that you need to specify the address in memory to load the kernel, initrd and possibly device tree.

This can cause failures to boot if the address ranges overlap (from one of those three getting larger than the space allocated for it) and while the default addresses are updated in NixOS as needed, NixOS doesn’t update the addresses in existing installations.

I don’t know if this is the issue in this case, however it’s an issue with the same symptoms that is more likely with a major kernel update (because of the increase in kernel and module size).

Thank you very much! I have successfully migrated from uboot to UEFI and now I can boot with mainline kernel! No more 1x hours compiling of kernel, that’s really great!
Its just a headless server so mainline kernel is fine!