- Install
lima
. Counterintuitively, the Nix version of Lima does not support thevz
engine, so you will want to grab the binary from https://github.com/lima-vm/lima/releases/latest - Before starting the VM for the first time,
limactl edit default
: Make sure the following entries are set to these values:
vmType: "vz"
rosetta:
# Hint: try `softwareupdate --install-rosetta` if Lima gets stuck at `Installing rosetta...`
enabled: true
binfmt: true
- Start the VM, which will create the disk image (
limactl start
). - Go into the Lima shell (
lima bash
) and install Nix. - Add the following two lines to
/etc/nix/nix.conf
:
system = aarch64-linux
extra-platforms = x86_64-linux aarch64-linux
- Install Cachix-
nix-env -i cachix
andcachix use
any relevant cachix repositories sudo pkill nix-daemon
- Go back to macOS (Ctrl+D) and restart the lima vm (
limactl stop && limactl start
) - Test that x86-64 works correctly:
lima bash
thennix-shell --option system x86_64-linux --extra-platforms x86_64-linux -p bash --run "bash -c 'echo hi'"
Script to build for all four platforms {darwin,linux}╳{x86_64,aarch64):
#!/bin/sh
nix-build --no-out-link
nix-build --no-out-link --option system x86_64-darwin --extra-platforms x86_64-darwin
lima bash -ic "nix-build --no-out-link"
lima bash -ic "nix-build --no-out-link --option system x86_64-linux --extra-platforms x86_64-linux"