Skip to content

Cross compiling Raspberry Pi image fails #1943

Description

@staticintlucas

When cross compiling a Raspberry Pi image the nixos-image-sd-card step fails with the following error:

> /nix/store/0dx98qvlmgdyksxf7pf9dngmb2hwkc0r-install-rpi-firmware/bin/install-rpi-firmware: line 15: /nix/store/saxvp3mqb7w7wbd88ljh1d8b39pa4f1r-coreutils-aarch64-unknown-linux-gnu-9.11/bin/mkdir: cannot execute binary file: Exec format error

It seems like this line is causing it to try to use the aarch64 version of coreutils rather than the x86_64 version:

runtimeInputs = [ pkgs.coreutils ];


Full log:

nix log /nix/store/85mrk499zr1pfv3fbvmr6c40wv25l93p-nixos-image-sd-card-26.05.20260710.8f0500b-aarch64-linux.img.zst-aarch64-unknown-linux-gnu.drv
Decompressing rootfs image
/nix/store/lxgai6ak3wbbk3v8p3124qsh04piy7i1-ext4-fs.img.zst-aarch64-unknown-linux-gnu: 2959110144 bytes
Disk /nix/store/ahdrc3qyahcrkf759ih7bj4vqq14n02m-nixos-image-sd-card-26.05.20260710.8f0500b-aarch64-linux.img.zst-aarch64-unknown-linux-gnu/sd-image/nixos-image-sd-card-26.05.20260710.8f0500b-aarch64-linux.img: 2.79 GiB, 2998956032 bytes, 5857336 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

>>> Script header accepted.
>>> Script header accepted.
>>> Created a new DOS (MBR) disklabel with disk identifier 0x2178694e.
/nix/store/ahdrc3qyahcrkf759ih7bj4vqq14n02m-nixos-image-sd-card-26.05.20260710.8f0500b-aarch64-linux.img.zst-aarch64-unknown-linux-gnu/sd-image/nixos-image-sd-card-26.05.20260710.8f0500b-aarch64-linux.img1: Created a new partition 1 of type 'W95 FAT32' and of size 30 MiB.
/nix/store/ahdrc3qyahcrkf759ih7bj4vqq14n02m-nixos-image-sd-card-26.05.20260710.8f0500b-aarch64-linux.img.zst-aarch64-unknown-linux-gnu/sd-image/nixos-image-sd-card-26.05.20260710.8f0500b-aarch64-linux.img2: Created a new partition 2 of type 'Linux' and of size 2.8 GiB.
/nix/store/ahdrc3qyahcrkf759ih7bj4vqq14n02m-nixos-image-sd-card-26.05.20260710.8f0500b-aarch64-linux.img.zst-aarch64-unknown-linux-gnu/sd-image/nixos-image-sd-card-26.05.20260710.8f0500b-aarch64-linux.img3: Done.

New situation:
Disklabel type: dos
Disk identifier: 0x2178694e

Device                                                                                                                                                                                                        Boot Start     End Sectors Size Id Type
/nix/store/ahdrc3qyahcrkf759ih7bj4vqq14n02m-nixos-image-sd-card-26.05.20260710.8f0500b-aarch64-linux.img.zst-aarch64-unknown-linux-gnu/sd-image/nixos-image-sd-card-26.05.20260710.8f0500b-aarch64-linux.img1      16384   77823   61440  30M  b W95
/nix/store/ahdrc3qyahcrkf759ih7bj4vqq14n02m-nixos-image-sd-card-26.05.20260710.8f0500b-aarch64-linux.img.zst-aarch64-unknown-linux-gnu/sd-image/nixos-image-sd-card-26.05.20260710.8f0500b-aarch64-linux.img2 *    77824 5857335 5779512 2.8G 83 Linu

The partition table has been altered.
5779512+0 records in
5779512+0 records out
2959110144 bytes (3.0 GB, 2.8 GiB) copied, 11.5157 s, 257 MB/s
mkfs.fat 4.2 (2021-01-31)
/nix/store/0dx98qvlmgdyksxf7pf9dngmb2hwkc0r-install-rpi-firmware/bin/install-rpi-firmware: line 15: /nix/store/saxvp3mqb7w7wbd88ljh1d8b39pa4f1r-coreutils-aarch64-unknown-linux-gnu-9.11/bin/mkdir: cannot execute binary file: Exec format error

To reproduce:

flake.nix
{
  description = "NixOS flake to test cross compiling nixos-hardware";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-26.05";
    nixos-hardware = {
      url = "github:nixos/nixos-hardware";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    {
      self,
      nixpkgs,
      nixos-hardware,
      ...
    }: rec {
      nixosConfigurations.pi-4 = nixpkgs.lib.nixosSystem {
        modules = [
          "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
          nixos-hardware.nixosModules.raspberry-pi-4
          ({ ... }: {
            nixpkgs = {
              hostPlatform = "aarch64-linux";
              buildPlatform = "x86_64-linux";
            };

            users.users.test = {
              isNormalUser = true;
              extraGroups = [];
              hashedPassword = "$y$xyz$NPMgKje91gAZQ7ZOli5FU0$JC6PpwRVVMqfG3x6.QY/h8iAc1eig5oucY4BDd3/2b0";
            };

            boot.initrd.allowMissingModules = true;
          })
        ];
      };

      images.pi-4 = nixosConfigurations.pi-4.config.system.build.sdImage;
    };
}

From an x86_64 machine:

$ nix build .#images.pi-4

I would offer to fix myself, but I'm nowhere near familiar enough with nix to be confident I wouldn't mess things up further

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions