Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nix
base: 8af4f886e212
Choose a base ref
...
head repository: NixOS/nix
compare: 3edcb198e5db
Choose a head ref
  • 4 commits
  • 3 files changed
  • 2 contributors

Commits on Dec 3, 2020

  1. Add extraPlatforms for Rosetta 2 macOS

    macOS systems with ARM64 can utilize a translation layer at
    /Library/Apple/usr/libexec/oah to run x86_64 binaries. This change
    makes Nix recognize that and it to "extra-platforms". Note that there
    are two cases here since Nix could be built for either x86_64 or
    aarch64. In either case, we can switch to the other architecture.
    Unfortunately there is not a good way to prevent aarch64 binaries from
    being run in x86_64 contexts or vice versa - programs can always
    execute programs for the other architecture.
    matthewbauer committed Dec 3, 2020
    Copy the full SHA
    9b1824e View commit details
    Browse the repository at this point in the history
  2. Use posix_spawn_setbinpref_np to advise which architecture to run

    When running universal binaries like /bin/bash, Darwin XNU will choose
    which architecture of the binary to use based on "binary preferences".
    This change sets that to the current platform for aarch64 and x86_64
    builds. In addition it now uses posix_spawn instead of the usual
    execve. Note, that this does not prevent the other architecture from
    being run, just advises which to use.
    
    Unfortunately, posix_spawnattr_setbinpref_np does not appear to be
    inherited by child processes in x86_64 Rosetta 2 translations, meaning
    that this will not always work as expected.
    
    For example:
    
      {
        arm = derivation {
          name = "test";
          system = "aarch64-darwin";
          builder = "/bin/bash";
          args = [ "-e" (builtins.toFile "test" ''
            set -x
            /usr/sbin/sysctl sysctl.proc_translated
            /usr/sbin/sysctl sysctl.proc_native
            [ "$(/usr/bin/arch)" = arm64 ]
            /usr/bin/touch $out
          '') ];
        };
        rosetta = derivation {
          name = "test";
          system = "x86_64-darwin";
          builder = "/bin/bash";
          args = [ "-e" (builtins.toFile "test" ''
            set -x
            /usr/sbin/sysctl sysctl.proc_translated
            /usr/sbin/sysctl sysctl.proc_native
            [ "$(/usr/bin/arch)" = i386 ]
            echo It works!
            /usr/bin/touch $out
          '') ];
        };
      }
    
    `arm' fails on x86_64-compiled Nix, but `arm' and `rosetta' succeed on
    aarch64-compiled Nix. I suspect there is a way to fix this since:
    
      $ /usr/bin/arch -arch x86_64 /bin/bash \
        -c '/usr/bin/arch -arch arm64e /bin/bash -c /usr/bin/arch'
      arm64
    
    seems to work correctly. We may need to wait for Apple to update
    system_cmds in opensource.apple.com to find out how though.
    matthewbauer committed Dec 3, 2020
    Copy the full SHA
    4b9acf4 View commit details
    Browse the repository at this point in the history

Commits on Dec 4, 2020

  1. Copy the full SHA
    3c9b702 View commit details
    Browse the repository at this point in the history

Commits on Jan 6, 2021

  1. Merge pull request #4310 from matthewbauer/rosetta2-extra-platforms

    Add x86_64-darwin and aarch64 to "extra-platforms" automatically when Rosetta2 is detected
    edolstra committed Jan 6, 2021
    Copy the full SHA
    3edcb19 View commit details
    Browse the repository at this point in the history