`which curl` not pointing to nix curl

I am using MacOS.
How to reproduce it:

% which curl
/usr/bin/curl
% nix-env -iA nixpkgs.curl
installing 'curl-8.4.0'
these 49 paths will be fetched (8.71 MiB download, 41.54 MiB unpacked):
  /nix/store/086bmv559kmjazkbzvwljwiwzfl06y9h-apple-framework-CFNetwork-11.0.0
  /nix/store/rkzrc6q4q3j1fyfc6jbhm7saxmw7kxyr-apple-framework-CoreAudio-11.0.0
  /nix/store/9alfl7q50d9f762ckxc5hs560lw1j585-apple-framework-CoreAudioTypes-11.0.0
  /nix/store/9xkl6bxkhf2lkdjknz6fccsi8cwsp81v-apple-framework-CoreFoundation-11.0.0
  /nix/store/w07fz5srxjv5zlsggmkd048l8s31hiic-apple-framework-CoreFoundation-11.0.0
  /nix/store/k3rf1hha56nfyq4rppi19i9m0s4qsm5n-apple-framework-CoreServices-11.0.0
  /nix/store/2ya144slx4mvsfzf9acnkw4iz2wkb62b-apple-framework-DiskArbitration-11.0.0
  /nix/store/lmqc4af9bcv2cx6b7nkx7hg9ad2v8wm0-apple-framework-IOKit-11.0.0
  /nix/store/hmss7x7296fqhqvs67nvgxnpbz11r793-apple-framework-NetFS-11.0.0
  /nix/store/75qzjxqmm544dcm4svkrxg48wgpdd8s2-apple-framework-Security-11.0.0
  /nix/store/ccv5hhvis2b9rcxg30n47nb46s93b518-apple-framework-ServiceManagement-11.0.0
  /nix/store/vgykyhwl1bjcka33snmsnn91scsd6ycl-apple-framework-SystemConfiguration-11.0.0
  /nix/store/2kbqs8xmbqz500w5gq853gnsdkmmrww8-apple-lib-libDER
  /nix/store/x1xxsh1gp6y389hyl40a0i74dkxiprl7-bash-5.2-p15
  /nix/store/7qg4s6pykxn3zv204y625znzdhswwmkw-brotli-1.1.0
  /nix/store/w0i3y2dnxgv3krx8x9rfb1gbzyx38p75-brotli-1.1.0-dev
  /nix/store/7yrkw7smf4iqdcvm4n5fajpz9ywgaf6r-brotli-1.1.0-lib
  /nix/store/a1mpv9bpsnqxh9fcwj79mq6lp1zfiqrj-c-ares-1.19.1
  /nix/store/c39qm57grkavw8a4hkramahpnspm1inq-curl-8.4.0
  /nix/store/mdqkhwklv25l9fwaifd40f6v6kdi8vdw-curl-8.4.0-bin
  /nix/store/m9ps3fxpww0i7hc5a5vh5kf0wmbpl2d8-curl-8.4.0-dev
  /nix/store/p8ri84z26payik5gyhwsih19h91r3vmk-curl-8.4.0-devdoc
  /nix/store/r4wa3jqgb7ylwpq2sia650d9x99ds2nf-curl-8.4.0-man
  /nix/store/98v0v3bwzgkcwsz4anjip62d2k3gz352-gnugrep-3.11
  /nix/store/vf7k7l7ny35g1nmninaqjbryl2xqkag5-libcxx-16.0.6
  /nix/store/x622mzi1g7v7nh7zq5r8d0nxbhrg9px3-libcxxabi-16.0.6
  /nix/store/ag37l0dxp7c37dw5909ikhplnzyfpzdw-libev-4.33
  /nix/store/g5r20rs0qhcjcbf9dhbnbd9ksg0h0jmx-libiconv-50
  /nix/store/abhslp7j1nmsfj1g0cgcl2kd5d44ia7a-libidn2-2.3.4
  /nix/store/gd72x5g8dghbca83zk7jkjd7ay7f8kd8-libidn2-2.3.4-bin
  /nix/store/7bxs5xq96n3gza4pskn3kysfrym8v5q5-libidn2-2.3.4-dev
  /nix/store/63050g0fdi1z5sd1686vwf3hpzlmq5af-libkrb5-1.20.2
  /nix/store/czdakh04vbkks83kid01mnfc97q56ady-libkrb5-1.20.2-dev
  /nix/store/symqih999rvrn22pb2kw0v1i9s9anfsr-libobjc-11.0.0
  /nix/store/0xja39g5a6arz00vh1idcnpig8p1j14p-libssh2-1.11.0
  /nix/store/kzzp7fnxh9lgfzfsjb3dna8l19dgzfj5-libssh2-1.11.0-dev
  /nix/store/qxr8rg3dmwg053jin40a5vpg2zq2a5mq-libunistring-1.1
  /nix/store/r95b9x36y068grsgh7vpadb6cswywsgn-nghttp2-1.57.0
  /nix/store/dn9crhvc82hkq7zskx81j42vg7kxav29-nghttp2-1.57.0-dev
  /nix/store/wxmakrb87pwsp54hpi0qna74sixl34bk-nghttp2-1.57.0-lib
  /nix/store/16ccmy0kylpjgnplh0rkyx4az3gzy5rj-openssl-3.0.12
  /nix/store/7iqri393gkmczk5f68jaxng6a6rbvsv6-openssl-3.0.12-bin
  /nix/store/99b4nzln09rw99j9y3ij6dz0hskcr2j9-openssl-3.0.12-dev
  /nix/store/zipi977775yxhb2yfdkqdl6v9w0flz6y-pcre2-10.42
  /nix/store/a377d66g1rgsd4vkzxdhkza5g55fkmky-zlib-1.3
  /nix/store/68289cwrk5pjj6nmlb7r76qqpw99s011-zlib-1.3-dev
  /nix/store/9pa8q4d582j3hc09y9l3lpjkdv2nk5fs-zstd-1.5.5
  /nix/store/108jgmxp88snxp4hgsbmd16wp1vgsy1f-zstd-1.5.5-bin
  /nix/store/c9lkm30sfdd761gynfdhcxihld6cqfvm-zstd-1.5.5-dev
copying path '/nix/store/r4wa3jqgb7ylwpq2sia650d9x99ds2nf-curl-8.4.0-man' from 'https://cache.nixos.org'...
copying path '/nix/store/p8ri84z26payik5gyhwsih19h91r3vmk-curl-8.4.0-devdoc' from 'https://cache.nixos.org'...
copying path '/nix/store/x1xxsh1gp6y389hyl40a0i74dkxiprl7-bash-5.2-p15' from 'https://cache.nixos.org'...
copying path '/nix/store/7yrkw7smf4iqdcvm4n5fajpz9ywgaf6r-brotli-1.1.0-lib' from 'https://cache.nixos.org'...
copying path '/nix/store/wxmakrb87pwsp54hpi0qna74sixl34bk-nghttp2-1.57.0-lib' from 'https://cache.nixos.org'...
copying path '/nix/store/16ccmy0kylpjgnplh0rkyx4az3gzy5rj-openssl-3.0.12' from 'https://cache.nixos.org'...
copying path '/nix/store/a377d66g1rgsd4vkzxdhkza5g55fkmky-zlib-1.3' from 'https://cache.nixos.org'...
copying path '/nix/store/x622mzi1g7v7nh7zq5r8d0nxbhrg9px3-libcxxabi-16.0.6' from 'https://cache.nixos.org'...
copying path '/nix/store/g5r20rs0qhcjcbf9dhbnbd9ksg0h0jmx-libiconv-50' from 'https://cache.nixos.org'...
copying path '/nix/store/symqih999rvrn22pb2kw0v1i9s9anfsr-libobjc-11.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/2kbqs8xmbqz500w5gq853gnsdkmmrww8-apple-lib-libDER' from 'https://cache.nixos.org'...
copying path '/nix/store/a1mpv9bpsnqxh9fcwj79mq6lp1zfiqrj-c-ares-1.19.1' from 'https://cache.nixos.org'...
copying path '/nix/store/ag37l0dxp7c37dw5909ikhplnzyfpzdw-libev-4.33' from 'https://cache.nixos.org'...
copying path '/nix/store/zipi977775yxhb2yfdkqdl6v9w0flz6y-pcre2-10.42' from 'https://cache.nixos.org'...
copying path '/nix/store/68289cwrk5pjj6nmlb7r76qqpw99s011-zlib-1.3-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/9xkl6bxkhf2lkdjknz6fccsi8cwsp81v-apple-framework-CoreFoundation-11.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/w07fz5srxjv5zlsggmkd048l8s31hiic-apple-framework-CoreFoundation-11.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/vf7k7l7ny35g1nmninaqjbryl2xqkag5-libcxx-16.0.6' from 'https://cache.nixos.org'...
copying path '/nix/store/63050g0fdi1z5sd1686vwf3hpzlmq5af-libkrb5-1.20.2' from 'https://cache.nixos.org'...
copying path '/nix/store/7qg4s6pykxn3zv204y625znzdhswwmkw-brotli-1.1.0' from 'https://cache.nixos.org'...
copying path '/nix/store/98v0v3bwzgkcwsz4anjip62d2k3gz352-gnugrep-3.11' from 'https://cache.nixos.org'...
copying path '/nix/store/qxr8rg3dmwg053jin40a5vpg2zq2a5mq-libunistring-1.1' from 'https://cache.nixos.org'...
copying path '/nix/store/9pa8q4d582j3hc09y9l3lpjkdv2nk5fs-zstd-1.5.5' from 'https://cache.nixos.org'...
copying path '/nix/store/108jgmxp88snxp4hgsbmd16wp1vgsy1f-zstd-1.5.5-bin' from 'https://cache.nixos.org'...
copying path '/nix/store/w0i3y2dnxgv3krx8x9rfb1gbzyx38p75-brotli-1.1.0-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/abhslp7j1nmsfj1g0cgcl2kd5d44ia7a-libidn2-2.3.4' from 'https://cache.nixos.org'...
copying path '/nix/store/0xja39g5a6arz00vh1idcnpig8p1j14p-libssh2-1.11.0' from 'https://cache.nixos.org'...
copying path '/nix/store/7iqri393gkmczk5f68jaxng6a6rbvsv6-openssl-3.0.12-bin' from 'https://cache.nixos.org'...
copying path '/nix/store/r95b9x36y068grsgh7vpadb6cswywsgn-nghttp2-1.57.0' from 'https://cache.nixos.org'...
copying path '/nix/store/gd72x5g8dghbca83zk7jkjd7ay7f8kd8-libidn2-2.3.4-bin' from 'https://cache.nixos.org'...
copying path '/nix/store/99b4nzln09rw99j9y3ij6dz0hskcr2j9-openssl-3.0.12-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/9alfl7q50d9f762ckxc5hs560lw1j585-apple-framework-CoreAudioTypes-11.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/lmqc4af9bcv2cx6b7nkx7hg9ad2v8wm0-apple-framework-IOKit-11.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/hmss7x7296fqhqvs67nvgxnpbz11r793-apple-framework-NetFS-11.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/086bmv559kmjazkbzvwljwiwzfl06y9h-apple-framework-CFNetwork-11.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/kzzp7fnxh9lgfzfsjb3dna8l19dgzfj5-libssh2-1.11.0-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/c9lkm30sfdd761gynfdhcxihld6cqfvm-zstd-1.5.5-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/7bxs5xq96n3gza4pskn3kysfrym8v5q5-libidn2-2.3.4-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/2ya144slx4mvsfzf9acnkw4iz2wkb62b-apple-framework-DiskArbitration-11.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/75qzjxqmm544dcm4svkrxg48wgpdd8s2-apple-framework-Security-11.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/rkzrc6q4q3j1fyfc6jbhm7saxmw7kxyr-apple-framework-CoreAudio-11.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/c39qm57grkavw8a4hkramahpnspm1inq-curl-8.4.0' from 'https://cache.nixos.org'...
copying path '/nix/store/czdakh04vbkks83kid01mnfc97q56ady-libkrb5-1.20.2-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/ccv5hhvis2b9rcxg30n47nb46s93b518-apple-framework-ServiceManagement-11.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/vgykyhwl1bjcka33snmsnn91scsd6ycl-apple-framework-SystemConfiguration-11.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/mdqkhwklv25l9fwaifd40f6v6kdi8vdw-curl-8.4.0-bin' from 'https://cache.nixos.org'...
copying path '/nix/store/dn9crhvc82hkq7zskx81j42vg7kxav29-nghttp2-1.57.0-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/k3rf1hha56nfyq4rppi19i9m0s4qsm5n-apple-framework-CoreServices-11.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/m9ps3fxpww0i7hc5a5vh5kf0wmbpl2d8-curl-8.4.0-dev' from 'https://cache.nixos.org'...
building '/nix/store/k27z725jck02mm8s3bjynfbaxzv7v2nc-user-environment.drv'...
% which curl
# now I expected it to point to /Users/joao/.nix-profile/bin/curl
/usr/bin/curl

Is it not pointing to /Users/joao/.nix-profile/bin/curl because I already have curl installed? Is that the correct behavior?

When I installed hello package with nix-env -iA nixpkgs.hello which hello returns /Users/joao/.nix-profile/bin/hello. I am following: Deterministic systems with Nix

 % nix-env --version
nix-env (Nix) 2.18.1

You’ll need to look into how your PATH is configured.

You can run type -a curl to confirm that both are on your PATH.

You may have a shell profile that is prefixing, hard-setting, or otherwise altering the PATH to put /usr/bin ahead of the various Nix locations.

2 Likes

Thank you @abathur!

The return of type -a curl:

type -a curl
curl is /Users/joao/.nix-profile/bin/curl
curl is /usr/bin/curl

That looks like the right order, so I’m not sure how what you described earlier occurred.

Are you doing this in the same shell session? Does which still report what you said above?

What does type -a which report?

1 Like

Yes, I am using the same shell session. Yes, which still reporting what I have said above in the same shell session but in a new shell session it’s returning: /Users/joao/.nix-profile/bin/curl

type -a which reports this result in the new and in the same:

% type -a which        
which is a shell builtin
which is /usr/bin/which

if you are using zsh you have to rehash the things in path with: hash -r which I guess the builtin which relies upon.

2 Likes

hash -r solved the issue, after it same session returned nix curl. Thank you @abathur and @Janik

1 Like

to solve that (and also fix tab completion for affected programs) I have this in my .zshrc

zstyle ":completion:*:commands" rehash 1
1 Like