astro / microvm.nix

NixOS MicroVMs
https://astro.github.io/microvm.nix/
MIT License
1.42k stars 103 forks source link

aarch64-darwin support? #154

Open LucaAttimis opened 1 year ago

LucaAttimis commented 1 year ago

We would like to use microvm to provide staging and build environments for developers, but a few of them use apple hardware/software.

I can't find a way to use this project to run aarch64-linux vm (qemu) guest on aarch64-darwin, and I guess this is not supported.

...Is there any chance of supporting this? I am not that familiar with nix, but I might contribute a patch if you have a few pointer on where to start

astro commented 1 year ago

I guess qemu should run but I don't run Darwin myself. Contributions welcome!

sgeop commented 11 months ago

I also would love to have this capability on nix-darwin. I typically have used nixos or fedora in the past, and my work made me switch to macos on an m2 processor, which makes virtualization/containers really painful. Lima has been a decent solution, but a project this could be a game changer for mac / nix-darwin users.

Does anyone with knowledge of this project and of macos/darwin know how feasible this would be to implent?

ss-twieland commented 1 day ago

Looking at the source code of microvm, I think it should be doable.

Not knowing anything about differences in CPU architectures and also not knowing anything about virtualisation packages (e.g. qemu) and their differences, I'm just pulling that statement out of thin air.

I started by adding "aarch64-darwin" to https://github.com/astro/microvm.nix/blob/main/flake.nix#L22.

This is a search result of x86_64 and are all the areas that should be looked at:

pkgs/alioth.nix
29:    platforms = [ "aarch64-linux" "x86_64-linux" ];

flake-template/flake.nix
16:      system = "x86_64-linux";

lib/runners/cloud-hypervisor.nix
12:    x86_64-linux = "${kernel.dev}/vmlinux";
17:    if pkgs.stdenv.system == "x86_64-linux"

lib/runners/crosvm.nix
31:    x86_64-linux = "${kernel.dev}/vmlinux";

nixos-modules/microvm/options.nix
423:        Get a full list with `qemu-system-x86_64 -M help`
491:      lib.mkIf (pkgs.system == "x86_64-linux") (

checks/default.nix
15:        guestSystem = if "${system}" == "x86_64-linux" then "aarch64-unknown-linux-gnu"
16:          else "x86_64-linux";
24:            cpu = if "${system}" == "x86_64-linux" then "cortex-a53"

lib/runners/stratovirt.nix
24:    x86_64-linux =
32:    x86_64-linux = "ttyS0";

doc/src/host.md
26:      system = "x86_64-linux";

lib/runners/qemu.nix
59:      else if system == "x86_64-linux"
83:      x86_64-linux = {
142:    else if system == "x86_64-linux"
182:    lib.optionals (system == "x86_64-linux") [
274:          # romfile= does not work with x86_64-linux and -M microvm
278:            (microvmConfig.cpu == null && system != "x86_64-linux")

checks/iperf.nix
56:            "x86_64-linux" = "kvm64,+svm,+vmx";

checks/startup-shutdown.nix
65:      else if crossSystem.config == "x86_64-linux" then
66:        "x86_64"

checks/vm.nix
14:          "x86_64-linux" = "kvm64,+svm,+vmx";

lib/runners/firecracker.nix
16:    x86_64-linux = "${kernel.dev}/vmlinux";

doc/src/packages.md
22:packages.x86_64-linux.my-microvm = self.nixosConfigurations.my-microvm.config.microvm.declaredRunner;

nixos-modules/microvm/system.nix
22:      pkgs.stdenv.targetPlatform.system == "x86_64-linux" &&

doc/src/declarative.md
27:      pkgs = import nixpkgs { system = "x86_64-linux"; };

doc/src/cpu-emulation.md
40:      system = "x86_64-linux";
45:          system = "x86_64-linux";

doc/src/declaring.md
24:      system = "x86_64-linux";

Maybe we can try creating a branch and working on it together?

Mayeu commented 23 hours ago

@ss-twieland I would be happy to help test things out if need be

astro commented 22 hours ago

VMMs will need to run on Apple's virtualization technology, not Linux/KVM. It is not supported by most VMMs but I guess at least qemu should include support.

ss-twieland commented 20 hours ago

There is also the MacOS runner for github:

runs-on: macos-12