|
| 1 | +# Using Rosetta with vfkit on Apple Silicon |
| 2 | + |
| 3 | +Rosetta support enables running x86_64 (Intel) binaries in your ARM64 Linux VM on Apple Silicon Macs. This is useful for running legacy applications or development tools that haven't been ported to ARM yet. |
| 4 | + |
| 5 | +## Requirements |
| 6 | + |
| 7 | +- Apple Silicon (M1/M2/M3/etc.) Mac |
| 8 | +- macOS with Rosetta installed |
| 9 | +- vfkit hypervisor |
| 10 | + |
| 11 | +## Configuration |
| 12 | + |
| 13 | +Enable Rosetta in your MicroVM configuration: |
| 14 | + |
| 15 | +```nix |
| 16 | +{ |
| 17 | + microvm = { |
| 18 | + hypervisor = "vfkit"; |
| 19 | +
|
| 20 | + vfkit.rosetta = { |
| 21 | + enable = true; |
| 22 | + # Optional: install Rosetta automatically if missing |
| 23 | + install = true; |
| 24 | + }; |
| 25 | + }; |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +The NixOS module automatically handles mounting the Rosetta virtiofs share and configuring binfmt to use Rosetta for x86_64 binaries. No additional guest configuration is required. |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +Once configured, you can run any x86_64 binary in your ARM64 VM. To verify Rosetta is working: |
| 34 | + |
| 35 | +```nix |
| 36 | +# Add an x86_64 package to your configuration |
| 37 | +environment.systemPackages = with pkgs; [ |
| 38 | + file # to verify binary architecture |
| 39 | + (pkgsCross.gnu64.hello) # x86_64 version of hello |
| 40 | +]; |
| 41 | +``` |
| 42 | + |
| 43 | +Then in the VM: |
| 44 | + |
| 45 | +```bash |
| 46 | +# Verify you're running on ARM64 |
| 47 | +uname -m |
| 48 | +# Output: aarch64 |
| 49 | + |
| 50 | +# Check the binary architecture |
| 51 | +file $(which hello) |
| 52 | +# Output: ELF 64-bit LSB executable, x86-64, ... |
| 53 | + |
| 54 | +# Run the x86_64 binary via Rosetta |
| 55 | +hello |
| 56 | +# Output: Hello, world! |
| 57 | +``` |
| 58 | + |
| 59 | +You can use `pkgsCross.gnu64.<package>` to cross-compile any package from nixpkgs to x86_64 and run it via Rosetta. |
| 60 | + |
| 61 | +## Options Reference |
| 62 | + |
| 63 | +| Option | Type | Default | Description | |
| 64 | +|--------|------|---------|-------------| |
| 65 | +| `microvm.vfkit.rosetta.enable` | bool | `false` | Enable Rosetta support | |
| 66 | +| `microvm.vfkit.rosetta.install` | bool | `false` | Auto-install Rosetta if missing | |
| 67 | +| `microvm.vfkit.rosetta.ignoreIfMissing` | bool | `false` | Continue if Rosetta unavailable | |
| 68 | + |
| 69 | +## Limitations |
| 70 | + |
| 71 | +- Only works on Apple Silicon Macs (M-series chips) |
| 72 | +- vfkit will fail to start on Intel Macs if Rosetta is enabled |
| 73 | +- Performance is slower than native ARM64 execution |
| 74 | +- Not all x86_64 binaries may work perfectly |
0 commit comments