Trouble with building SD card image for aarch64 (uboot unsupported?)

I’m trying to generate a NixOS configuration for a Raspberry Pi Zero 2 that has an SD card image. Here’s the configuration:

{ lib, pkgs, ... }:

let
  inherit (lib) mkForce;
in
{
  imports = [ "${pkgs}/nixos/modules/installer/sd-card/sd-image-raspberrypi.nix" ];

  time.timeZone = "America/Los_Angeles";

  services = {
    openssh.enable = true;
    octoprint.enable = true;
  };

  networking.useDHCP = true;

  boot = {
    kernelPackages = mkForce pkgs.linuxPackages_latest;
    supportedFilesystems = {
      # ZFS is broken on the latest kernel for aarch64
      zfs = lib.mkForce false;
    };
  };

  # https://wiki.nixos.org/wiki/FAQ/When_do_I_update_stateVersion
  system.stateVersion = "23.11";
}

I try to build the SD card image with this:

$ nix build .#nixosConfigurations.nestor.config.system.build.sdImage

I end up getting this error though:

error:
       … while evaluating 'strict' to select 'drvPath' on it
         at /builtin/derivation.nix:1:552:
       … while calling the 'derivationStrict' builtin
         at /builtin/derivation.nix:1:208:
       (stack trace truncated; use '--show-trace' to show the full trace)

       error: Package ‘uboot-rpi_0_w_defconfig-2025.01’ in /nix/store/xq5rfjj1z2r8yx338arajg5vwsxh1fri-source/pkgs/misc/uboot/default.nix:136 is not available on the requested hostPlatform:
         hostPlatform.config = "aarch64-unknown-linux-gnu"
         package.meta.platforms = [
           "armv6l-linux"
         ]
         package.meta.badPlatforms = [ ]
       , refusing to evaluate.

       a) To temporarily allow packages that are unsupported for this system, you can use an environment variable
          for a single invocation of the nix tools.

            $ export NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1

          Note: When using `nix shell`, `nix build`, `nix develop`, etc with a flake,
                then pass `--impure` in order to allow use of environment variables.

       b) For `nixos-rebuild` you can set
         { nixpkgs.config.allowUnsupportedSystem = true; }
       in configuration.nix to override this.

       c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
         { allowUnsupportedSystem = true; }
       to ~/.config/nixpkgs/config.nix.

How can I fix with this without allowing the unsupported system?

I’m on this nixpkgs commit: Revert "calamares: 3.3.13 -> 3.3.14" (#387517) · NixOS/nixpkgs@10069ef · GitHub

${pkgs} is not correct. You want ${pkgs.path}

EDIT: I’m guessing you figured that out or something, because the error you shared is not the error you would get for that mistake.

This part is saying that you’re trying to build for aarch64, but the pi 0 and pi 1 don’t have aarch64. You need to build for armv6l, which btw is not cached so you’ll be building a lot.

I though the Raspberry Pi Zero 2 uses aarch64 though? That’s what the spec sheet says at least: https://datasheets.raspberrypi.com/rpizero2/raspberry-pi-zero-2-w-product-brief.pdf

Can I get a version of uboot for aarch64? I’ll be honest, arm booting seems very complicated and I don’t know a lot about it.

oh, sorry, I missed that it was for the Zero 2. For that you don’t want to use the sd-image-raspberrypi.nix module. You want to use sd-image-aarch64.nix

Thanks, that actually builds now. Will I have to manually do some of the configuration to make it work for a Raspberry Pi?

I’m not sure what you mean?

Nevermind, it looks like that file already has some Raspberry Pi specific stuff. Thanks!

ah, yea, indeed the sd-image-aarch64.nix module is explicitly and exclusively intended for RPis.