Open GuillaumeDesforges opened 1 year ago
You and I seem to think very similarly @GuillaumeDesforges : D. Each time I come looking for info on something I want, you have already opened an issue for it.
Did some research on this one and heres a dump of my findings:
nix flake
command just straight up doesn't support a lot of those documented flags. Here is an example of where the command
flag gets parsed. I imagine we will have to mimic how the command
variable is done.rcfile
to source, which then sources the original. Here is an example of what that might look like:
$ tmpfile=$(mktemp)
$ cat <
export PS1="[new-prefix]\040$PS1" EOF
$ nix shell nixpkgs#jq --command bash --rcfile $tmpfile
- This has issues because
- you now have to pass an additional shell-specific argument
- you have to specify the shell command explicitly so the shell-specific argument is parsed/passed properly
- it seems really flimsy to me
I was able to at least verify this does work (even with multiple layers of `nix shell`) but it was hardcoding assumptions based on my local environment in terms of profile sourcing and shell.
By reading the source here: https://github.com/NixOS/nix/blob/ea2dd166235e049699cf7f70c243c2b83089f824/src/nix/run.cc#L105-L140
I was able to find that the shell command does not do much that you can measure other than that it changes the PATH
. However, this could be helpful. Maybe you can figure out your default/expected path before shells. And then you can only print the things that get added onto the path.
Example:
~
❯ echo $PATH
/opt/homebrew/bin:/opt/homebrew/sbin:/Users/xavierruiz/.nix-profile/bin:/etc/profiles/per-user/xavierruiz/bin:/run/current-system/sw/bin:/nix/var/nix/profiles
/default/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin
~
❯ nix shell nixpkgs#nodejs nixpkgs#yarn
~
❯ echo $PATH
/nix/store/rr171p6xks9xf2f0ds9wyi4mc36xm5c1-nodejs-20.10.0/bin:/nix/store/45vwimqzlg79phkshmci9rw2r94vns9y-yarn-1.22.19/bin:/opt/homebrew/bin:/opt/homebrew/sb
in:/Users/xavierruiz/.nix-profile/bin:/etc/profiles/per-user/xavierruiz/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/b
in:/usr/sbin:/bin:/sbin
~
❯ # ideally, new shell would look like:
/nix/store/rr171p6xks9xf2f0ds9wyi4mc36xm5c1-nodejs-20.10.0/bin:/nix/store/45vwimqzlg79phkshmci9rw2r94vns9y-yarn-1.22.19/bin:
~
❯ # or you can do something like
❄️
~
❯ # each shell resets the expected "default/expected" path. so another shell adds another flake
I think this functionality can be accomplished with some clever bash scripting, which I don't have time for right now.
Is your feature request related to a problem? Please describe. It is hard to track "how many nix shells deep" I am. I want to know through the prompt.
Describe the solution you'd like When I enter a Nix shell with
nix shell ...
, I want the prompt to be updated using thebash-prompt-prefix
configuration fromnix.conf
, just likenix develop
does. Every new nix shell should concatenate with the previous.Describe alternatives you've considered There seems to be a
--bash-prompt-prefix
flag according to the doc ofnix shell
(2.13.3) but it does not do anything.Priorities
Add :+1: to issues you find important.