Brew not on PATH on M1 Mac

I’m using nix-darwin/home-manager with flake on 3 Macs (2 Intel, 1 M1 MacBook Pro).

in flake.nix I have

Kodachi = darwinSystem {
        system = "aarch64-darwin";        
        modules = attrValues self.darwinModules ++ [ 
          # Main `nix-darwin` config
          ./configuration.nix
          # `home-manager` module
          home-manager.darwinModules.home-manager
          {
            nixpkgs = nixpkgsConfig;
            # `home-manager` config
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.phil = import ./home.nix;            
          }
        ];
      };

It’s been working great and I have a relatively simple brew configuration

homebrew = {
    enable = true;
    onActivation.autoUpdate = false; 
  };

  # If an app isn't available in the Mac App Store, or the version in the App Store has
  # limitiations, e.g., Transmit, install the Homebrew Cask.
  homebrew.casks = [
    "cleanmymac"
    "pulsar"
    "rectangle"
    "visual-studio-code"
    "vlc"
  ];

  homebrew.brews = [    
    "mas"
  ];

  homebrew.masApps = {
    "Microsoft Remote Desktop" = 1295203466;
    "Slack for Desktop" = 803453959;
    Xcode = 497799835;
  };

At some point, I found that brew is no longer on the $PATH although I do see it installed at /opt/homebrew.

Any ideas why brew is not being put on the $PATH? And more generally, how can I troubleshoot these kinds of issues?

1 Like

Enabling Homebrew in nix-darwin does not add the brew initialization biz to your environment. I solved this problem like so:

  home-manager.users.dazmin.programs.zsh = {
    initExtra = ''
      eval "$(/opt/homebrew/bin/brew shellenv)"
    '';
  };

And that line’ll get popped into your .zshrc, which is just what you would have done manually after installing Homebrew in a classic setup.

Hmm…but it’s working on my Intel Macs without that. And it seems nix-darwin should be doing it based on

brewPrefix = mkOption {
      type = types.str;
      default = if pkgs.stdenv.hostPlatform.isAarch64 then "/opt/homebrew/bin" else "/usr/local/bin";
      defaultText = literalExpression ''
        if pkgs.stdenv.hostPlatform.isAarch64 then "/opt/homebrew/bin"
        else "/usr/local/bin"
      '';
      description = ''
        The path prefix where the <command>brew</command> executable is located. This will be set to
        the correct value based on your system's platform, and should only need to be changed if you
        manually installed Homebrew in a non-standard location.
      '';
    };

I’m 99% sure this was working at some point for both Intel and M1.

Just to close the loop on this I ended up adding

#make sure brew is on the path for M1 
if [[ $(uname -m) == 'arm64' ]]; then
     eval "$(/opt/homebrew/bin/brew shellenv)"
 fi

to initExtra to get it working on M1. Still not sure why I don’t need to do that on Intel (or rather why it’s needed on M1)

1 Like

I met this issue too.
homebrew on mac apple sillicon change installation path from /usr/local/bin to /opt