You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
$PATH is incorrect when running fish in a nix-shell #18946
When starting a fish shell after dropping in a nix-shell, the PATH environment variable is improperly set. This makes fish unusable for my use case with nix-shell.
Steps to reproduce
Say I have the following default.nix file in directory :
In the same directory, if I do nix-shell, I drop into a bash shell where the bin path of whatever-dependency is added to the PATH environment variable (if applicable).
However, if I start a fish shell from this bash instance, the PATH variable reverts to its default value.
The problem is the same when doing directly nix-shell --run fish or nix-shell --command fish. This doesn't cause any issue with zsh.
In the fish instance, other environment variables are properly updated. The IN_NIX_SHELL variable is indeed set to 1 and if you add some shellPrompt code in the derivation, you do inherit the proper environment. The PATH variable seems to be the only one affected.
I suspect that somewhere in fish-foreign-env we recreate the PATH from scratch instead of using the value of the parent shell. I might be mistaken ; I just tried fish on NixOS today and don't know much.
I've noticed a very strange problem, potentially related, in NixOS 17.03. When I use fish as a login shell at a virtual console, I get a ton of errors and login hangs. I do not get this behavior when I open a terminal in the GUI. I also do not get this behavior if I disable my oh-my-fish profile— even if I then go on to source my OMF config manually after logging in at the virtual console.
The particular errors I see from OMF, though, are about binaries (system dependencies of my OMF plugins) being missing, which sounds very much like a path problem.
The plugin has had some changes since we last updated it.
I'm going to update our fish-foreign-env package right now and see where that takes us, as a start.
That didn't seem to help. I am now able to log in (looks like the omf plugin 'local-config' was causing the hang. Lots of things are getting errors. I checked my path and it's set to /bin and /usr/bin.
I think maybe the user config is being read before the PATH is set.
@rasendubi , are you using fish as a login shell (or do you at least have programs.fish.enable = true; set)?
The foreign-env plugin for fish by design simply replaces the values of the environment variables in fish with whatever they were set to in the bash script, if they've changed at all.
What's happening on NixOS is that every fish invocation sources ${config.system.build.setEnvironment} through fenv. The sourced file totally clobbers the PATH (as it should), and foreign-env is faithfully reproducing that clobbering (as it should). Here is the relevant line from that file on my system:
Notice that there are no instances of ‘$PATH’ on the right-hand side there.
I took a look at the module for zsh, and it looks like what we want is likely just to prevent NixOS' /etc/fish/config.fish script from being sourced multiple times by the same shell or its descendants.
I did a thing, you guys! Let me know what you think.
I fixed redundant sourcing (both partial and for the whole file) and got it to work so that it can detect when another shell, like bash or zsh, has already done the basic Nix initialization. :-)
Activity
rasendubi commentedon Sep 27, 2016
The issue doesn't seem to be related to nix-shell, as it's reproducible outside of it:
The issue seems to be NixOS-specific, as nixpkgs-fish works fine outside of NixOS (Gentoo).
therealpxc commentedon Mar 25, 2017
I've noticed a very strange problem, potentially related, in NixOS 17.03. When I use fish as a login shell at a virtual console, I get a ton of errors and login hangs. I do not get this behavior when I open a terminal in the GUI. I also do not get this behavior if I disable my oh-my-fish profile— even if I then go on to source my OMF config manually after logging in at the virtual console.
The particular errors I see from OMF, though, are about binaries (system dependencies of my OMF plugins) being missing, which sounds very much like a path problem.
The plugin has had some changes since we last updated it.
I'm going to update our fish-foreign-env package right now and see where that takes us, as a start.
therealpxc commentedon Mar 25, 2017
That didn't seem to help. I am now able to log in (looks like the omf plugin 'local-config' was causing the hang. Lots of things are getting errors. I checked my path and it's set to /bin and /usr/bin.
I think maybe the user config is being read before the PATH is set.
therealpxc commentedon Mar 25, 2017
@rasendubi , are you using fish as a login shell (or do you at least have
programs.fish.enable = true;set)?The foreign-env plugin for fish by design simply replaces the values of the environment variables in fish with whatever they were set to in the bash script, if they've changed at all.
What's happening on NixOS is that every fish invocation sources
${config.system.build.setEnvironment}throughfenv. The sourced file totally clobbers the PATH (as it should), and foreign-env is faithfully reproducing that clobbering (as it should). Here is the relevant line from that file on my system:Notice that there are no instances of ‘$PATH’ on the right-hand side there.
I took a look at the module for zsh, and it looks like what we want is likely just to prevent NixOS' /etc/fish/config.fish script from being sourced multiple times by the same shell or its descendants.
therealpxc commentedon Mar 25, 2017
I did a thing, you guys! Let me know what you think.
I fixed redundant sourcing (both partial and for the whole file) and got it to work so that it can detect when another shell, like bash or zsh, has already done the basic Nix initialization. :-)
xeji commentedon Sep 6, 2018
fixed in #45784