Nixpkgs aarch64-darwin build (M1) uses wrong/old clang, how to fix?

I’m trying to add a specific yabai_4_x to nixpkgs (I couldn’t get 3.x to work on a Monterey M1).

Building a fresh yabai clone manually (in a native mac env) works well, but via nix-build (with an expression based on existing yabai/default.nix) doesn’t.

The steps I took:

  1. try to build the existing yabai from nixpkgs with modified version/ref => xcrun not found
  2. change build input xxd to xcbuild =>
    > clang-11: error: invalid arch name '-arch arm64e'
    
    I assume that this is because arm64e is M1 and only supported on newer clang?
  3. In my normal environment I appear to have clang-13, so this probably means stdenv chooses the wrong clang for this case?

How to override this?

1 Like

You may need something like this https://github.com/NixOS/nixpkgs/blob/6de161729c81dc98e844793cc9c8fda29d5ef62a/pkgs/build-support/libredirect/default.nix#L35-L49

Currently I use this overlay as a workaround:

self: super: {
  yabai = let
    replace = {
      "aarch64-darwin" = "--replace '-arch x86_64' ''";
      "x86_64-darwin" = "--replace '-arch arm64e' '' --replace '-arch arm64' ''";
    }.${super.pkgs.stdenv.system};
  in super.yabai.overrideAttrs(
    o: rec {
      version = "4.0.0";
      src = super.fetchFromGitHub {
        owner = "koekeishiya";
        repo = "yabai";
        rev = "v${version}";
        sha256 = "sha256-rllgvj9JxyYar/DTtMn5QNeBTdGkfwqDr7WT3MvHBGI=";
      };
      postPatch = ''
        substituteInPlace makefile ${replace};
      '';
      buildPhase = ''
        PATH=/usr/bin:/bin /usr/bin/make install
      '';
    }
  );
}

Need install CommandLineTools first (xcode-select --install).

Can’t you get make out of gnumake and skip the reliance on CommandLineTools? For me make is /nix/store/zw06h3iqvaxkbbw573n3qwmib82sk1xm-gnumake-4.3/bin/make.

Thanks, I guess that could work, but wouldn’t that keep using clang-11 and just change the Makefile to be compatible with it? I’d guess a better (and more sustainable/“correct”) solution would be to have nix’s build env actually use the clang-13 available on the system? Is there no way to achieve that?

EDIT: spoke too soon, I just saw @azuwis posted overlay workaround is actually not really related to the reference to libredirect also posted, which, glancing at the source, is intended to achieve the above. I have yet to understand how to use that though…

EDIT2: ah, I saw that by setting the PATH in the build step actually the system’s default clang (which on Monterey-M1 is clang-13) is used and the replace’s in the makefile do the rest, so it works as intended!

No sure how to implement the solution mentioned by @azuwis
Here my open issue description:
https://github.com/NixOS/nixpkgs/issues/171090

is this related?
If so, can you help and explain how to solve it within the general case of a shell.nix as posted?