-
-
Notifications
You must be signed in to change notification settings - Fork 18k
NixOS test framework: Add macOS VMs #429189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { lib, ... }: | ||
|
|
||
| let | ||
| inherit (lib) mkOption types; | ||
| in | ||
| { | ||
| options = { | ||
| osType = mkOption { | ||
| type = types.optionType; | ||
| defaultText = lib.literalMD '' | ||
| NixOS as an option type | ||
| ''; | ||
| }; | ||
| moduleForName = mkOption { | ||
| type = types.functionTo types.deferredModule; | ||
| default = { }; | ||
| description = '' | ||
| A function that receives the machine name and returns a module that may use the machine name. | ||
| This is added to all nodes. | ||
| ''; | ||
| }; | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| { lib, hostPkgs, ... }: | ||
|
|
||
| let | ||
|
|
||
| nixThePlanet = builtins.getFlake "github:MatthewCroughan/NixThePlanet/c9d159dc2e0049e7b250a767a3a01def52c3412b"; | ||
|
|
||
| # no specific commit in particular | ||
| nix-darwin = builtins.getFlake "github:nix-darwin/nix-darwin/e04a388232d9a6ba56967ce5b53a8a6f713cdfcf"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering if the correct place of this test framework would be nix-darwin itself? Afaik all the module system of the test framework should be accessible from there as well.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was thinking to move things when it works, and the refactoring is done.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect some parts should live in NixThePlanet and some parts will make more sense to be put into nix-darwin where they can be shared between both x86 and ARM VMs
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an open issue about nix-darwin refractor to allow this to happen without flakes? |
||
|
|
||
| guestDarwin = | ||
| let | ||
| inherit (hostPkgs.stdenv) hostPlatform; | ||
| in | ||
| if hostPlatform.isDarwin then | ||
| hostPlatform.system | ||
| else | ||
| let | ||
| hostToGuest = { | ||
| "x86_64-linux" = "x86_64-darwin"; | ||
| "aarch64-linux" = "aarch64-darwin"; | ||
| }; | ||
|
|
||
| supportedHosts = lib.concatStringsSep ", " (lib.attrNames hostToGuest); | ||
|
|
||
| message = "NixOS Test: don't know which VM guest system to pair with VM host system: ${hostPlatform.system}. Perhaps you intended to run the tests on a Darwin host, or one of the following systems that may run NixOS tests: ${supportedHosts}"; | ||
| in | ||
| hostToGuest.${hostPlatform.system} or (throw message); | ||
|
|
||
| defaultDarwinModule = { config, name, ... }: | ||
| { | ||
| _file = "${__curPos.file}:${toString (__curPos.line - 1)}"; | ||
| imports = [ ./multi-os/qemu-vm.nix ]; | ||
| virtualisation.host.pkgs = hostPkgs; | ||
| }; | ||
|
|
||
| darwinBaseEval = nix-darwin.lib.darwinSystem { | ||
| system = guestDarwin; | ||
| modules = [ defaultDarwinModule ]; | ||
| }; | ||
|
|
||
| in | ||
|
|
||
| { | ||
| name = "nixos-test-driver-multi-os"; | ||
| passthru = { | ||
| /** NixThePlanet flake, for use in repl */ | ||
| inherit nixThePlanet; | ||
| /** nix-darwin flake, for use in repl */ | ||
| inherit nix-darwin; | ||
| }; | ||
| node.specialArgs = { | ||
| inherit nixThePlanet; | ||
| }; | ||
| nodes = { | ||
| # A NixOS VM | ||
| rose = { }; | ||
| # A macOS VM | ||
| daisy = { | ||
| system.stateVersion = 6; | ||
| virtualisation.diskImage = "${nixThePlanet.packages.${hostPkgs.stdenv.hostPlatform.system}.macos-ventura-image}"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be an FOD?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's an installation process into a disk image, and it's not byte for byte reproducible, so we can't slap a hash on it.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ventura is going to be EOL by the release of Nixpkgs 25.11. |
||
| virtualisation.qemu.options = [ | ||
| "-drive" "if=pflash,format=raw,readonly=on,file=${nixThePlanet.legacyPackages.${hostPkgs.stdenv.hostPlatform.system}.osx-kvm}/OVMF_CODE.fd" | ||
| "-drive" "if=pflash,format=raw,readonly=on,file=${nixThePlanet.legacyPackages.${hostPkgs.stdenv.hostPlatform.system}.osx-kvm}/OVMF_VARS-1920x1080.fd" | ||
| "-drive" "id=OpenCoreBoot,if=virtio,snapshot=on,readonly=on,format=qcow2,file=${nixThePlanet.legacyPackages.${hostPkgs.stdenv.hostPlatform.system}.osx-kvm}/OpenCore/OpenCore.qcow2" | ||
|
Comment on lines
+62
to
+64
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OpenCore is, of course, open, and we have from‐source builds of EDK II and OVMF. It would be unfortunate to consume it in the form of opaque binary blobs from the somewhat messy OSX-KVM repository that contains things like decompiled macOS code. (Again only relevant for
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just opened a wip PR for OpenCore. Builds only x86_64-linux for now, but I intend to also make it buildable on Darwin too. |
||
|
|
||
| ]; | ||
| }; | ||
| }; | ||
| machines = { | ||
| daisy = { | ||
| osType = darwinBaseEval.type; | ||
|
|
||
| }; | ||
| }; | ||
| testScript = '' | ||
| # start_all(); | ||
| daisy.succeed("uname -s | tee /dev/stderr | grep '^Darwin$'"); | ||
| ''; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think we should use
builtins.getFlakein Nixpkgs, especially to a repository that contains a bunch of legally dubious stuff. (But I assume this is just a proof‐of‐concept and the intention was to pull the relevant functionality in‐tree.)