How to run a NixOS on a virtual machine on MacOS with M1?

I am trying to set up NixOS on an M1 MacOS, but I have no clue where to start. As AArch64 is not supported for NixOS right now, I want to try using virtual machine instead. Is there any guide that I can follow to create NixOS on a virtual machine, like qemu or virtual box?

3 Likes

I don’t have an m1 mac but I believe the easiest free way to run an x86_64 OS is to use something like UTM which is an easy to use front end for QEMU. Keep in mind, performance may not be ideal since you will basically be emulating x86_64.

From a NixOS perspective, the install isn’t done any differently. You should be able to follow the NixOS installation guide once you have the VM up and running.

it should be possible and work much better to use arm64 nixos image

3 Likes

Aarch64 is supported by NixOS. Not that using a VM would let you use non-aarch64 anyway.

It would let you but that would be very slow because the VM would be emulated instead of virtualised.

I’ve had some success with this. I’m using VMware Fusion Tech Preview (Player Version e.x.p (18656771)). It’s technically preview software with ARM support, but I haven’t run into any issues with VMware itself.

Finding the right ISOs was a little tricky. They’re not available on the homepage anywhere, and the links in the wiki (NixOS on ARM/UEFI - NixOS Wiki) only point to unstable builds. Eventually I dug around and found Hydra - nixos:release-21.05-aarch64:nixos.iso_minimal.aarch64-linux. I should probably edit the wiki to make this more discoverable at some point.

I used my own tool, nixos-up, and after fixing a few bugs (like this and the fact that gdm doesn’t work) I was off to the races.

Unfortunately VMware guest tools are not currently supported on aarch64-linux yet. Not sure if this is an issue with nixpkgs or with the upstream builds.

2 Likes

Update: UTM is much better than vmware. Would def recommend. It’s built on qemu so setting up the spice guest agent tools is mostly a breeze.

Yea I’ve been using UTM to run my NixOS VM on my Apple Silicon machine. I’m probably eventually going to eschew it in favor of a launch daemon that just launches qemu headlessly for me to SSH into. But as a quick and painless way to get something going, UTM works quite well. And yea, spice mostly works well. I’ve had some issues where I had to fully capture the mouse and “move” it to the left forever until it finally actually moved off the edge and into the center of the screen.

1 Like

Here’s the guide from Mitchell Hashimoto (Hashicorp). Many folks seem to be quite curious about his setup GitHub - mitchellh/nixos-config: My NixOS configurations.

What I’d really like is a way to use a shared folder for / instead of a disk image. A) I imagine disk image files are very unfriendly to Time Machine. B) It’d be great to be able to read and write the files from macOS.

Read and write from the host and guest would be quite slow for primary use, but NFS or SCP could work for occasional file copies.

Asking here as I am struggling with this same task (virtualizing aarch64 NixOS on MacOS M1 using UTM): how does one go past the UEFI interactive shell? Or, put another way, if I see the UEFI interactive shell, does that mean that I set up the VM incorrectly in UTM?

(@atemu pointed out where I steered wrong so hiding the noise.)

Based on the NixOS on ARM wiki article,

  1. downloaded the latest 22.05 nixos.sd_image.aarch64-linux image from the list of builds

  2. uncompressed it with unzstd

  3. Installed UTM and created a VM using the .img file just like in this video (i.e., Create new VM → Virtualize → Other → select boot ISO image etc.)

There is a very recent blog post, NixOS on Apple silicon with UTM (August 23, 2022), seemingly going through the exact same steps, and never mentioning any of this:

(using “seemingly” because the exact steps for UTM are not specified…)

UEFI Interactive Shell u2.2
EDK II
UEFI u2.70 (EDK II, 0Ă—00010000)

Mapping table
  BLK4: Alias (s) :
    VenHw(93E34C7E-B50E-11DF-9223-2443DFD72085,00)
  BLK3: Alias (s) :
    PciRoot (0x0) /Pci (0x6,0x0)
  BLKO: Alias (s) :
    PciRoot (0x0) /Pci (0Ă—4,0x0) /USB (0Ă—7,0x0) /USB (0x0,0x0)
  BLK1: Alias (s) :
    PciRoot (0x0) /Pci (0Ă—4,0x0) /USB (0x7,0x0) /USB (0x0,0x0) /HD (1, MBR, 0x2178694E,0x4000,0xF000)
  BLK2: Alias(s):
    PciRoot (0x0) /Pci (0x4,0x0) /USB (0x7,0x0) /USB (0x0,0x0) /HD (2,MBR.0Ă—2178694E,0x13000,0Ă—61A4E8)

Press ESC in 1 seconds to skip startup.sh or any other key to continue.

Shell>

Then created a new VM by using the image file whose extension I renamed from .img to .iso (this articles states that they are identical if uncompressed), assuming the maybe there was something wrong with the format.

When I exit the UEFI interactive shell, this is what I see in BIOS(?):

image

image

You need the ISO image, not the SD image.

SD images are for embedded boards like a RPI, not systems that sport a full EFI like a UTM VM.

It works just like on an x86 PC.

1 Like

Btw, does anyone know how to get a UTM VM to correctly resize screen etc. in graphical desktops?

Which graphics driver should one use here? (Both in VM settings and NixOS drivers)

Wow, I’m indeed an in idiot - totally skipped over the “UEFI iso” section in the NixOS wiki…

Installation

Getting the installer

UEFI iso

Continue to the UEFI page.

SD card images (SBCs and similar platforms)

For AArch64 it is possible to download images from Hydra.

(… and the link to the latest ISO image in the article I quoted… Not my day, I guess…: )

Thanks a lot!

If you ever figure this out I’d really appreciate it if you could share your solution. Getting graphics right with UTM and i3, specifically, is what I’ve been stuck on for quite a while.