How to configure QEMU binfmt wrapper on a non-NixOS machine

Hi group,

I want to build aarch64 packages using a remote builder.

I have a non-aarch64 machine baseline configured as a remote builder, meaning I can just run ssh builder nix-store --version.
The machine does not have NixOS installed but nix and nix-daemon running.

I am stuck with where to add boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; equivalent as I have no configuration.nix. Do I have to set up a qemu vm with NixOS inside ?

1 Like

Checkout the config section of the binfmt.nix module in NixOS. It’ll give you an idea of how to implement the same functionality on a non-NixOS system.

1 Like

Hi @ElvishJerricco, thanks for giving a good hint here, as far as I understand it, the remote builder running on arch linux I would have to install the binfmt packages provided in arch linux’ aur ?

Or do you mean implementing the config boot.* attribute in like home-manager, cause I’m using home-manager on that remote builder ?

Still lost somehow.

Edit: Found this as a further reference. If there is an alternative approach to try I’d be happy to contribute to it, especially the binfmt.nix based one for nix-only (but non-NixOS) setups.

Following NixOS on a Raspberry Pi: creating a custom SD image with OpenSSH out of the box | Roberto Frenna’s description I installed the needed binaries on my arch linux box and trying with the minimal sd-image.nix given in Robert’s article triggered a build using

nix-build '<nixpkgs/nixos>' -A config.system.build.sdImage --option system aarch64-linux --option sandbox false -I nixos-config=sd-image.nix

but got another error: /run/current-system/systemd/bin/systemctl is called in udev rules but is not executable or does not exist.

Regarding my last comment describing just a special case where the remote isn’t necessarily a physically different one but running inside qemu.

In most other cases installing / configuring QEMU binfmt wrapper on the other hence remote machine should just work, see this comment on github as well. Bc we are talking about non-NixOS remotes you don’t even need the configuration.nix, qemu.nix and overlay changes mentioned there.

If you’re trying to use GitHub actions and Cachix to build aarch64 derivations, you can do this with

uses: docker/setup-qemu-action@v1

or similarly, run the following installation on ubuntu:

sudo apt-get update -q -y && sudo apt-get install -q -y qemu-system-aarch64 qemu-efi binfmt-support qemu-user-static

Then do your build with

nix-build --option system aarch64-linux --extra-platforms aarch64-linux
3 Likes

It does work for me but to be precise you’ll need Ubuntu 20.04+ (old qemu version are failing because of missing syscall) and in order for your builder process to access quemu you must set --option sandbox false