NixThePlanet - Run macOS, Windows and more via a single Nix command + nixosModules

I was nerd sniped by @Enzime at nix.camp into implementing this, and here it is, over two months of painstaking work and reproducibility testing. See the README.md for more details of how it works, but the TL;DR is that it uses TCL Expect and Tesseract OCR together to automate the installation of archaic operating systems and boil them down to a single Nix command, or nixosModule.

The main attraction, I’m sure is going to be macOS, which you can enable from this flake with:

services.macos-ventura.enable = true

CI is implemented to run the macOS installer 10 times whenever it changes, catching any bugs and uploading a replay of what went wrong as screencaptures to IPFS. I’m tempted to increase that number to 100 and to start doing statistics, because VMs are tricky. But I’ve found it’s pretty reliable after 200~ runs without failure on various slow/fast hardware.

NixThePlanet introduces a few image builder functions such as makeDarwinImage and makeWin30Image which can be used like this for example:

makeWin30Image {
  dosPostInstall = ''
    c:
    echo win >> AUTOEXEC.BAT
  '';
}
makeDarwinImage { diskSizeBytes = 60000000000; };

There’s still plenty left to do in this project as you can see by the TODOs in the README.md, which you should read if you’re interested.

67 Likes

Absolutely incredible nerd-sniping result. Amazing.

7 Likes

I don’t even like macOS, or Windows. I don’t know why I did this.

38 Likes

Just tried it and it works like a charm! Thanks for doing this.

Very exited for this in the future:
Implement `runInDarwinVM` using the `makeDarwinImage` primitive

Should make building ios apps from nixos a breeze.

5 Likes

First, Thank you for your contribution.

As far as I can understand, it looks great. But I don’t understand where I can use it.

This morning I needed to run a Windows 11 application.

I ran:

quickget windows 11                                                       
quickemu --vm windows-11.conf --display spice

How does NixThePlanet compare with the above approach?

note: I know currently it’s only macOS Ventura

4 Likes

For the moment, there’s WFVM for that, which I either hope to use as a library in NixThePlanet, or integrate into it, if @astro is up for some hacking :slight_smile:

You can also run Windows 3.0, 3.11 (For Workgroups) or MS DOS 6.22 whilst you’re waiting.

2 Likes

If I understand correctly, it’s already a breeze via https://github.com/NixOS/nixpkgs/blob/0db55faf29f9fd1006d2b1c99c79657e097a6118/doc/languages-frameworks/ios.section.md, although I guess this requires running Darwin as your host. and I guess the XCode stuff isn’t automated.

1 Like

Cool project!

I hope it’s OK to share some of my projects similar to this.

https://github.com/quyse/coil-toolchain-macos - macOS VM in Nix, with Xcode command line tools, which I’ve been using successfully for CI purposes, for building a macOS version of a C++ video game in a purely Nix pipeline on Linux. Uses startosinstall script as opposed to using GUI OS installer. Some metadata URL hashes are outdated, because with latest metadata the installation script breaks, and I don’t know yet how to fix it (and couldn’t get it working yet for Sonoma).

https://github.com/quyse/coil-toolchain-msvs - infra for installing many versions of MS Visual Studio, in Nix sandbox, to use in Windows VM or Wine. Again, used successfully for the CI purposes of a video game, including Xbox version which required particular version of MSVS.

Unfortunately my repos are not really documented, sorry, has been postponing writing some docs since forever - if anyone’s interested, I’ll write some.

10 Likes

Wow! I had no idea, I’m amazed. Thank you so much for sharing.

1 Like

@quyse, since @matthewcroughan and/or the contributors to nixtheplanet seem more inclined to document, maybe you can consider merging your projects into nixtheplanet.

1 Like

I’ve been looking into startosinstall. I’m not 100% sure about it and I’d love to take everything I can get and put it into the repo, I’ve pinged @quyse on Matrix in case we can hack on it together.

1 Like