Skip to content

Commit

Permalink
apple virtualization
Browse files Browse the repository at this point in the history
  • Loading branch information
zupo authored Feb 13, 2025
1 parent 7459182 commit 7312671
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions source/guides/recipes/macos
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ A big part of developing for NixOS are the [NixOS Integration Tests](https://nix

Assuming the Linux Builder is installed and running, let's run an example NixOS test with `$ nix -L build github:tfc/nixos-integration-test-example` and you should see `test script finished in ...s` in your output after a few minutes.

But what happens when tests fail? Well, you can run them in Interactive Mode to see what's going on! First, run `$ nix -L build github:tfc/nixos-integration-test-example#default.driverInteractive` to build the test driver with interactive mode then run it with `$ /result/bin/nixos-test-driver --keep-vm-state`.
But what happens when tests fail? Well, you can run them in Interactive Mode to see what's going on! First, run `$ nix -L build github:tfc/nixos-integration-test-example#default.driverInteractive` to build the test driver with interactive mode then run it with `$ ./result/bin/nixos-test-driver --keep-vm-state`.

At this point you are dropped into the Python shell of the NixOS test driver. Usually, you would type `start_all()` to start all VMs that your tests define. And now, since the test example we are using defines SSH access for testing VMs, we can actually SSH into the VM and debug them: `ssh root@localhost -p 2222`.

Expand Down Expand Up @@ -94,5 +94,13 @@ You can now run the example NixOS test with `$ nix -L build github:tfc/nixos-int

## Nested Virtualization

Use UTM.
TODO: install docs.
If you have followed this guide from the start, you might have noticed that NixOS tests [running in UTM](#nixos-in-a-virtual-machine) are slower than those [running natively on macOS](#linux-builder). Why is that?

The reason is that NixOS Tests build and start a QEMU VM, then run a python test script against this VM. And UTM is also a QEMU VM! VM inside a VM! Obviously, it would be slower!

Luckily, there is a workaround, called "nested virtualization" which allows the guest VM to passthrough CPU commands through the host VM up to the hardware host (your Mac). It's fairly easy to enable, but you do need a Mac with the M3 CPU or newer.

Follow the same process as above, but when creating the UTM image, tick the `Use Apple Virtualization` checkbox. You will have to recreate the image, but the steps are the same.


TODO: how to rerun example test

0 comments on commit 7312671

Please sign in to comment.