Skip to content
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

macOS support? #16

Open
ggPeti opened this issue Aug 4, 2020 · 9 comments
Open

macOS support? #16

ggPeti opened this issue Aug 4, 2020 · 9 comments

Comments

@ggPeti
Copy link

ggPeti commented Aug 4, 2020

what is needed?

@Mic92
Copy link
Owner

Mic92 commented Aug 5, 2020

This would need some major refactorings in nixpkgs itself. Qemu would need to be built for macOS itself, while the image itself needs to target Linux. Basically the NixOS module that provides our qemu abstraction needs to evaluate on macOS and than nixpkgs is imported again with Linux as the target for the rest.

@Mic92
Copy link
Owner

Mic92 commented Aug 19, 2020

Interestingly enough there is a macOS target for the qemu binary: https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/qemu-flags.nix#L28
Not sure where is this used so.

@anka-213
Copy link

I don't think it needs refactoring for that reason. I almost got it running with this config:

{ pkgs, ... }: {
  nixos-shell.mounts.mountHome = false;
  system.build.qemu = (import <nixpkgs> {}).pkgs.qemu_test;
}

However, it seems like virtfs isn't supported on macos, so it still failed:

$ nixos-shell -- --arg system '"x86_64-linux"'
/nix/store/4292rkypmhb9fzmc4yj4dnjy27j5iy3h-nixos-vm
qemu-system-x86_64: -virtfs local,path=/nix/store,security_model=none,mount_tag=store: There is no option group 'virtfs'
qemu-system-x86_64: -virtfs local,path=/nix/store,security_model=none,mount_tag=store: virtfs support is disabled

I don't know if there are other options for mounting the nix store, but this is how far I've gotten now.

@Mic92
Copy link
Owner

Mic92 commented Sep 28, 2020

qemu has builtin support for smb, which might work. Otherwise NFS could be used. The latter lone might require a bit more setup code.

@r2r-dev
Copy link

r2r-dev commented May 14, 2021

I've managed to get nixos-shell working on macOS by tying together PRs waiting to be merged to nixpkgs as well as some of my own changes:

@Mic92
Copy link
Owner

Mic92 commented May 14, 2021

Might be also interesting for you: @kloenk

@kloenk
Copy link

kloenk commented May 14, 2021

@r2r-dev what about aarch64? I have a m1 Mac, so would be interested in that.

@r2r-dev
Copy link

r2r-dev commented May 16, 2021

Haven't tried that yet. afaik x86_64-darwin qemu should work just fine via rosetta, however, it might not be the best way to go. To make it somehow more usable:

  1. I'll need to compile an aarch64-darwin version of qemu v6.0.0 target, so we could skip rosetta and use TCG for emulating aarch64 and x86_64 guests. [0]
  2. Enable HVF support on aarch64-darwin qemu by applying [1] on top of the v6.0.0 tree.

With the above changes in place, it should be possible to run virtualized aarch64-linux guests, as well as emulated x86_64 guests.

Finally, there's some additional patching required to make a network adapter somewhat more performant [2].

Also, it looks like @benpye has some experience in this field [3].

I'll test nixos-shell on m1 Mac with this overlay applied on top of my nixpkgs fork. Stay tuned.

[0]: https://patchwork.kernel.org/project/qemu-devel/patch/[email protected]/
[1]: https://patchwork.kernel.org/project/qemu-devel/list/?series=400619&state=%2A&archive=both
[2]: https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg04637.html
[3]: https://github.com/benpye/nix-config/blob/main/overlays/qemu/default.nix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants