From unknown Thu Aug 14 21:56:51 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#59774 <59774@debbugs.gnu.org> To: bug#59774 <59774@debbugs.gnu.org> Subject: Status: Activating conda environments breaks the prompt because bash eats PS1 Reply-To: bug#59774 <59774@debbugs.gnu.org> Date: Fri, 15 Aug 2025 04:56:51 +0000 retitle 59774 Activating conda environments breaks the prompt because bash = eats PS1 reassign 59774 guix submitter 59774 Hugo Buddelmeijer severity 59774 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 02 07:48:27 2022 Received: (at submit) by debbugs.gnu.org; 2 Dec 2022 12:48:27 +0000 Received: from localhost ([127.0.0.1]:46518 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p15Ss-00050W-HP for submit@debbugs.gnu.org; Fri, 02 Dec 2022 07:48:27 -0500 Received: from lists.gnu.org ([209.51.188.17]:55980) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p15Sr-00050L-3R for submit@debbugs.gnu.org; Fri, 02 Dec 2022 07:48:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p15Se-0004Dp-BU for bug-guix@gnu.org; Fri, 02 Dec 2022 07:48:21 -0500 Received: from mail-ed1-f51.google.com ([209.85.208.51]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p15SY-0002Qo-2A for bug-guix@gnu.org; Fri, 02 Dec 2022 07:48:08 -0500 Received: by mail-ed1-f51.google.com with SMTP id a16so6301504edb.9 for ; Fri, 02 Dec 2022 04:48:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OkCNPliP5wQS8XpXmH8lx8hHPwVmYWMp7BgUKdUVDbg=; b=kjGzBLd6eNhUTQrym40gee9SV2L9+ZBW0FaZKLDBCsa2RedwrbynTRr3EsLMnKQuNH 9QClK1LK75gL9aOd4gCzBkJiafAILXHQu/Udfa45prGdOt/m07k7VPnGkw3W6VC31UMc 5uxhWOA/VxFtpjgZ5pvWTdskEDjX+GbM6b16HFOBKcqzwPLMndMlQyW7yiRZdtp9loDM fJlkmtKSvRhREJWY0mpAuisnp1yh1zGhg0/MdNZNj5L8czbSe6yFnDxrLULvxk2uESg3 gMobYsA9gHCtLSwJ3KgBhtQacSGnOPamj8q+9uPOt5P1J6nZvhnKFygV2bRCAvi2fb3v VslA== X-Gm-Message-State: ANoB5pnRw7vsWNrWzSoPFlwktH3G3VF+5bq5rTL7TVoLoCVJUu+cxtnl FyL3cxriqTV0OrZ6j67KGFTIt3x8d1RNOadL0tj4P0oE+VBbNQ== X-Google-Smtp-Source: AA0mqf58dx0jOU7PD25LjGvh8Bt4gPLv7AwcupieTNKqR21RTjIS8a/pPgiQbuujQg+Md71vLMWnYtybMbFyarxjsl8= X-Received: by 2002:aa7:cc04:0:b0:463:1a0c:4dd1 with SMTP id q4-20020aa7cc04000000b004631a0c4dd1mr56054151edt.137.1669985283891; Fri, 02 Dec 2022 04:48:03 -0800 (PST) MIME-Version: 1.0 From: Hugo Buddelmeijer Date: Fri, 2 Dec 2022 13:47:52 +0100 Message-ID: Subject: Activating conda environments breaks the prompt because bash eats PS1 To: bug-guix@gnu.org Content-Type: multipart/alternative; boundary="000000000000a0667505eed7bfe5" Received-SPF: pass client-ip=209.85.208.51; envelope-from=blackshift@gmail.com; helo=mail-ed1-f51.google.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.1 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.1 (--) --000000000000a0667505eed7bfe5 Content-Type: text/plain; charset="UTF-8" Hi all, ### Summary #### Activating a conda environment on guix will break your bash prompt, because guix' binary-replacing-bash-script eats PS1. ### Reproduce #### E.g.: # Start a container with conda hugo@alex ~/t $ guix shell -C conda sudo bash # Add conda functions to ~/.bashrc. This raises errors but does work. hugo@alex ~/t [env]$ conda init bash # ignore the errors # Add the functions to bash. This activates the conda environment called "base". hugo@alex ~/t [env]$ source ~/.bashrc sh: dirname: command not found sh: dirname: command not found (base) # Deactivate the environment. (base) conda deactivate ### Actual and expected behaviour ### The prompt is now empty. The expected result is that the "(base)" string is prefixed to the prompt when activating an environment (or replaced when switching environments). "base" is the default environment. The string should be removed when the environment is deactivated. However, instead, upon activating an environment, the entire prompt is replaced with "(base)". Deactivating the environment removes the string, resulting in an empty prompt. ### Cause ### The cause of the disappearing prompt is due to an interplay between conda and guix and bash. Normally, "conda" is either a binary executable, or a bash function, but in guix it can also be a bash script. What normally happens after installing conda is: - The user calls "conda init bash". This is the binary executable "conda", which adds the "conda" bash function to ~/.bashrc. This is only done once for each user, after which the shell is restarted. What normally happens in a user session is: - The shell implicitly calls "conda activate base" through ~/.bashrc, or the user calls it explicitly (usually not with "base", but with their own environment). This "conda" is the conda bash function. - The conda bash function calls the conda binary, passing PS1 (and other variables). - The conda binary uses PS1 to construct a new string to be used as a prompt, and returns that to the conda bash function. - The conda bash function uses the output from the conda binary to set PS1. It also makes a backup of PS1 in CONDA_PS1_BACKUP. But in guix, the conda binary is renamed to conda_real, and is replaced with [by?] the conda bash script. Therefore this happens: - The conda shell function is called through "conda activate base". - The conda shell function calls the conda bash script. The conda bash script eats PS1 because it is non-interactive. - The conda bash script calls the conda_real binary, specifying an empty PS1. - The conda_real binary adds the "(base)" prefix to the empty string and returns the string to the conda bash script. - The conda bash script returns the string to the conda bash function. - The conda bash function sets PS1 to the new string, which is just "(base)". ### Workaround ### My personal workaround is to skip the "conda init bash" step entirely, but do something equivalent manually: - Call "conda shell.bash hook" and store the output in ~/. conda_shell.bash_hook.sh . - Replace the "$CONDA_EXE" at the top of the file with "${HOME}/.guix-profile/bin/conda"; otherwise it contains an absolute path, including a guix hash. (This is another problem, I now realize.) - Add "--norc -i" to every "$CONDA_EXE" call in that file. - Add ". ~/.conda_shell.bash_hook.sh" to ~/.bash_profile (has to be .bash_profile and not .bashrc because otherwise it would be called from the conda bash script, leading to recursion). The crux is that now it calls the conda bash script (created by guix) with the -i flag (interactive mode), which prevents PS1 from being eaten. The --norc prevents .bash_profile from being read again, thereby preventing recursion. ### Proper Solution ### I can see two possible proper solutions; but I cannot vouch for the feasibility in guix. 1) Use another shell than bash for the executable-replacing-script of the conda package. Only bash eats PS1, other POSIX-compliant shells do not; e.g. dash. Is it possible to use another shell than bash for guix packages? 2) "conda shell.bash hook" uses the contents of /etc/profile.d/conda.sh to create the conda bash function. Perhaps it would be possible to patch that file to include the "--norc -i" flags. Maybe this would also require placing the "conda init" output in ".bash_profile" instead of ".bashrc", not sure. ### Disclaimer ### My ultimate goal is to ditch conda altogether and use guix instead. However, it will take a while to convince everyone. In the meantime it would help to have conda running well. That would also make it easier to attract conda package maintainers. Cheers, Hugo --000000000000a0667505eed7bfe5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi all,

### Summary ####

Activating a conda environment on guix will break you= r bash prompt, because guix' binary-replacing-bash-script eats PS1.
=


### Reproduce ####
<= br>
E.g.:

# Start a container with conda=
hugo@alex ~/t $ guix shell -C conda sudo bash
=
# Add conda functions to ~/.bashrc. This raises errors but d= oes work.
hugo@alex ~/t [env]$ conda init bash
# ig= nore the errors

# Add the functions to bash. This = activates the conda environment called "base".
hugo= @alex ~/t [env]$ source ~/.bashrc
sh: dirname: command not found<= br>sh: dirname: command not found
(base)

#= Deactivate the environment.
(base) conda deactivate


### Actual and expected behaviour ###

The prompt is now empty. The expected result is= that the "(base)" string is prefixed to the prompt when activati= ng an environment (or replaced when switching environments). "base&quo= t; is the default environment. The string should be removed when the enviro= nment is deactivated.

However, instead, upon activ= ating an environment, the entire prompt is replaced with "(base)"= . Deactivating the environment removes the string, resulting in an empty pr= ompt.


### Cause ###

<= /div>
The cause of the disappearing prompt is due to an interplay betwe= en conda and guix and bash. Normally, "conda" is either a binary = executable, or a bash function, but in guix it can also be a bash script.

What normally happens after installing conda is= :
- The user calls "conda init bash". This is the b= inary executable "conda", which adds the "conda" bash f= unction to ~/.bashrc. This is only done once for each user, after which the= shell is restarted.

What normally happens in = a user session is:
- The shell implicitly calls "conda a= ctivate base" through ~/.bashrc, or the user calls it explicitly (usua= lly not with "base", but with their own environment). This "= conda" is the conda bash function.
- The conda bash function= calls the conda binary, passing PS1 (and other variables).
- The= conda binary uses PS1 to construct a new string to be used as a prompt, an= d returns that to the conda bash function.
- The conda bash funct= ion uses the output from the conda binary to set PS1. It also makes a backu= p of PS1 in CONDA_PS1_BACKUP.

But in guix, the con= da binary is renamed to conda_real, and is replaced with [by?] the conda ba= sh script. Therefore this happens:
- The conda shell function is = called through "conda activate base".
- The conda s= hell function calls the conda bash script. The conda bash script eats PS1 b= ecause it is non-interactive.
- The conda bash script calls the c= onda_real binary, specifying an empty PS1.
- The conda_real binar= y adds the "(base)" prefix to the empty string and returns the st= ring to the conda bash script.
- The conda bash script returns th= e string to the conda bash function.
- The conda bash function se= ts PS1 to the new string, which is just "(base)".

<= /div>

### Workaround ###

My per= sonal workaround is to skip the "conda init bash" step entirely, = but do something equivalent manually:
- Call "conda shell.ba= sh hook" and store the output in ~/.conda_shell.bash_hook.sh .
- Replace the "$CON= DA_EXE" at the top of the file with "${HOME}/.guix-profile/bin/co= nda"; otherwise it contains an absolute path, including a guix hash. (= This is another problem, I now realize.)
- Add "--norc -= i" to every "$CONDA_EXE" call in that file.
- Add = ". ~/.conda_shell.bash_hoo= k.sh" to ~/.bash_profile (has to be .bash_profile and not .bashrc = because otherwise it would be called from the conda bash script, leading to= recursion).

The crux is that now it calls the= conda bash script (created by guix) with the -i flag (interactive mode), w= hich prevents PS1 from being eaten. The --norc prevents .bash_profile from = being read again, thereby preventing recursion.

### Proper Solution ###

I can see two= possible proper solutions; but I cannot vouch for the feasibility in guix.=

1) Use another shell than bash for the executable= -replacing-script of the conda package. Only bash eats PS1, other POSIX-com= pliant shells do not; e.g. dash. Is it possible to use another shell than b= ash for guix packages?

2) "conda shell.bash h= ook" uses the contents of /etc/profile.d/conda.sh to create the conda = bash function. Perhaps it would be possible to patch that file to include t= he "--norc -i" flags. Maybe this would also require placing the &= quot;conda init" output in ".bash_profile"
=C2= =A0instead of ".bashrc", not sure.


<= /div>
### Disclaimer ###

My ultimate goal is t= o ditch conda altogether and use guix instead. However, it will take a whil= e to convince everyone. In the meantime it would help to have conda running= well. That would also make it easier to attract conda package maintainers.=


Cheers,
Hugo
<= br>




<= br>




<= br>

--000000000000a0667505eed7bfe5--