Repository navigation
Description
Problem description
Currently, when running the shell cli command we first activate the environment and then start a new shell process. This has some issues:
When the shell is started (after activation) it sources the shell profile
This causes some issues:
- It might overwrite the PATH variable which places the binary PATHs from pixi in the middle of the PATH. This is the case for homebrew and it breaks the environment:
- If a user uses the default installation of conda they have a base environment which is sourced in the profile. This basically overwrites all conda specific environment variables which activates the base environment instead of the conda environment. 🙈
The PS1 variable needs to be set/modified from the shell process
The PS1 environment variable is a special one. It only seems to work if you modify the variable from the shell process itself. This means you cannot set it before starting the shell. Pixi currently works around this by setting a special environment variable (PIXI_PROMPT) and requires some bash profile modifications (as part of the completion script).
This is a less than ideal situation because it requires modifications to your bash profile. Although our default installation script can do this for you, people might not use that to install pixi (they might use homebrew, cargo, simply copy the binary, etc.).
This is also explained in the docs but I'd prefer that this just works out of the box.
We cannot do isolated shells
As requested by #289, it would be nice if we could spawn a shell without any outside environment variables set. Essentially running a completely pure environment. Currently, because the profile is sourced we cannot guarantee this.
Proposed solution
The solution is to run the pixi installation script after and inside the spawned shell process. We already found several workarounds to achieve this.
- Some shells (powershell and cmdexe) have native support to run a file before becoming interactive
- @pavelzw found a hacky way for bash
- @pavelzw found a hacky way for zsh
- We can inject keystrokes in the spawned process to basically type "source <our_activation_script" (this is the approach taken by poetry)
- More?
Activity
jonashaag commentedon Aug 24, 2023
FWIW I would expect @pavelzw's approach to be more robust than sending keystrokes. It should be feasible for all (most?) shells.
Another approach would be to have a special magic script sourced in your .bashrc (etc) that deals with all of this logic. We can pass params to the script via environment variables.
pavelzw commentedon Aug 24, 2023
I would prefer to not need to change my bashrc except for shell completion if possible.
baszalmstra commentedon Aug 24, 2023
This is also my philosophy. This is exactly what I dislike about conda/mamba/micromamba. Although our installation script can add these things for you there are a number of different ways to install pixi on your system (homebrew, cargo, just put binary on your PATH). Preferably all features just work out of the box.
pelson commentedon Aug 25, 2023
This is a big one, IMO (and one I just tripped over). Essentially, it gives the impression that things are working (the PS1 is being updated), but you don't actually get the right shell environment. I have a fairly vanilla miniforge installation...
Reproducer:
wolfv commentedon Aug 25, 2023
Yes, we are actively working on this - using
rexpectto mimic whatpoetryis doing withpexpect- starting a shell and sending some keystrokes!twrightsman commentedon Sep 27, 2023
Is this solved by #316? From my reading it seems the
PS1issue persists?baszalmstra commentedon Sep 28, 2023
@twrightsman Yes this should be solved by #316. That PR changes the way the shell is started. The environment activation now happens after the shell has started which should solve issues with environment variables being overwritten by the shell profile.
There are still some issues with the PS1 for different shells which we will solve in another PR.