1 { config, lib, pkgs, ... }:
4 cfg = config.virtualisation.rosetta;
9 virtualisation.rosetta.enable = lib.mkOption {
13 Whether to enable [Rosetta](https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment) support.
15 This feature requires the system to be a virtualised guest on an Apple silicon host.
17 The default settings are suitable for the [UTM](https://docs.getutm.app/) virtualisation [package](https://search.nixos.org/packages?channel=unstable&show=utm&from=0&size=1&sort=relevance&type=packages&query=utm).
18 Make sure to select 'Apple Virtualization' as the virtualisation engine and then tick the 'Enable Rosetta' option.
22 virtualisation.rosetta.mountPoint = lib.mkOption {
24 default = "/run/rosetta";
27 The mount point for the Rosetta runtime inside the guest system.
29 The proprietary runtime is exposed through a VirtioFS directory share and then mounted at this directory.
33 virtualisation.rosetta.mountTag = lib.mkOption {
37 The VirtioFS mount tag for the Rosetta runtime, exposed by the host's virtualisation software.
39 If supported, your virtualisation software should provide instructions on how register the Rosetta runtime inside Linux guests.
40 These instructions should mention the name of the mount tag used for the VirtioFS directory share that contains the Rosetta runtime.
45 config = lib.mkIf cfg.enable {
48 assertion = pkgs.stdenv.hostPlatform.isAarch64;
49 message = "Rosetta is only supported on aarch64 systems";
53 fileSystems."${cfg.mountPoint}" = {
54 device = cfg.mountTag;
60 extra-platforms = [ "x86_64-linux" ];
61 extra-sandbox-paths = [
66 boot.binfmt.registrations.rosetta = {
67 interpreter = "${cfg.mountPoint}/rosetta";
69 # The required flags for binfmt are documented by Apple:
70 # https://developer.apple.com/documentation/virtualization/running_intel_binaries_in_linux_vms_with_rosetta
71 magicOrExtension = ''\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00'';
72 mask = ''\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'';
74 matchCredentials = true;
75 preserveArgvZero = false;
77 # Remove the shell wrapper and call the runtime directly
78 wrapInterpreterInShell = false;