Open wch opened 10 months ago
I was trying to reproduce this on an older Mac install I had and was not able to. I suspect it's related to something that changed in 0.15, perhaps related to the new Mac Nix hooks. I'm going to spend some more time investigating. Thank you for this report!
I tested this again in 0.16.0 today and was able to confirm it. Noting you do need to nix profile install nixpkgs#hello
before entering the nix shell
to reproduce.
I was able to reproduce this on an aarch64 Sonoma 14.3 using the installer from https://nixos.org/download as well as ours, in your issue you stated you also tried with the upstream installer, however it was when the upstream installer was pointing to 2.18 (I believe). I wonder if this is a Nix 2.19 issue.
~ % nix profile install nixpkgs#hello
~ % nix shell github:wch/nix-hello-demo
~ % hello
Hello, world!
~ % echo $PATH
/Users/user/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/nix/store/050vas2swsvr7sqrf75mkxwi851ycxcz-hello/bin:/Users/user/.nix-profile/bin:/nix/var/nix/profiles/default/bin:...
~ % nix --version
nix (Nix) 2.19.3
~ % sw_vers
ProductName: macOS
ProductVersion: 14.3
BuildVersion: 23D56
I was also able to reproduce this on a fresh Ubuntu VM using the upstream installer:
On my Mac where I used the Determinate Systems installer, when I run
nix shell
, it puts~/.nix-profile/bin
as the first thing in thePATH
, but this means that if there is a copy of a program installed there, it will be used instead of the program I want to use withnix shell
.For example, suppose you already have
hello
installed on your system.I have a
hello
flake at https://github.com/wch/nix-hello-demo that prints something slightly different:However, when I use
nix shell
, and the runhello
, it runs the regular version instead of my customized one.Note that this happens on my Mac, but not on my NixOS computer (where I didn't use the Determinate Systems installer). The behavior on NixOS is what I would expect on the Mac.
On the Mac, in the
nix shell
thePATH
is set so that/Users/winston/.nix-profile/bin:/nix/var/nix/profiles/default/bin:
come first, before/nix/store/050vas2swsvr7sqrf75mkxwi851ycxcz-hello/bin
. On the NixOS machine, those two paths are not put first.I found that the PATH is being set by
/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
. Is it intentional that those directories are put first even whennix shell
is used?