I’m using a Flake to define a NixOS system for a Raspberry Pi. By setting:
nixpkgs.buildPlatform = "x86_64-linux";
nixpkgs.hostPlatform = "aarch64-linux";
I’m able to cross-compile NixOS on my x86 box, i.e. I can generate an SD card image like this:
nix build .#nixosConfigurations.sandy.config.system.build.sdImage
Which boots up fine on the Pi.
Now the issue is that nixos-rebuild
seems to want to run aarch64 binaries on my build host:
❯❯ nixos-rebuild switch --flake .#sandy --target-host 192.168.0.81 --use-remote-sudo
/nix/store/svk2dgsb1j87z6sqb3c5257d6n0l4vf8-nixos-rebuild/bin/nixos-rebuild: line 443: /nix/store/7hwrcf22m39i3mx7qxwbjjidnz2in777-coreutils-aarch64-unknown-linux-gnu-9.6/bin/mktemp: cannot execute binary file: Exec format error
I have a feeling there’s a way to work around this by just getting my x86 host to support running Arm binaries with binfmt_misc hackery, but I don’t really wanna do that if I can avoid it. (My x86 host system is not NixOS, plus this is inefficient and generally unsatisfying).
Also, I tried setting --build-host
to point to the Pi as well, this is also not really a solution but I wanted to see what would happen. Turns out I still got the Exec format error
which is a bit surprising…
Does anyone know what I’m missing here?