numtide / devshell

Per project developer environments
https://numtide.github.io/devshell/
MIT License
1.24k stars 88 forks source link

Dev shell leaves `/path-not-set` in my `PATH` #158

Open lilyball opened 2 years ago

lilyball commented 2 years ago

Describe the bug

After loading the dev shell, my PATH looks like /nix/store/8fl62lppihdwcxkwjlbs6w6yfw40ghff-devshell-dir/bin:/nix/store/qyasdwgp15xm056kzzblrzc01w62kwqf-bash-interactive-5.1-p12/bin:/path-not-set:[inherited path…]. Note the /path-not-set component.

Digging into this, Nix sets PATH=/path-not-set. The devshell env.bash script tries to remove this, but it does so like

PATH=${PATH%:/path-not-set}

The problem is, this script isn't loaded until shellHook, which itself isn't evaluated until after

PATH="$PATH:$nix_saved_PATH"

And so by the time the shellHook is evaluated, my PATH looks like /path-not-set:[inherited path…]. This doesn't end with :/path-not-set and so that line does nothing.

What would work is PATH=${PATH#/path-not-set:}. However, this line is immediately prior to PATH=${PATH#/nix/store/qyasdwgp15xm056kzzblrzc01w62kwqf-bash-interactive-5.1-p12/bin:}, which is attempting to trim the bash shell off of the front of the path prior to prepending both it and the devshell bin dir back on. I don't know why it's doing this as my path does not have the bash shell in it, but if this is a legitimate concern then perhaps something like

PATH=${PATH#/nix/store/qyasdwgp15xm056kzzblrzc01w62kwqf-bash-interactive-5.1-p12/bin:}
PATH=${PATH#/path-not-set:}

This way it says "trim the bash shell if present, then trim /path-not-set if present", this way it will trim either or both.

To Reproduce

Steps to reproduce the behavior:

  1. nix flake new -t github:numtide/devshell foo
  2. cd foo && nix develop
  3. echo $PATH
❯ echo $PATH | tr : \\n
/nix/store/mw2rxkp01vv8hfwmpq6d00x0lri1k9jl-devshell-dir/bin
/nix/store/qyasdwgp15xm056kzzblrzc01w62kwqf-bash-interactive-5.1-p12/bin
/path-not-set
/Users/lily/.nix-profile/bin
/usr/local/bin
/etc/profiles/per-user/lily/bin
/run/current-system/sw/bin
/nix/var/nix/profiles/default/bin
/usr/bin
/bin
/usr/sbin
/sbin

Expected behavior

The same PATH but without the /path-not-set component.

System information

Nix 2.5.1 macOS 12.1 (21C52)

zimbatm commented 2 years ago

Still valid. I tried removing it a few times but it tends to crop up again.