Repository navigation
fix(zsh): keep Nix profiles ahead of /usr/bin and Homebrew in PATH - #309
Merged
Merged
Conversation
.zshrc prepended /usr/bin, /opt/homebrew/bin, /Library/TeX/texbin and ~/.local/bin, so they outranked the Nix profiles and git resolved to the Xcode shim. Append them after the Nix entries and de-duplicate PATH. Closes #308 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Move Nix profiles and user bin directories ahead of /usr/bin even when the inherited PATH is already wrong, and keep Homebrew and TeX after it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
.zshenv runs inside devShell and direnv shells, so rebuilding PATH there would push their tools behind the global profiles. Only append missing user directories and keep inherited order. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Insert missing user and Homebrew directories just before the first system PATH entry so they stay behind Nix and devShell entries but ahead of the macOS tools. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
シェルの PATH で
/usr/binや/opt/homebrew/binが nix のプロファイルより前に来ていた原因を特定し,直した.原因と証拠
env -i HOME=… zsh -lic 'print -l $path'では,先頭が~/.local/bin,/Library/TeX/texbin,/opt/homebrew/bin,/usr/binで,その後ろに~/.nix-profile/bin,/etc/profiles/per-user/kaito/bin,/run/current-system/sw/binが並んでいた.zsh -lc(非対話)では nix のプロファイルが先頭側に来る.つまり nix-darwin の/etc/zshenv(set-environment)は正しい順序を作っており,その上からzsh/.zshrcが壊していた.zsh/.zshrcのexport PATH="/usr/bin:$PATH",export PATH="/opt/homebrew/bin:$PATH",export PATH="/Library/TeX/texbin:$PATH",export PATH="$HOME/.local/bin:$PATH".zsh/.zshenv(gem,cargo)とzsh/.zprofile(~/.local/bin)も先頭に足しており,同じ問題があった.shellenv,macOS のpath_helper,/etc/paths,/etc/paths.dは関係しない(nix-darwin が生成する/etc/zprofileは空で,path_helperを呼ばない).変更
.zshrc,.zprofile,.zshenvから削除..zshenvは PATH の順序を強制しない.devShell や direnv 内の zsh でも,継承した順序(devShell のツールが先頭)を保つ.typeset -U path PATHで重複を除く./usr/local/bin,/usr/bin,/bin,/usr/sbin,/sbinのうち最初のもの)の直前に挿入する.順序は~/.local/bin,~/.cargo/bin,~/.gem/bin(.zshenv),/opt/homebrew/bin,/Library/TeX/texbin(.zshrc).すでにあるエントリは動かさない.nix と devShell が先頭,これらが macOS 標準より前になる.switch後にターミナルや Claude を再起動すれば直る.tests/zsh/startup.bats:クリーンなログインシェルの順序(nix → 上記ディレクトリ →/usr/bin),devShell が先頭の PATH がそのまま保たれること(-c,-ic,-lic),挿入位置(システムエントリの直前,なければ末尾)を完全一致で検証.前後の比較
~/.local/bin,texbin,/opt/homebrew/bin,/usr/bin,…,nix プロファイル,…,/usr/bin~/.local/bin,~/.cargo/bin,~/.gem/bin,/opt/homebrew/bin,texbin,/usr/bin,…/usr/bin,~/.local/binなど)command -v git/usr/bin/git受け入れ条件
switchのあと,ターミナルと Claude を再起動し,新しいターミナルでprint -l $pathを実行して,nix のプロファイルが/usr/binと/opt/homebrew/binより前にあり,重複がないecho $PATH)command -v gitが nix の git を返すCloses #308
🤖 Generated with Claude Code