Cross-compile kexec image (x86_64 host, arm64 target)

Hello nix community!

I am trying to follow an existing guide for installing nixOS onto an Oracle Cloud VM, which is written assuming the VM is x86_64 – however, in my case I am attempting to adapt the guide/approach for an ARM64 VM.

Link to the guide:

The general approach is to replace an initial Ubuntu install by booting a kexec-based image and install nixOS from there.

My difficulty at the moment is replacing the (and in the following section with something that cross-compiles a kernel from an x86_64 Linux host to arm64:

{ config, pkgs, ... }:
  imports = [
    # this will work only under qemu, uncomment next line for full image
    # <nixpkgs/nixos/modules/installer/netboot/netboot-minimal.nix>

  # stripped down version of = rec {
    image = pkgs.runCommand "image" { buildInputs = [ pkgs.nukeReferences ]; } ''
      mkdir $out
      cp ${}/bzImage $out/kernel
      cp ${}/initrd $out/initrd
      nuke-refs $out/kernel

<omitted remaining contents of kexec.nix>

So far I added the following snippet to the top of the file, and replaced some of the occurences of “pkgs” with “pkgs.crossSystem”:

let pkgs = import <nixpkgs> {
  crossSystem = {
    config = "aarch64-unknown-linux-gnu";
<kexec.nix contents from the guide...>

Hopefully someone can suggest a way how to replace config with something that is compatible with the cross-compile target!

Unless you’re pursuing this for educational value, consider using nixos-infect - works out of the box on Oracle’s ARM offerings.

Wow @ius, thanks for the tip on nixos-infect; that was super fast – and easy! – and no intermediate build machine needed. nixOS is happily running on my (free) OCI ARM64 instance; I can move on with putting Oracle’s resources to work for Folding@Home.


I’m still curious how to get a cross-compiled equivalent to the “cp ${}/bzImage $out/kernel” line, since I do some cross-compiling occasionally and I think nix has the potential to be very powerful in my cross-compiling toolbox.

1 Like