Conditional logic based on Intel Mac or M1 Mac

I’m getting home-manager set up on my Macs. On my M1, I enabled zsh and based on my pre-home-manager .zprofile I have

profileExtra = ''
      eval "$(/opt/homebrew/bin/brew shellenv)"

because my .zprofile had that before I moved to home-manager.

This issue is that I used the same config on my Intel Mac and it’s not working because brew is in a different location on Intel vs M1.

Blockquote Homebrew files in /usr/local (for macOS Intel) or /opt/homebrew (for Apple Silicon).

How can I set the appropriate path based on the type of Mac?

I realized I could do this by conditional logic in the shell script. So I ended up doing

      #configure brew based on M1 or Intel Mac
      if [[ $(uname -m) == 'arm64' ]]; then
        eval "$(/opt/homebrew/bin/brew shellenv)"
        eval "$(/usr/local/bin/brew shellenv)"
1 Like

Here’s how nix-darwin does it: