Emacs Overlay + Yabai on Darwin

I’m trying to install emacs via the community overaly, but yabai is not able to tile / manage emacs.

Based on this thread it seems like the issue is caused by the accessibility role that emacs windows use on macOS. Homebrew seems to have solved this: emacs-plus uses a patch, and if I install emacs-plus@30 (follows the emacs master branch) via homebrew, there is no issue.

I tried applying the same patch in my nix derivation, but the problem remains. Emacs shows up in the Accessibility Inspector's list of programs, but it has no information (see screenshot), and if I use the cross-hair, I cannot select the emacs OS window.

Is there anything else the homebrew would be doing differently from nix that might cause this?
Alternatively, has anyone gotten emacs + yabai to work on darwin via the community overlay (I want to use emacsWithPackagesFromUsePackage)?


My derivation with patches applied
  { my-emacs = pkgs.emacsWithPackagesFromUsePackage {
      config = ../programs/emacs/emacs.el;
      defaultInitFile = true;
      package =
        if pkgs.stdenv.isDarwin
          pkgs.emacsGit.overrideAttrs (old: {
            patches =
              (old.patches or [])
              ++ [
                # Fix OS window role so that yabai can pick up emacs
                (fetchpatch {
                  url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/fix-window-role.patch";
                  sha256 = "0c41rgpi19vr9ai740g09lka3nkjk48ppqyqdnncjrkfgvm2710z";
                # Use poll instead of select to get file descriptors
                (fetchpatch {
                  url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-29/poll.patch";
                  sha256 = "0j26n6yma4n5wh4klikza6bjnzrmz6zihgcsdx36pn3vbfnaqbh5";
                # Enable rounded window with no decoration
                (fetchpatch {
                  url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-29/round-undecorated-frame.patch";
                  sha256 = "111i0r3ahs0f52z15aaa3chlq7ardqnzpwp8r57kfsmnmg6c2nhf";
                # Make emacs aware of OS-level light/dark mode
                (fetchpatch {
                  url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/system-appearance.patch";
                  sha256 = "14ndp2fqqc95s70fwhpxq58y8qqj4gzvvffp77snm2xk76c1bvnn";
            configureFlags =
              (old.configureFlags or [])
              ++ [
        else pkgs.emacsPgtk;
      alwaysEnsure = true;
      extraEmacsPackages = epkgs: [

An update: the first time I open an emacs window after home-manager switch yabai correctly detects and tiles emacs. But subsequent windows don’t tile (including if I close the first window).

I managed to figure out the problem!

I was launching emacs using emacs or emacsclient from a shell, but doing so does not work correctly with Yabai. However, nixpkgs also builds a macOS app for Emacs (which I didn’t realize before). If I launch via the app, Yabai tiles it correctly (note that I’m still using the patch mentioned above though, so that might be required as well).

I’m solving the problem by aliasing emacs to the macOS app via the following snippet in my home-manager config:

programs.zsh = {
 enable = true;
 shellAliases = {
   emacs = "${your-emacs-package}/Applications/Emacs.app/Contents/MacOS/Emacs";