-
-
Notifications
You must be signed in to change notification settings - Fork 158
Add Darwin support via vfkit hypervisor #430
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
Open
luizribeiro
wants to merge
7
commits into
microvm-nix:main
Choose a base branch
from
luizribeiro:vfkit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6e7d7cb
Add Darwin support via vfkit hypervisor
luizribeiro 16acd1f
docs: Update documentation for vfkit hypervisor support
luizribeiro 67b66af
feat: Add graphics support for vfkit hypervisor
luizribeiro 7e84afe
feat: Add Rosetta support for vfkit on Apple Silicon
luizribeiro 95a1204
refactor: Simplify flake.nix example generation logic
luizribeiro 1f4177c
fix: Only create darwin examples for hypervisors that work on macOS
luizribeiro 571fd39
refactor: address code review feedback
luizribeiro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ rec { | |
| "kvmtool" | ||
| "stratovirt" | ||
| "alioth" | ||
| "vfkit" | ||
| ]; | ||
|
|
||
| hypervisorsWithNetwork = hypervisors; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| { pkgs | ||
| , microvmConfig | ||
| , macvtapFds | ||
| , withDriveLetters | ||
| , ... | ||
| }: | ||
|
|
||
| let | ||
| inherit (pkgs) lib; | ||
| inherit (vmHostPackages.stdenv.hostPlatform) system; | ||
| inherit (microvmConfig) vmHostPackages; | ||
|
|
||
| vfkit = vmHostPackages.vfkit; | ||
|
|
||
| inherit (microvmConfig) | ||
| hostName vcpu mem user interfaces volumes shares socket | ||
| storeOnDisk kernel initrdPath storeDisk kernelParams | ||
| balloon devices credentialFiles vsock; | ||
|
|
||
| inherit (microvmConfig.vfkit) extraArgs logLevel; | ||
|
|
||
| volumesWithLetters = withDriveLetters microvmConfig; | ||
|
|
||
| # vfkit requires uncompressed kernel | ||
| kernelPath = "${kernel.out}/${pkgs.stdenv.hostPlatform.linux-kernel.target}"; | ||
|
|
||
| kernelCmdLine = "console=hvc0 reboot=t panic=-1 ${toString kernelParams}"; | ||
|
|
||
| bootloaderArgs = [ | ||
| "--bootloader" | ||
| "linux,kernel=${kernelPath},initrd=${initrdPath},cmdline=\"${kernelCmdLine}\"" | ||
| ]; | ||
|
|
||
| deviceArgs = | ||
| [ "--device" "virtio-rng" ] | ||
| ++ | ||
| [ "--device" "virtio-serial,stdio" ] | ||
luizribeiro marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ++ | ||
| (builtins.concatMap ({ image, ... }: [ | ||
| "--device" "virtio-blk,path=${image}" | ||
| ]) volumesWithLetters) | ||
| ++ | ||
| (builtins.concatMap ({ proto, source, tag, ... }: | ||
| if proto == "virtiofs" then [ | ||
| "--device" "virtio-fs,sharedDir=${source},mountTag=${tag}" | ||
| ] | ||
| else if proto == "9p" then | ||
| throw "vfkit does not support 9p shares on macOS. Use proto = \"virtiofs\" instead." | ||
| else | ||
| throw "Unknown share protocol: ${proto}" | ||
luizribeiro marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) shares) | ||
| ++ | ||
| (builtins.concatMap ({ type, id, mac, ... }: | ||
| if type == "user" then [ | ||
| "--device" "virtio-net,nat,mac=${mac}" | ||
| ] | ||
| else if type == "tap" then | ||
| throw "vfkit does not support tap networking on macOS. Use type = \"user\" for NAT networking." | ||
| else if type == "bridge" then | ||
| throw "vfkit bridge networking requires vmnet-helper which is not yet implemented. Use type = \"user\" for NAT networking." | ||
| else if type == "macvtap" then | ||
| throw "vfkit does not support macvtap networking on macOS. Use type = \"user\" for NAT networking." | ||
| else | ||
| throw "Unknown network interface type: ${type}" | ||
luizribeiro marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) interfaces); | ||
|
|
||
| allArgsWithoutSocket = [ | ||
| "${vfkit}/bin/vfkit" | ||
luizribeiro marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "--cpus" (toString vcpu) | ||
| "--memory" (toString mem) | ||
| ] | ||
| ++ lib.optionals (logLevel != null) [ | ||
| "--log-level" logLevel | ||
| ] | ||
| ++ bootloaderArgs | ||
| ++ deviceArgs | ||
| ++ extraArgs; | ||
|
|
||
| in | ||
| { | ||
| tapMultiQueue = false; | ||
|
|
||
| preStart = lib.optionalString (socket != null) '' | ||
| rm -f ${socket} | ||
| ''; | ||
|
|
||
| command = | ||
| if !vmHostPackages.stdenv.hostPlatform.isDarwin | ||
| then throw "vfkit only works on macOS (Darwin). Current host: ${system}" | ||
| else if vmHostPackages.stdenv.hostPlatform.isAarch64 != pkgs.stdenv.hostPlatform.isAarch64 | ||
| then throw "vfkit requires matching host and guest architectures. Host: ${system}, Guest: ${pkgs.stdenv.hostPlatform.system}" | ||
| else if user != null | ||
| then throw "vfkit does not support changing user" | ||
| else if balloon | ||
| then throw "vfkit does not support memory ballooning" | ||
| else if devices != [] | ||
| then throw "vfkit does not support device passthrough" | ||
| else if credentialFiles != {} | ||
| then throw "vfkit does not support credentialFiles" | ||
| else if vsock.cid != null | ||
| then throw "vfkit vsock support not yet implemented in microvm.nix" | ||
| else if storeOnDisk | ||
| then throw "vfkit does not support storeOnDisk. Use virtiofs shares instead (already configured in examples)." | ||
| else | ||
| let | ||
| baseCmd = lib.escapeShellArgs allArgsWithoutSocket; | ||
| vfkitCmd = lib.concatStringsSep " " (map lib.escapeShellArg allArgsWithoutSocket); | ||
| in | ||
| # vfkit requires absolute socket paths, so expand relative paths | ||
| if socket != null | ||
| then "bash -c ${lib.escapeShellArg '' | ||
| SOCKET_ABS=${lib.escapeShellArg socket} | ||
| [[ "$SOCKET_ABS" != /* ]] && SOCKET_ABS="$PWD/$SOCKET_ABS" | ||
| exec ${vfkitCmd} --restful-uri "unix:///$SOCKET_ABS" | ||
| ''}" | ||
| else baseCmd; | ||
|
|
||
| canShutdown = socket != null; | ||
|
|
||
| shutdownCommand = | ||
| if socket != null | ||
| then '' | ||
| SOCKET_ABS="${lib.escapeShellArg socket}" | ||
| [[ "$SOCKET_ABS" != /* ]] && SOCKET_ABS="$PWD/$SOCKET_ABS" | ||
| echo '{"state": "Stop"}' | ${vmHostPackages.socat}/bin/socat - "UNIX-CONNECT:$SOCKET_ABS" | ||
| '' | ||
| else throw "Cannot shutdown without socket"; | ||
|
|
||
| supportsNotifySocket = false; | ||
|
|
||
| requiresMacvtapAsFds = false; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.