Skip to content

Instantly share code, notes, and snippets.

@donn
Last active December 5, 2023 21:29
Show Gist options
  • Save donn/5a6ab0be8d207d1726e8c31ca3543127 to your computer and use it in GitHub Desktop.
Save donn/5a6ab0be8d207d1726e8c31ca3543127 to your computer and use it in GitHub Desktop.
Lima with Rosetta 2 and Nix
  1. Install lima. Counterintuitively, the Nix version of Lima does not support the vz engine, so you will want to grab the binary from https://github.com/lima-vm/lima/releases/latest
  2. 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
  1. Start the VM, which will create the disk image (limactl start).
  2. Go into the Lima shell (lima bash) and install Nix.
  3. Add the following two lines to /etc/nix/nix.conf:
system = aarch64-linux
extra-platforms = x86_64-linux aarch64-linux
  1. Install Cachix- nix-env -i cachix and cachix use any relevant cachix repositories
  2. sudo pkill nix-daemon
  3. Go back to macOS (Ctrl+D) and restart the lima vm (limactl stop && limactl start)
  4. Test that x86-64 works correctly: lima bash then nix-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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment