Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zsh.dotDir breaks homebrew, removing nix-darwin's homebrew from the PATH #6483

Open
2 tasks done
brandoncc opened this issue Feb 17, 2025 · 7 comments
Open
2 tasks done
Assignees
Labels
bug triage Issues or feature request that have not been triaged yet

Comments

@brandoncc
Copy link

brandoncc commented Feb 17, 2025

Are you following the right branch?

  • My Nixpkgs and Home Manager versions are in sync

Is there an existing issue for this?

  • I have searched the existing issues

Issue description

Homebrew is added to the PATH here. If I set programs.zsh.dotDir = ".config/zsh", homebrew is no longer in the PATH.

I've tested this with both unstable and release 24.11 for nixpkgs, nix-darwin, and home-manager.

Maintainer CC

@sudoforge

System information

$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"aarch64-darwin"`
 - host os: `Darwin 24.3.0, macOS 15.3`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.25.2`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/store/k8nkf470zpidpa5nh76lh2x6rxfzpwa4-source`
@brandoncc brandoncc added bug triage Issues or feature request that have not been triaged yet labels Feb 17, 2025
@brandoncc
Copy link
Author

CC @sudoforge because I didn't fill out the CC section before creating the issue. I don't think it pings after an edit, where I added the CC info.

@sudoforge
Copy link
Contributor

I don't think it pings after an edit, where I added the CC info.

it does - or at least, i received an email notification of the comment.


can you provide a working reproduction of your issue? at first glance, i'm not following the logic behind the issue report here. programs.zsh.dotDir is an attribute within home-manager, and doesn't appear to be used within the homebrew module from nix-darwin.

@brandoncc
Copy link
Author

can you provide a working reproduction of your issue?

Is there a simple way of doing this? I'm a bit afraid of repercussions such as deleted app preferences on my machine if I switch to a super simple config. Is there a good way to setup a virtual machine or some other way to test it? I don't think creating a new user on my machine would be sufficient since nix-darwin is machine-wide?

at first glance, i'm not following the logic behind the issue report here. programs.zsh.dotDir is an attribute within home-manager, and doesn't appear to be used within the homebrew module from nix-darwin.

This is exactly the same place I'm at. I don't understand why this is happening, as there isn't a clear line between the two.

@brandoncc
Copy link
Author

I'd like to resolve this issue, but in the meantime I've fixed it with this in my zsh config:

initExtra = ''
  # Ensure homebrew paths are in PATH. We have to do this manually because
  # using programs.zsh.dotDir causes these paths to be removed for some
  # reason.
  #
  # ref: https://github.com/nix-community/home-manager/issues/6483
  homebrewBinPath="/opt/homebrew/bin"
  brewBinaryPath="$homebrewBinPath/brew"
  masBinPath="/opt/homebrew/sbin"

  if [ -f "$brewBinaryPath" ]; then
    if [ -d "$masBinPath" ]; then
      if [[ ":$PATH:" != *":$masBinPath:"* ]]; then
        export PATH="$masBinPath:$PATH"
      fi
    fi

    if [[ ":$PATH:" != *":$homebrewBinPath:"* ]]; then
      export PATH="$homebrewBinPath:$PATH"
    fi
  fi
'';

@sudoforge
Copy link
Contributor

sudoforge commented Feb 17, 2025

yes, using an ephemeral VM to test out your configuration(s) is a very safe way to go about testing configuration changes or reproducing bugs (as are in-place changes, because, after all, nix is all about reproducibility), but let's not send you down that rabbit hole for this issue.

posting snippets of your configuration would work, or if you'd rather not, more detail as to how your configuration is laid out would be useful.


when programs.zsh.dotDir is not null, we use the value in two ways:

  1. setting ZDOTDIR, which is a variable that zsh consumes. this is done within the ${cfg.dotDir}/.zshenv file.
  2. sourcing the ${cfg.dotDir} file within the default ~/.zshenv file, such that the chain is appropriately set up for zsh.

visually, that means that:

{
  programs.zsh.dotDir = ".config/zsh";
}

would result in the following files and content:

➜ cat ~/.zshenv
source $HOME/.config/zsh/.zshenv

➜ rg --no-line-number 'ZDOTDIR' ~/.config/zsh/.zshenv
export ZDOTDIR=$HOME/.config/zsh

i don't use macos (nor nix-darwin), but what i suspect is that the homebrew module isn't adding to PATH in the way you'd expect, or otherwise, you have an issue in your config. without seeing the entire configuration chain you have for zsh + homebrew, it'd be difficult to debug further.


that being said, i feel fairly confident stating that this is not an issue within home-manager, nor its zsh module.

@sudoforge
Copy link
Contributor

also, entirely unrelated and strictly out of curiosity - what led you to ping me as the maintainer for this?

@brandoncc
Copy link
Author

Thanks for that information. I was thinking about using a VM, but I don't have a simple way to create a MacOS VM. I forgot I could use home manager without nix-darwin and therefore could use a linux VM. I can do that if necessary, but the conflict seems to happen between nix-darwin's homebrew package and home-manager's zsh package.

The relevant part of my config is here. If I remove all of the highlighted code, everything works. If I remove only the part in initExtra, homebrew (and, therefore, its apps) is no longer available via PATH.

I completely understand why you say it isn't the zsh module, but I'm struggling to think of another cause when it is the dotDir config that triggers the issue 🤔

I considered managing homebrew completely from home-manager, but it looked to me like home-manager's homebrew config was just a nix-darwin wrapper. Based on that, I decided it wouldn't help. Perhaps I should give that another look?


also, entirely unrelated and strictly out of curiosity - what led you to ping me as the maintainer for this?

The issue template says:

Image

I just realized I was looking at the 24.11 release when I checked who was the most recent committer. There have been a few since you, so I shouldn't have pinged you. Sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Issues or feature request that have not been triaged yet
Projects
None yet
Development

No branches or pull requests

5 participants