Moving to nix-darwin breaks path order

So I’m new to nix and got started with home-manager. I got it working on 3 different Macs and it’s great.

I then wanted to move to use nix-darwin with home-manager (using flakes). I’ve got that going on one machine based on this gist.

When I run darwin-rebuild, I found that my path order is messed up. “/usr/local/bin” is at the front of the path and of the nix paths. This wasn’t the case when I had just home-manager.

I found this discussion, but I’m not sure if that’s still the recommended approach

Looking at .zshenv I see

. "/etc/profiles/per-user/phil/etc/profile.d/"

# Only source this once
if [[ -z "$__HM_ZSH_SESS_VARS_SOURCED" ]]; then


I’m not clear it’s messing up the path.

This open github issue is about the same thing.

His workaround was to comment out path_helper in /etc/zprofile but my /etc/zprofile doesn’t contain path_helper

# /etc/zprofile: DO NOT EDIT -- this file has been generated automatically.
# This file is read for login shells.

# Only execute this file once per shell.
if [ -n "$__ETC_ZPROFILE_SOURCED" ]; then return; fi

# Read system-wide modifications.
if test -f /etc/zprofile.local; then
  source /etc/zprofile.local

I think I narrowed it down to something I’m doing for brew. In my ~/.zprofile (that’s generated by nix-darwin/home-manager) I have

if [[ $(uname -m) == 'arm64' ]]; then
        eval "$(/opt/homebrew/bin/brew shellenv)"
        eval "$(/usr/local/bin/brew shellenv)"

I think brew needs that and it didn’t seem to be an issue when I just had home-manager. Any ideas how to work around that?

I realize that I can configure brew with nix-darwin by

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

(and removing the if/else block for brew from ~/.zprofile)

and that resolves the issue.