From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id orNZE2/0iWNTLwAAbAwnHQ (envelope-from ) for ; Fri, 02 Dec 2022 13:49:51 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id GOqrEW/0iWOqIgEAG6o9tA (envelope-from ) for ; Fri, 02 Dec 2022 13:49:51 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id ACDB61DFB6 for ; Fri, 2 Dec 2022 13:49:50 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p15U5-0004Sm-JZ; Fri, 02 Dec 2022 07:49:41 -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 1p15TT-0004RS-77 for bug-guix@gnu.org; Fri, 02 Dec 2022 07:49:15 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p15TS-0003KP-P4 for bug-guix@gnu.org; Fri, 02 Dec 2022 07:49:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p15TS-000510-Hw for bug-guix@gnu.org; Fri, 02 Dec 2022 07:49:02 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#59774: Activating conda environments breaks the prompt because bash eats PS1 Resent-From: Hugo Buddelmeijer Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Fri, 02 Dec 2022 12:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 59774 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 59774@debbugs.gnu.org X-Debbugs-Original-To: bug-guix@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.166998530719256 (code B ref -1); Fri, 02 Dec 2022 12:49:02 +0000 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: 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: bug-guix-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1669985390; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:list-id:list-help:list-unsubscribe:list-subscribe: list-post; bh=OkCNPliP5wQS8XpXmH8lx8hHPwVmYWMp7BgUKdUVDbg=; b=VWc/DU/hopGWyWzV5Ua8HRucfWNFAPq7DJ/MPYdyHWR45m5oi4zW5kJ4zukyaveQwCZq+8 yGPjAXlhfAmEkRkLgyKxuGc5oXm/nBjISoNk6HLoTf20z2lDDPKB6hYD2jlNl3yQlbpiDC OkxtL8DNgDlmLwDjQVqZ4bEK1bMpsdo9UogXPa0QooIdXHw7BIpZ0EdtDbBdhcznumGPnZ FpfTpG7iwsztJvor/vSKO5MW57JGzWA137QIVJlOVG+T800XXbmoP4zahEQPFAoS12B0KN ZfJlf0AadDclpFyLF9WsQFpstWEI+CYqyS2X/JNDn9THWzJ8x81aYQGKdyVgAQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1669985390; a=rsa-sha256; cv=none; b=dHqjc03N4yZBDfJhIFCrsX4KOaWZ6jvQfjZbEaJrgzPn5vBMC68FHz3wYVhnrcZVvBK503 zvPzXKhZwpNlTQeDwUhy7X9YP71wh9S36wHiNyPeMaRYTy8Xlvelr7PSldlKobxLx/78/I 9WIWFnJb7z5vvM7IHUGKuV8WgBvNBa2XSS+4WhwToDb8n44vLa6GXqJ1jq1vg5KTZtalVf e1SDn5s1ra8f9u3JADTnmxzHg1ju4glErdgUu8sfON8tYacey7eFI9MVTY52TEUY0+tYCy U/GbP/RwDuAI1m9u5vtSO5Tihk0/3O9R7viemckNQuI9SqkUDjYZMiqIZBQLjQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.67 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: ACDB61DFB6 X-Spam-Score: -1.67 X-Migadu-Scanner: scn1.migadu.com X-TUID: FennKZJ1CFS4 --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--