unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: Wojtek Kosior via <help-guix@gnu.org>
To: Gottfried <gottfried@posteo.de>
Cc: help-guix@gnu.org
Subject: Re: to enable all profiles at login time
Date: Sun, 16 Apr 2023 22:18:39 +0200	[thread overview]
Message-ID: <20230416221839.00454cad.koszko@koszko.org> (raw)
In-Reply-To: <8b5e1a16-195c-3cd3-73f5-cf748dd60e56@posteo.de>

[-- Attachment #1: Type: text/plain, Size: 4521 bytes --]

Hi Gottfried,

I see 3 potential problems.

1.
The snippet you addet to .bashrc refers to a variable named
"GUIX_EXTRA_PROFILES". Is this variable defined somewhere? Is seems it
isn't. It should be assigned the path to the directory holding your
profiles so you could for example add a

    GUIX_EXTRA_PROFILES=/path/to/directory/with/my/guix/profiles

line before the `for` loop. Of course, replacing the
"/path/to/directory/with/my/guix/profiles" with the appropriate path
for your system.

2.
Why is `basename` being used here? Consider the following example:

- "GUIX_EXTRA_PROFILES" is set to /home/user/my-extra-guix-stuff
- you have 1 extra Guix profile under
  "/home/user/my-extra-guix-stuff/music"
- the profile mentioned above has its `profile` script under
  "/home/user/my-extra-guix-stuff/music/etc/profile"

Now, let's look at what the

    profile=$i/$(basename "$i")

line does. This line is inside a `for` loop, in each iteration the
variable "i" holds the path to one of the profiles under
"/home/user/my-extra-guix-stuff". In one iteration "i" is going to hold
the string "/home/user/my-extra-guix-stuff/music". The `basename "$i"`
command therefore outputs just "music". So the line we're analyzing
assigns the string "/home/user/my-extra-guix-stuff/music/music" to
variable called "profile". Is this what we wanted? The next line is
going to check for the existence of file
"/home/user/my-extra-guix-stuff/music/music/etc/profile" but it should
instead check for the existence of
"/home/user/my-extra-guix-stuff/music/etc/profile". So you might want
to e.g. replace the line

    profile=$i/$(basename "$i")

with just

    profile=$i

3.
You edited "~/.bash_profile" which is indeed known to be read by bash.

However, this is not that simple. Bash has 3 possible modes of running:
non-interactive shell, interactive shell and (interactive) login shell.
The "login shell" mode is meant to be used when, well, bash is spawned
in a terminal upon user login. "~/.bash_profile" is *only* read by bash
in this mode and not in the other 2. In interactive shell mode, bash
reads "~/.bashrc" *instead*.

When you, for example, execute a `bash` command inside an
already-running shell, the child bash shell that spawns is not going to
consider itself a login shell but rather a mere interactive shell. To
make bash think is is a login shell, you can e.g. start it with a `-l`
flag, like `bash -l`.

The problem is, most terminal emulators by default don't start bash
this way. The 2 solutions I've been using are to either
- change the configuration of one's terminal emulator to start bash
  with `-l`
- or make the ".bashrc" script check if current interactive shell was
  spawned by a teminal emulator process and if yes, have it activate the
  Guix profiles.

The 1st solution is the proper one, the 2nd one is just a workaround
for terminal emulators that are not configurable enough :)


Wojtek


-- (sig_start)
website: https://koszko.org/koszko.html
PGP: https://koszko.org/key.gpg
fingerprint: E972 7060 E3C5 637C 8A4F  4B42 4BC5 221C 5A79 FD1A

♥ R29kIGlzIHRoZXJlIGFuZCBsb3ZlcyBtZQ== | ÷ c2luIHNlcGFyYXRlZCBtZSBmcm9tIEhpbQ==
✝ YnV0IEplc3VzIGRpZWQgdG8gc2F2ZSBtZQ== | ? U2hhbGwgSSBiZWNvbWUgSGlzIGZyaWVuZD8=
-- (sig_end)


On Sun, 16 Apr 2023 13:09:00 +0000
Gottfried <gottfried@posteo.de> wrote:

> Hi,
> 
> according to the cookbook
> I added
> --------------------------------------------
> for i in $GUIX_EXTRA_PROFILES/*; do
>    profile=$i/$(basename "$i")
>    if [ -f "$profile"/etc/profile ]; then
>      GUIX_PROFILE="$profile"
>      . "$GUIX_PROFILE"/etc/profile
>    fi
>    unset profile
> done
> -----------------------------------------------
> into my .bash_profile file
> in order to enable all profiles at login time:
> ------------------------------------------------
> My .bash_profile file looks now like that:
> 
> # Honor per-interactive-shell startup file
> if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
> 
> for i in $GUIX_EXTRA_PROFILES/*; do
>    profile=$i/$(basename "$i")
>    if [ -f "$profile"/etc/profile ]; then
>      GUIX_PROFILE="$profile"
>      . "$GUIX_PROFILE"/etc/profile
>    fi
>    unset profile
> done
> -----------------------------------------------
> 
> but when starting MATE Desktop all my profiles are not enabled.
> 
> Could somebody help because probably the two entries in my .bash_profile
> got a mistake.
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2023-04-16 20:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-16 13:09 to enable all profiles at login time Gottfried
2023-04-16 20:18 ` Wojtek Kosior via [this message]
2023-04-17  7:37   ` Gottfried
2023-04-17 11:56     ` Wojtek Kosior via
2023-04-17 12:45       ` Gottfried
2023-04-17 12:55         ` Wojtek Kosior via
2023-04-17 14:30           ` Martin Castillo
2023-04-17 14:55           ` Gottfried
2023-04-17 20:15             ` Wojtek Kosior via
2023-04-18 15:19               ` Gottfried
2023-04-17 18:32         ` Sergiu Ivanov
2023-04-20 10:11           ` Gottfried
2023-04-20 10:20             ` Sergiu Ivanov
2023-04-20 11:28               ` Gottfried
2023-04-20 13:51                 ` Sergiu Ivanov
2023-04-17 17:25 ` Giovanni Biscuolo
  -- strict thread matches above, loose matches on Subject: below --
2023-04-19 16:10 Gottfried
2023-04-19 18:19 ` Martin Castillo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230416221839.00454cad.koszko@koszko.org \
    --to=help-guix@gnu.org \
    --cc=gottfried@posteo.de \
    --cc=koszko@koszko.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).