Re: Modify user PATH in GNOME in Debian 12

2023-11-25 Thread Max Nikulin

On 25/11/2023 10:50, Greg Wooledge wrote:

On Sat, Nov 25, 2023 at 10:28:13AM +0700, Max Nikulin wrote:

SDDM does read /etc/profile and ~/.profile when starting a user session:
https://sources.debian.org/src/sddm/0.20.0-1/data/scripts/Xsession/


Interesting.  I wondered whether that might be a Debian patch, since I
couldn't see mention of it in the upstream SDDM changelog.


You are right. I posted a link to a wrong file. It should be
https://sources.debian.org/src/sddm/0.20.0-1/debian/Xsession/
Perhaps added in

sddm (0.11.0-4) unstable; urgency=medium
[...]
  * Add the Xsession script. (Closes: #794419)
[...]
 -- Maximiliano Curia   Thu, 03 Sep 2015 17:23:08 +0200


I expect that GDM contains similar code reading /etc/profile and ~/.profile.
LightDM Ubuntu package (but not Debian one) has it.


Ubuntu makes a change of that nature?  That surprises me.  It seems
uncharacteristically nerdy for their mission goal of dumbing everything
down to a common denominator.  Could it be an upstream change instead,
with Ubuntu simply using a newer upstream version than Debian?


I think that patch was added when Unity was the default session and 
LightDM was the default display manager. Nowadays it is Gnome and GDM.





Re: Modify user PATH in GNOME in Debian 12

2023-11-24 Thread Greg Wooledge
On Sat, Nov 25, 2023 at 10:28:13AM +0700, Max Nikulin wrote:
> SDDM does read /etc/profile and ~/.profile when starting a user session:
> https://sources.debian.org/src/sddm/0.20.0-1/data/scripts/Xsession/

Interesting.  I wondered whether that might be a Debian patch, since I
couldn't see mention of it in the upstream SDDM changelog.  But it's
in the upstream repository as well, and it seems it's been there for a
rather long time:

https://github.com/sddm/sddm/blob/develop/data/scripts/Xsession

The cute little unquoted $0 is practically mandatory -- you can't release
a shell script without massively stupid quoting bugs, right?  Ah well,
I'm sure no operating system vendor would **EVER** make a directory
with a space in its name, so it should be **just fine**, right?? :-(

> (wayland-session is a sibling file). I do not like that a part of code is
> similar, but not identical to /etc/X11/Xsession from x11-common. Ideally
> there should be no code duplication.

Well, if the ultimate goal is to have everything work consistently, then
there's gonna be code duplication.  Of course, we're nowhere near that
goal.

> I expect that GDM contains similar code reading /etc/profile and ~/.profile.
> LightDM Ubuntu package (but not Debian one) has it.

Ubuntu makes a change of that nature?  That surprises me.  It seems
uncharacteristically nerdy for their mission goal of dumbing everything
down to a common denominator.  Could it be an upstream change instead,
with Ubuntu simply using a newer upstream version than Debian?



Re: Modify user PATH in GNOME in Debian 12

2023-11-24 Thread Max Nikulin

On 25/11/2023 00:15, Greg Wooledge wrote:

On Fri, Nov 24, 2023 at 11:51:53PM +0700, Max Nikulin wrote:


On the other hand I can not say that I understand what happens with PATH.
Likely modifications made through environment.d are overwritten by
/etc/profile. The latter is called by /etc/sddm/Xsession (or
wayland-session).

/etc/profile is only read by login shells of the Bourne family, unless
something goes out of its way to read that file explicitly.  Does KDE
spawn login shells instead of regular ones?


I see no evidences that launching konsole or xterm using menu or krunner 
causes starting bash as a login shell. I added a "logger" call to 
~/.bash_profile and log entries appear during login only.


SDDM does read /etc/profile and ~/.profile when starting a user session:
https://sources.debian.org/src/sddm/0.20.0-1/data/scripts/Xsession/
(wayland-session is a sibling file). I do not like that a part of code 
is similar, but not identical to /etc/X11/Xsession from x11-common. 
Ideally there should be no code duplication.


I expect that GDM contains similar code reading /etc/profile and 
~/.profile. LightDM Ubuntu package (but not Debian one) has it.


I suspect that startplasma does a bit more and transfers environment 
variables to systemd user session. The reason is the following.


plasma X11:

echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/added-by-etc-profile-d
systemctl --user show-environment | grep '^PATH'
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/added-by-etc-profile-d

fluxbox

echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/added-by-etc-profile-d
systemctl --user show-environment | grep '^PATH'
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/added-by-user-config-environment-d

Notice that a component from ~/.config/evironment.d appears only in 
systemd and only in the case of fluxbox.




Re: Modify user PATH in GNOME in Debian 12

2023-11-24 Thread Greg Wooledge
On Fri, Nov 24, 2023 at 11:51:53PM +0700, Max Nikulin wrote:
> I guess you are not running Gnome.

I'm using fvwm.

> A window manager still might do some magic by calling "systemctl
> set-environment". My impression is that nowadays an application spawned by
> systemd is not something unusual.

The world is definitely changing, and user sessions are becoming more
diverse and more complex.  I certainly don't understand all of the
cases in use today.

> I experimented a bit with KDE and SDDM (I do not have a Gnome VM ready for
> tests). Terminal applications (konsole, xterm) are started as children of
> systemd user session, not startplasma that is spawned by the display
> manager. So /etc/environment.d and ~/.config/environment.d *affect*
> environment of shell in terminal applications.

Well, that's new to me, and very interesting.  I can't say whether it's
a good or bad change, but it's good to know about it.

> On the other hand I can not say that I understand what happens with PATH.
> Likely modifications made through environment.d are overwritten by
> /etc/profile. The latter is called by /etc/sddm/Xsession (or
> wayland-session).

/etc/profile is only read by login shells of the Bourne family, unless
something goes out of its way to read that file explicitly.  Does KDE
spawn login shells instead of regular ones?

> I am puzzled why neither environment.d nor /etc/profile works in the case of
> the topic starter. I suspect a typo somewhere. I am unsure if various bugs
> like https://github.com/systemd/systemd/issues/6414 are relevant.

My reading was that /etc/profile *would* work for them, if they
reconfigured their desktop environment to launch login shells instead
of regular shells, but that isn't what they want to do.

They also pointed out that /etc/bash.bashrc or ~/.bashrc would work,
but only for bash, whereas they were looking for something independent of
the user's shell.

> Just a reminder: BASH does not read ~/.profile if ~/.bash_login or
> ~/.bash_profile exists.

And none of them are read by regular shells.  Those read ~/.bashrc instead.

> You post is great in respect to details concerning current state of affairs.
> I tried to ask if you see a way to make configuration easier for users. E.g.
> /etc/profile is suitable when a shell is involved. It was fine decades ago,
> but display managers may start sessions bypassing shells. Perhaps
> environment.d may be sourced by shells in the case of console login and
> xinit. I still hope that it is possible to create a single point for
> environment configuration and to provide helper tools for various ways to
> login.

The way everything is diversifying right now, it appears that the
situation is going to become more complicated, not simpler, in the next
few years/decades.

If *simple* and *consistent* user configuration across session types
and shells is a goal that any of the desktop environment authors care
about, they need to talk to each other and come up with *one* scheme
that they can all agree on, and implement that.

I've yet to see any evidence that this is a priority for them.

Even if they do come up with one scheme and implement it, we'll still
have legacy environments (like fvwm and fluxbox, presumably) that won't
use it.  And of course direct login shells (console, ssh) will remain
separate entities.



Re: Modify user PATH in GNOME in Debian 12

2023-11-24 Thread Max Nikulin

On 24/11/2023 00:20, Greg Wooledge wrote:

For me, all of the environment.d(5) stuff goes into the systemd --user
service manager which spawns... nothing that's visible to me.  Nothing
at all.

All of my visible applications (terminals, web browsers, etc.) are
spawned by my window manager, which is spawned by my X session, which
is spawned by startx, which is spawned by my console login shell, when
I type the "startx" command.


I guess you are not running Gnome. I am not surprised that environment.d 
and /etc/profile and other shell settings are almost not connected in 
your case. A window manager still might do some magic by calling 
"systemctl set-environment". My impression is that nowadays an 
application spawned by systemd is not something unusual.

- emacs.service (optional)
- Gtk and Qt application may activate various D-Bus services ("busctl 
--user" to get list of ones ready to start)
- MIME type or URI scheme handlers advertised through .desktop files may 
be invoked by GUI applications through D-Bus: "grep DBusActivatable 
/usr/share/applications/*.desktop" see

https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s06.html#key-dbusactivatable

Certainly for particular set of application there may be almost no 
systemd services. Alternatives may be available, e.g. XDG autostart is 
implemented in KDE and Gnome using systemd user session, but other 
window managers may invoke them directly.


Due to these reasons I would not neglect environment.d completely.

I experimented a bit with KDE and SDDM (I do not have a Gnome VM ready 
for tests). Terminal applications (konsole, xterm) are started as 
children of systemd user session, not startplasma that is spawned by the 
display manager. So /etc/environment.d and ~/.config/environment.d 
*affect* environment of shell in terminal applications.


On the other hand I can not say that I understand what happens with 
PATH. Likely modifications made through environment.d are overwritten by 
/etc/profile. The latter is called by /etc/sddm/Xsession (or 
wayland-session).


Another observation is that /etc/profile settings (besides PATH!) do not 
affect "systemctl --user show-environment", but the same settings are 
present in children processes of systemd obtained using


tr '\0' '\n' Fluxbox session has both trees: systemd and window manager. 
environment.d does not affect terminals launched by fluxbox. 
(fbautostart was not installed.)


I am puzzled why neither environment.d nor /etc/profile works in the 
case of the topic starter. I suspect a typo somewhere. I am unsure if 
various bugs like https://github.com/systemd/systemd/issues/6414 are 
relevant.


Just a reminder: BASH does not read ~/.profile if ~/.bash_login or 
~/.bash_profile exists.



Greg, do you have ideas how to relieve pain with environment configuration?
E.g. to not override pam_environment by PATH hardcoded in /etc/profile, to
negotiate what files display managers should read, etc.


Didn't I just post a long message about this?


You post is great in respect to details concerning current state of 
affairs. I tried to ask if you see a way to make configuration easier 
for users. E.g. /etc/profile is suitable when a shell is involved. It 
was fine decades ago, but display managers may start sessions bypassing 
shells. Perhaps environment.d may be sourced by shells in the case of 
console login and xinit. I still hope that it is possible to create a 
single point for environment configuration and to provide helper tools 
for various ways to login.





Re: Modify user PATH in GNOME in Debian 12

2023-11-23 Thread gene heskett

On 11/23/23 09:18, Greg Wooledge wrote:

On Thu, Nov 23, 2023 at 05:43:18AM -0500, gene heskett wrote:

I'm user 1000 and have had the expected results by putting a modified path
in my .profile but it is not automatic, I have to . .profile for every
terminal I start. I have 2 non-stock dirs in my /home/me path, bin and
AppImages, and I put them ahead of the rest of the default path. Now if
someone would tell me how to make that automatic I'd be delighted.


There's nothing that will work in *all* setups.  You have to do what
works for *your* setup.

Last I heard, you use a third-party desktop environment (Trinity or
something like that), and from your context above it looks like you use a
GUI Display Manager to login.  I also believe you're using an X session
(not Wayland) and I'm guessing that your DE is normal, not GNOME-like,
in its terminal spawning.

For this setup, I'd go with the ~/.xsessionrc file.  Create the
file /home/gene/.xsessionrc and put this in it:

 PATH=$HOME/bin:$HOME/AppImages:$PATH
 GENETEST=hello
 export PATH GENETEST

Then on your next login, see whether you have the correct PATH, and
whether you have the GENETEST variable in your environment (this is just a
debugging aid, to be sure the file was used).  If all works as expected,
you can get rid of the GENETEST variable later.  It shouldn't hurt
anything, just uses a few extra bytes of memory, so it's a low priority.

If you don't get the GENETEST variable in any program's environment,
then your OS isn't Debian enough (or your DE clears it out, or your
terminals are spawned in a GNOME-like manner...), and you'll have to
find a different solution.


Got it, thanks Greg


.


Cheers, Gene Heskett.
--
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
 - Louis D. Brandeis



Re: Modify user PATH in GNOME in Debian 12

2023-11-23 Thread Greg Wooledge
On Thu, Nov 23, 2023 at 10:52:25PM +0700, Max Nikulin wrote:
> On 23/11/2023 21:02, Greg Wooledge wrote:
> > Usually, creating ~/.xsessionrc (on Debian only, as it's specific to
> > Debian) will suffice for this, as it gets read in by the X session
> > before it spawns your window manager, and then the WM spawns everything
> > else, all with your desired environment.  (Again, assuming X, not Wayland.)
> 
> I would verify that changes are reflected in
> 
> systemctl --user show-environment
> 
> output. XDG autostart instances, applications activated through D-Bus may be
> spawned by systemd user session, not X session & window manager.

Well, the important thing here is knowing what's spawned by whom, in
your particular setup.

In a traditional window manager setup like I use, *nothing* is spawned
by dbus or by the systemd --user manager.  (Well, maybe not nothing.
Maybe pulseaudio or whatever does audio now?  I have no idea how that
stuff works.  I just login, check whether audio works, and if it does,
I *do not touch it*.)

If you've got things that are actually spawned by systemd --user, then
this may be relevant for you.  For me, it's not.  Nothing that I put
in any of the files mentioned in environment.d(5) has EVER become
part of my environment upon login.  I've been down all of these roads
before, you see.

For me, all of the environment.d(5) stuff goes into the systemd --user
service manager which spawns... nothing that's visible to me.  Nothing
at all.

All of my visible applications (terminals, web browsers, etc.) are
spawned by my window manager, which is spawned by my X session, which
is spawned by startx, which is spawned by my console login shell, when
I type the "startx" command.

So, for *me*, configuring the environment in my login shell's dot files
works.

> Greg, do you have ideas how to relieve pain with environment configuration?
> E.g. to not override pam_environment by PATH hardcoded in /etc/profile, to
> negotiate what files display managers should read, etc.

Didn't I just post a long message about this?

People have been searching for this holy grail for DECADES.  It does not
exist.



Re: Modify user PATH in GNOME in Debian 12

2023-11-23 Thread Max Nikulin

On 23/11/2023 21:02, Greg Wooledge wrote:

Usually, creating ~/.xsessionrc (on Debian only, as it's specific to
Debian) will suffice for this, as it gets read in by the X session
before it spawns your window manager, and then the WM spawns everything
else, all with your desired environment.  (Again, assuming X, not Wayland.)


I would verify that changes are reflected in

systemctl --user show-environment

output. XDG autostart instances, applications activated through D-Bus 
may be spawned by systemd user session, not X session & window manager.


Greg, do you have ideas how to relieve pain with environment 
configuration? E.g. to not override pam_environment by PATH hardcoded in 
/etc/profile, to negotiate what files display managers should read, etc.




Re: Modify user PATH in GNOME in Debian 12

2023-11-23 Thread Max Nikulin

On 23/11/2023 21:16, Greg Wooledge wrote:

For this setup, I'd go with the ~/.xsessionrc file.  Create the
file/home/gene/.xsessionrc and put this in it:

 PATH=$HOME/bin:$HOME/AppImages:$PATH


SDDM (default for KDE and I assume it is Gene's case) reads ~/.profile 
that contains the following


 >8 
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
 8< 

so perhaps it is enough to add similar blocks for other custom 
directories. In Ubuntu LightDM reads this file as well, but in Debian it 
is not so by default.





Re: Modify user PATH in GNOME in Debian 12

2023-11-23 Thread Greg Wooledge
On Thu, Nov 23, 2023 at 05:43:18AM -0500, gene heskett wrote:
> I'm user 1000 and have had the expected results by putting a modified path
> in my .profile but it is not automatic, I have to . .profile for every
> terminal I start. I have 2 non-stock dirs in my /home/me path, bin and
> AppImages, and I put them ahead of the rest of the default path. Now if
> someone would tell me how to make that automatic I'd be delighted.

There's nothing that will work in *all* setups.  You have to do what
works for *your* setup.

Last I heard, you use a third-party desktop environment (Trinity or
something like that), and from your context above it looks like you use a
GUI Display Manager to login.  I also believe you're using an X session
(not Wayland) and I'm guessing that your DE is normal, not GNOME-like,
in its terminal spawning.

For this setup, I'd go with the ~/.xsessionrc file.  Create the
file /home/gene/.xsessionrc and put this in it:

PATH=$HOME/bin:$HOME/AppImages:$PATH
GENETEST=hello
export PATH GENETEST

Then on your next login, see whether you have the correct PATH, and
whether you have the GENETEST variable in your environment (this is just a
debugging aid, to be sure the file was used).  If all works as expected,
you can get rid of the GENETEST variable later.  It shouldn't hurt
anything, just uses a few extra bytes of memory, so it's a low priority.

If you don't get the GENETEST variable in any program's environment,
then your OS isn't Debian enough (or your DE clears it out, or your
terminals are spawned in a GNOME-like manner...), and you'll have to
find a different solution.



Re: Modify user PATH in GNOME in Debian 12

2023-11-23 Thread Greg Wooledge
NOTE: the original Subject: header of this thread includes the keyword
"GNOME" which does not appear in the body of the original message, but
which is *terribly* important here.  See below.

On Thu, Nov 23, 2023 at 09:49:13AM +, Bernhard Walle wrote:
> I want to add some directory to $PATH for each user. In the past, I added a
> file /etc/profile.d/path.sh, but that doesn't work any more, only when I
> manually start bash as login shell (or modify the setting of
> gnome-terminal).

OK, good.  You already understand the basics, so we don't need to explain
those in detail.

> My next attempt was to use systemd's /etc/environment.d/path.conf
> 
> PATH=${PATH}:/opt/vendor/product/bin
> XPATH=${PATH}:/opt/vendor/product/bin
> 
> but that doesn't work either. While XPATH appears, PATH is still the
> default.
> 
> systemctl show-environment --user

"systemctl --user" does not show you the environment that a login
session uses.  It only shows you the environment that the "per-user
service manager" uses when it starts --user units.

Systemd actually has nothing to do with login session configuration
at all.  It's a gigantic dead end.

> To be honest, I'm quite confused where that default path is defined. Even
> when I modify /etc/login.defs (ENV_PATH) or /etc/profile, I still get the
> default value.

/etc/login.defs only works with the login(1) program, which is for the
console.  Even then, the value of PATH set by login(1) can and will be
overridden by other programs before you finally get a shell prompt.
Among those overrides are PAM (see pam_env(7)) and your shell (as you
already knew, since you mentioned /etc/profile).

As such, ENV_PATH in /etc/login.defs is pretty much useless.  It's never
going to survive to see the light of day, even on a console login.  And
it's not used at all by Display Manager (GUI) logins.

Even pam_env ends up being useless for PATH, as the shell overrides it.
It might be useful to set *other* variables, but it's extremely limited.
You can set MYVAR=/some/absolute/path but you *cannot* for example set
MAIL=$HOME/Maildir/ because it will not expand $HOME for you.  It's
just so frustatingly inept that you ultimately end up forgetting about
it (but not until you've wasted hours trying to get it to work).

> Of course I can edit my own ~/.bashrc or /etc/bashrc, but that's not what I
> want since then only bash gets the PATH environment, not other shells or
> other programs.

The sad news is that there IS no holy grail here.  I've searched for it
myself, as have many other people.  It just *does not* exist.

There is no single point of configuration that can customize all user
login sessions, across all login methods, all shells, all desktop
environments, etc.

What ends up happening in practice is that you have to identify *all*
of the configuration points for all of the login methods and shells
that you care about.  For console logins with Bourne-family shells,
you can customize a default PATH in /etc/profile (or one of the files
that it dots in).  For console logins with csh-family shells, you can
use /etc/csh.login.  For Debian X sessions, there is no recommended
global access point, but you can create a ~/.xsessionrc file in your
home directory.  I don't know how you do it with Wayland.  Nobody who
uses Wayland has ever cared enough to figure it out and publically
announce how to do it (or at least, not here).

Now, I mentioned GNOME at the top of this reply, because GNOME was in the
Subject: header.  This is important because GNOME adds one additional
wrinkle to this problem.  In a normal X session, there is a single
parent process from which all the other X client processes are spawned.
Getting the correct environment into that parent process is sufficient
to have it propagated into every program that gets launched thereafter.
Usually, creating ~/.xsessionrc (on Debian only, as it's specific to
Debian) will suffice for this, as it gets read in by the X session
before it spawns your window manager, and then the WM spawns everything
else, all with your desired environment.  (Again, assuming X, not Wayland.)

Not so with GNOME.  In GNOME, all gnome-terminal processes are spawned
by dbus, instead of by the user's X/Wayland session.  Therefore,
gnome-terminal and the shell inside it derive from a completely
different ancestry, and come up with a completely different environment.
(And don't even ask me how to configure dbus's environment.  I have no
idea.)

So, *specifically* for GNOME, what you end up doing in practice is
precisely the thing you didn't want to do: customizing ~/.bashrc or
~/.cshrc or whatever shell-equivalent RC file, to establish the desired
environment in the shell itself, bypassing whatever crap dbus gives you.



Re: Modify user PATH in GNOME in Debian 12

2023-11-23 Thread gene heskett

On 11/23/23 05:06, Bernhard Walle wrote:

Hello,

I want to add some directory to $PATH for each user. In the past, I 
added a file /etc/profile.d/path.sh, but that doesn't work any more, 
only when I manually start bash as login shell (or modify the setting of 
gnome-terminal).


My next attempt was to use systemd's /etc/environment.d/path.conf

     PATH=${PATH}:/opt/vendor/product/bin
     XPATH=${PATH}:/opt/vendor/product/bin

but that doesn't work either. While XPATH appears, PATH is still the 
default.


     systemctl show-environment --user

     PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
NCP_PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/ncp/clnt/bin:/opt/ncp/clnt/bin

To be honest, I'm quite confused where that default path is defined. 
Even when I modify /etc/login.defs (ENV_PATH) or /etc/profile, I still 
get the default value.


Of course I can edit my own ~/.bashrc or /etc/bashrc, but that's not 
what I want since then only bash gets the PATH environment, not other 
shells or other programs.


Can somebody help me, please? Thanks a lot.


Kind regards,
Bernhard


I'm user 1000 and have had the expected results by putting a modified 
path in my .profile but it is not automatic, I have to . .profile for 
every terminal I start. I have 2 non-stock dirs in my /home/me path, bin 
and AppImages, and I put them ahead of the rest of the default path. Now 
if someone would tell me how to make that automatic I'd be delighted.




.


Cheers, Gene Heskett.
--
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
 - Louis D. Brandeis