Remote building NixOS packages using QEMU

contents

In a previous post I wrote about a method for remote building aarch64 packages for NixOS using a cloud ARM server, so that you can escape very long build times on the Raspberry Pi. This post does something similar, but using a faster x86_64 NixOS system, using QEMU binary wrapping.

This method is much cheaper and readily available than building on an expensive cloud server which costs $1 per hour.

Admittedly, the build is significantly slower using QEMU than it would be natively. Perhaps this can be improved by using a cross-compiler.

Generate an SSH key

On the Raspberry Pi, generate an ssh key with ssh-keygen. Copy the content of the public key to the host builder.

Host setup

Add the following to configuration.nix:

Setup on Raspberry Pi

Build on Raspberry Pi

Build, disabling local jobs:

sudo nixos-rebuild switch -I nixpkgs=. -j0

References