{"id":16321245,"url":"https://github.com/matthewcroughan/nixtheplanet","last_synced_at":"2025-05-15T13:08:37.081Z","repository":{"id":197903463,"uuid":"698405642","full_name":"MatthewCroughan/NixThePlanet","owner":"MatthewCroughan","description":"Run macOS, Windows and more via a single Nix command, or simple nixosModules","archived":false,"fork":false,"pushed_at":"2025-03-20T23:46:33.000Z","size":28109,"stargazers_count":617,"open_issues_count":10,"forks_count":17,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-15T03:49:16.291Z","etag":null,"topics":["automation","hacking","proprietary","shitcode"],"latest_commit_sha":null,"homepage":"","language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MatthewCroughan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["matthewcroughan","nixified-ai"]}},"created_at":"2023-09-29T20:59:24.000Z","updated_at":"2025-04-14T13:12:39.000Z","dependencies_parsed_at":"2024-02-16T01:32:22.569Z","dependency_job_id":"63287d73-769e-4652-9fb6-ef82e3f8d7c7","html_url":"https://github.com/MatthewCroughan/NixThePlanet","commit_stats":{"total_commits":252,"total_committers":6,"mean_commits":42.0,"dds":0.0357142857142857,"last_synced_commit":"00d07c86548805eab1bc0dac2f95fce8d7e9aac6"},"previous_names":["matthewcroughan/osx-nix","matthewcroughan/proprietarekackscheisse"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatthewCroughan%2FNixThePlanet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatthewCroughan%2FNixThePlanet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatthewCroughan%2FNixThePlanet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatthewCroughan%2FNixThePlanet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatthewCroughan","download_url":"https://codeload.github.com/MatthewCroughan/NixThePlanet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254346624,"owners_count":22055808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","hacking","proprietary","shitcode"],"created_at":"2024-10-10T22:47:07.461Z","updated_at":"2025-05-15T13:08:32.071Z","avatar_url":"https://github.com/MatthewCroughan.png","language":"Nix","funding_links":["https://github.com/sponsors/matthewcroughan","https://github.com/sponsors/nixified-ai","https://github.com/sponsors/MatthewCroughan","https://github.com/sponsors/hercules-ci"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cbr/\u003e\n\u003ca href=\"https://www.youtube.com/watch?v=u3CKgkyc7Qo\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/26458780/278759718-c3b59702-6bb4-4fbf-8a1d-fff04e933dd2.png\" height=250 title=\"Hack the Planet!\"/\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n# NixThePlanet\n\nThis is a Nix flake that allows you to run medieval operating systems, some new\nand some old. Some other candidate names for this flake were:\n\n- `ProprietareKackscheisse`\n- `nix-zoo`\n- `Windows 12`\n- `menagerie`\n\nInspired by the great [Astro](https://github.com/astro) and his [WFVM flake for building Windows VM images](https://git.m-labs.hk/M-Labs/wfvm)\n\nIt took at least a painstaking month to make this project. If you use this project and enjoy it, it would mean a lot if you could [sponsor me via GitHub Sponsors](https://github.com/sponsors/MatthewCroughan), and whilst you're at it, why not [sponsor Hercules CI too](https://github.com/sponsors/hercules-ci) for making the CI in this repo so incredible.\n\nThis code was made whilst listening to [Ｗｉｎｄｏｗｓ９６](https://www.youtube.com/watch?v=MLpcfuotLmM)\n\n# Thanks\n\nMassive thanks to the following for various kinds of help!\n\n- [Michael Hoang](https://github.com/enzime) - Getting started with the idea and nerd sniping me at [nix.camp](https://nix.camp/)\n- [Robert Hensing](https://github.com/roberth) - Putting up with endless questions about determinism\n- [Max Headroom](https://github.com/max-privatevoid) - Figuring out non deterministic fetching in `fetch-macOS-v2.py`, tl;dr [it's the Board ID](https://github.com/kholia/OSX-KVM/commit/aae332207fde2aaab209a63c3467ec94c3b32090)\n- [cleverca22](https://github.com/cleverca22/) - Helping me sift through the QEMU source code and so much more\n- [pkharvey](https://github.com/pkharvey) - Unmatched DOS/Amiga expertise and talking for countless hours about how to do this\n- [Raito Bezarius](https://github.com/RaitoBezarius/) - Explaining theory about VMs, Kernels, IO and deadlines to me in a way I could understand\n- [Gaétan Lepage](https://github.com/GaetanLepage) - Allowing me to test for weeks on his machine, installing macOS hundreds of times\n- [Felix](https://github.com/flxai) - Allowing me to test for weeks on his machine, installing macOS hundreds of times\n- [ElvishJerricco](https://github.com/ElvishJerricco) - Helping me figure out some QEMU CLI flags\n\n### Prior Art\n\nWithout work such as [OSX-KVM by Kholia](https://github.com/kholia/OSX-KVM), and [macOS-Simple-KVM](https://github.com/foxlet/macOS-Simple-KVM) by Foxlet, a repo like mine could not possibly exist. To bootstrap the project, I use some of the OSX-KVM repo as a Flake input. It contains some qcow2 files that I don't know how to reproduce yet, as noted below in the TODOs.\n\nAs [pointed out to me on Twitter](https://twitter.com/cirrus_labs/status/1727415699034062869), Cirrus Labs had made a [Hashicorp Packer template](https://github.com/cirruslabs/macos-image-templates) to do similar automation by using VNC and Sleeps. The major difference between this and what I am doing, is that I use TCL Expect and Tesseract OCR to more reliably get the same result, without relying as much on sleeps/waits. Additionally, the CI for this repo runs the macOS installer 10 times whenever anything changes, to validate that nothing is broken, and that the function `makeDarwinImage` works reliably. There is also a NixOS test that boots the VM, in a VM, and tests that the macOS VM is able to be SSH'd into on port 22.\n\n\n## macOS\n\nCurrently, only macOS Ventura is supported, building will take ***at least 40-50 minutes** as the official 11GiB macOS installer is downloaded and used in the Nix sandbox. **No user interaction is required**. Be patient and sit tight.\n\n\u003cimg src=\"https://github.com/MatthewCroughan/NixThePlanet/assets/26458780/2720900d-637c-4cc3-9dbb-3be11da8c729\"\u003e\n\n#### Launch macOS Ventura with a single `nix` command\n\n##### GTK\n\n`nix run github:matthewcroughan/NixThePlanet#macos-ventura`\n\n##### VNC (Port 5901)\n\nYou can pass QEMU flags like `-vnc`\n\n`nix run github:matthewcroughan/NixThePlanet#macos-ventura -- -vnc 0.0.0.0:1`\n\n#### Using the nixosModule\n\nTo enable the VM as a NixOS service via the `nixosModule` enable the macos-ventura module on a `nixosConfiguration` in your `flake.nix`\n\n- SSH is accessible on port 2222 by default, but is configurable via `services.macos-ventura.sshPort`\n- VNC is accessible on port 5900 by default, but is configurable via `services.macos-ventura.vncDisplayNumber`\n\n```nix\n{\n  inputs = {\n    nixtheplanet.url = \"github:matthewcroughan/nixtheplanet\";\n    nixpkgs.url = \"github:nixos/nixpkgs/nixos-23.05\";\n  };\n  outputs = { self, nixpkgs, nixtheplanet }: {\n    nixosConfigurations.my-machine = nixpkgs.lib.nixosSystem {\n      modules = [\n        nixtheplanet.nixosModules.macos-ventura\n        {\n          services.macos-ventura = {\n            enable = true;\n            openFirewall = true;\n            vncListenAddr = \"0.0.0.0\";\n          };\n        }\n      ];\n    };\n  };\n}\n```\n\n#### Using the `makeDarwinImage` function\n\nThis flake exports a function `makeDarwinImage` which takes a `diskSizeBytes` argument in order to influence the disk size of the resulting VM, it could be used like this in a `flake.nix` for example\n\n```nix\n{\n  inputs = {\n    nixtheplanet.url = \"github:matthewcroughan/nixtheplanet\";\n    nixpkgs.url = \"github:nixos/nixpkgs/nixos-23.05\";\n  };\n  outputs = { self, nixpkgs, nixtheplanet }: {\n    # Create a 60GB Darwin disk image, two ways of doing the same thing\n    # x is accessing legacyPackages directly from the flake\n    # y is applying the overlay from nixtheplanet unto its own instance of nixpkgs\n\n    x = nixtheplanet.legacyPackages.x86_64-linux.makeDarwinImage { diskSizeBytes = 60000000000; };\n    y = (import nixpkgs { system = \"x86_64-linux\"; overlays = [ nixtheplanet.overlays.default ]; }).makeDarwinImage { diskSizeBytes = 60000000000; };\n  };\n}\n```\n\nUsing the `makeDarwinImage` function directly, you could increase the size of the macOS image used by `services.macos-ventura.enable = true` in your NixOS config as follows:\n\n```nix\n{ pkgs, ... }:\n{\n  services.macos-ventura = {\n    enable = true;\n    package = pkgs.makeDarwinImage { diskSizeBytes = 60000000000; };\n  };\n}\n```\n\n# Windows/DOS\n\nEach of the outputs in this flake have their own image builders and `runScript`.\n\n- `makeMsDos622Image`\n- `makeWin30Image`\n- `makeWfwg311Image`\n- `makeWin98Image`\n\nThey can each be passed the `dosPostInstall` argument arbitrary **dos\ncommands** to be ran after Windows has been installed, for example here's how\nyou can use them to build an image that adds `win` to the `AUTOEXEC.BAT`\n\n##### Example\n\n```nix\nmakeWin30Image {\n  dosPostInstall = ''\n    c:\n    echo win \u003e\u003e AUTOEXEC.BAT\n  '';\n}\n```\n\nThe `runScript` is a method of the image builder, for example `makeWin30Image {}).runScript`. Additionally there is a `makeRunScript` method which can be passed arguments like `diskImage`.\n\n##### Example\n\n```nix\n(makeWin30Image {}).makeRunScript {\n  diskImage = makeWin30Image {\n    dosPostInstall = \"echo foo\";\n  };\n}\n```\n\n## MS Dos 6.22\n\n#### Launch MS Dos 6.22 with a single `nix` command\n\n`nix run github:matthewcroughan/NixThePlanet#msdos622`\n\n![msdos622](https://github.com/MatthewCroughan/NixThePlanet/assets/26458780/909e3953-5c9b-4eed-86ef-9183d13f0e0c)\n\n## Windows 3.0\n\n#### Launch Windows 3.0 with a single `nix` command\n\n`nix run github:matthewcroughan/NixThePlanet#win30`\n\n![win30](https://github.com/MatthewCroughan/NixThePlanet/assets/26458780/9a2b5638-190a-4fbc-b4e8-93f581776cd3)\n\n## Windows 3.11 (For Workgroups)\n\n#### Launch Windows For WorkGroups 3.11 with a single `nix` command\n\n`nix run github:matthewcroughan/NixThePlanet#wfwg311`\n\n![wfwg311](https://github.com/MatthewCroughan/NixThePlanet/assets/26458780/107dd737-64b1-4fa8-ba67-2cd979f84ac6)\n\n## Windows 98\n\n#### Launch Windows 98 with a single `nix` command\n\n`nix run github:matthewcroughan/NixThePlanet#win98`\n\n![win98](https://github.com/MatthewCroughan/NixThePlanet/assets/26458780/5f4ef28d-e38e-474c-a166-d931359c3022)\n\n# TODO\n\n- Allow diskSizeBytes to be grown by a second layer, sshing into the base image\n  and performing the necessary operations to grow the disk, instead of\n  reinstalling each time\n- Install Nix into the Darwin VM as part of the installation via SSH by using `${pkgs.nix.outPath}/scripts/install.in`\n- Support installing/initialising a [nix-darwin](https://github.com/LnL7/nix-darwin) configuration as part of the installation\n- Remove dependency on vncdo, use qemu framebuffer directly\n- Create nixosModules and VM Tests for win30, wfwg311, msdos622\n- Create derivation based checks/tests for win30, wfwg311, msdos622 using telnet\n- Find a more reproducible way of fetching macOS BaseSystems, currently the\n  board identifier determines what is fetched, and Apple changes what OS is\n  compatible with which board identifier routinely\n- Add amiga, macOS System 1 to 7, Windows 1.0, Windows 95 and Windows 98, and\n  the rest.\n- Find a way of getting serial access for Dosbox so we can make `runInWin311`\n  and similar functions\n- Implement `runInDarwinVM` using the `makeDarwinImage` primitive\n- Remove dependency on OSX-KVM that is currently being copied into the\n  repository without a git submodule\n- Reproduce OpenCore qcow2 image ourselves\n- Put screen captures into `$out` for the image builders using `vncdo`, would\n  help with debugging\n- Better logging in image builders\n- Maybe make a framework for using `expect` and `tesseract` together with Nix,\n  similar to the NixOS Testing Framework to reduce code duplication in this repo\n- Make some installation options configurable, such as initial username/pass for\n  all image builders\n- Create a watchdog to retry if failure/hanging is encountered\n- Create `runInDos` primitive using telnet and dosbox-x serial, would look\n  something like:\n  ```\n  runInDos ''\n    c:\n    echo hello world \u003e file\n  ''\n  ```\n- Make the Windows \u003c 3.11 installers less dependent on source floppy disk count,\n  perhaps by making a single 10MB FAT16/FAT12 HDD/FLOPPY with all the files in,\n  so DOSBox only has to mount a single disk, or maybe we can just make a Windows\n  rootfs ourselves from scratch\n\n# Known Issues\n\n- On some CPUs macOS will fail to boot when using multiple cores due to macOS\n  lacking drivers for host CPU timers, this has been encountered on an AMD Ryzen\n  2700U for example,\n\n- If the VM is too slow, Apple's macOS installer can hit race conditions and\n  hang. A retry of the build of the derivation will usually fix this.\n\n# Notes\n\nNotable changes to the `OpenCore-Boot.sh` script for the OSX-KVM repository that\nI am copy-pasting into this repo temporarily for bootstrapping purposes are:\n\n- Using `snapshot=on` and generating QCOW2 images backed by raw disk images to\nimprove performance and disk usage during installation phase\n- Using Virtio for all disks and gpu\n- Disabling nic during installation\n- Doing everything offline by default\n- Limiting CPU to one core and thread for determinism, there were some threading\n  issues during installation that caused non deterministic behavior and failed\n  installations that lead to this.\n\nI am also changing `scripts/run_offline.sh` to automatically partition the Disk,\nand not embedding it into the InstallAssistant, to allow for reconfiguration of\nthe run_offline script in a separate derivation.\n\n# Reviews\n\n###### Chris McDonough\n\nIn this review, Chris McDonough appears very excited. Apparently, NixThePlanet has the power to make grown men giggle.\n- www.youtube.com/watch?v=fFIDf8ZWX2w\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthewcroughan%2Fnixtheplanet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatthewcroughan%2Fnixtheplanet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthewcroughan%2Fnixtheplanet/lists"}