Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Bullseye: setting user environment correctly?

Graphical Environments, Managers, Multimedia & Desktop questions.
Post Reply
Message
Author
zenlord
Posts: 81
Joined: 2009-06-17 15:23

Bullseye: setting user environment correctly?

#1 Post by zenlord »

Hi,

Debian Bullseye + Gnome 3.38 (current versions in official repo's)
$HOME is served to the client over NFS -> this may cause leftover configuration from the Buster and Stretch era to be present.

I'm finishing up migration of my Buster configuration scripts to Bullseye, and the last error I was able to workaround was the missing $DISPLAY environment variable. I just hardcoded it in /etc/bash.bashrc:

Code: Select all

export DISPLAY=:1
... and now I have almost no more errors left to solve :).

Online sources(TM) seem to indicate that Wayland does not require the DISPLAY variable, and that my errors are caused by applications that still rely on the DISPLAY variable being set.
The Archlinux wiki (Talk page) seems to indicate that environment variables are set in the systemd user session these days.

My question is: the above solution seems a bit blunt and maybe there's a better way of doing this - but I don't know where to start. Any hints?
Thx,
Vincent

zenlord
Posts: 81
Joined: 2009-06-17 15:23

Re: Bullseye: setting user environment correctly?

#2 Post by zenlord »

Following up on this, I have edited the title of this thread. Although the $DISPLAY variable is also on my radar, my more generic question is "how do I set user environment variables anno 2021 (i.e. with Gnome 3.38, Systemd 242 and Bullseye)?" - variables such as

Code: Select all

XDG_CACHE_HOME=/var/cache/users/<username>
UMASK=0007
NSS_SDB_USE_CACHE=yes
umask($UMASK)
The above referenced Archlinux wiki-page contains a nice overview of 7 options, and I have only had real success with an approach that is probably around since the 1980's: setting the vars in $HOME/.bashrc and then sourcing that file in $HOME/.bash_profile.

The other options either
* failed silently (maybe Debian uses other paths than Archlinux and my files were just not picked up), or
* I hit the constraint that with some system-wide options (in /etc or /lib), one cannot use so-called specifiers (mapping e.g. %u to <username>), or
* I came pretty close (the option where you set a system-wide user@.service), but that seemed to trigger systemd's user manager failing to start on some occasions - I did use the "ConditionGroup=users" control in the service file, and maybe I did not use it correctly.

Until today, I was using a mixture of pam_umask (reading from the user's GECOS field), pam_env (setting vars in /etc/security/pam_env.conf), but pam_env was always spewing 2 errors upon login (without consequences I might add) and overall, it feels outdated.

The ideal Systemd-based solution would be either a system-wide service file that is only applied to a certain group of users, or a 'systemd generator' that I can enable for a group of users. I may be completely misguided, though. Happy to hear other experiences (or solutions? ;))

Thx.

peter_irich
Posts: 1403
Joined: 2009-09-10 20:15
Location: Saint-Petersburg, Russian Federation
Been thanked: 11 times

Re: Bullseye: setting user environment correctly?

#3 Post by peter_irich »

Also for umask is /etc/profile:
umask 007
and /etc/pam.d/common-session, string
session optional pam_umask.so umask=0007

Peter.

seeker5528
Posts: 61
Joined: 2021-09-18 00:37
Been thanked: 2 times

Re: Bullseye: setting user environment correctly?

#4 Post by seeker5528 »

If you are talking bash and compatible shell variables, if I am reading things correctly, it looks like for system wide you would use /etc/profile.d different files for different purposes, can have conditions for doing different things for different users.

I use .xsessionrc for variables for the graphical environment, but whether that gets sourced or not may depend on the display manager you use and variables have to be exported if you want them to be set in the user environment just like any other script.

Code: Select all

export PIPEWIRE_RUNTIME_DIR=/run/user/1000
I'm using sddm for my display manager. It gets source there.
I have used .xprofile in the past, but seems less likely to work these days.

For the graphical environments, the xdg directories might be the thing to look into. Based on the files that are on my system it looks like scripts go in /etc/xdg and the .desktop files that run them go in /etc/xdg/autostart and it looks like at least for KDE and Gnome you can put a phase line in the .desktop file to indicate which phase of the startup the script should be ran in.

I would guess for the user specific case that ~/.config/autostart-scripts and `~/.config/autostart have this same relationship. I have not tested the hypothesis.

The ~/.config/autostart-scripts folder is new to me, I have copied files from /etc/xdg/autostart and modified them and in those cases the .desktop file in ~/.config/autostart got used instead of the one in /etc/xdg/autostart

zenlord
Posts: 81
Joined: 2009-06-17 15:23

Re: Bullseye: setting user environment correctly?

#5 Post by zenlord »

Thank you both for your comments! I agree with most of them. Indeed, /etc/profile is probably more appropriate than /etc/bashrc.

Using /etc/profile, just like /etc/bashrc, it is possible to add scripting, and e.g. for setting umask, it is necessary to at least check whether the user=='root' or not, because you can seriously mess up your system if root is creating files with 'umask 0007':

Code: Select all

if [ "$EUID" != "0" ]; then
  umask 0007
  USER=$(id -un)
  [[ -d "/var/cache/users/$USER" ]] || mkdir "/var/cache/users/$USER"
  chown "$USER" "/var/cache/users/$USER"
  XDG_CACHE_HOME=/var/cache/users/$USER
fi
However, this can get messy, e.g Debian-gdm is a system user launching the GDM session manager, and I believe I have to exclude that one as well. I liked the concept "ConditionGroup" used by Systemd, as that would allow me to only apply these settings to my normal users. So, still looking for the "2021 way of setting environment variables" ;)

zenlord
Posts: 81
Joined: 2009-06-17 15:23

Re: Bullseye: setting user environment correctly?

#6 Post by zenlord »

One smallish correction and one improvement to take away my concern of including no-root system users:

/etc/profile.d/99-ldap-users.sh:

Code: Select all

if ((`id -u`>=2000)); then
  umask 0007
  USER=$(id -un)
  if [[ !-d "/var/cache/users/$USER" ]]; then
    mkdir "/var/cache/users/$USER"
    chown "$USER" "/var/cache/users/$USER"
  fi
  XDG_CACHE_HOME=/var/cache/users/$USER
  export XDG_CACHE_HOME
fi

seeker5528
Posts: 61
Joined: 2021-09-18 00:37
Been thanked: 2 times

Re: Bullseye: setting user environment correctly?

#7 Post by seeker5528 »

I'm not all that familiar with systemd, but while searching for something else, systemd user came to my attention for things that should be ran when the user logs in and stopped when the user logs out of their last session. With complimentary folders in the home directory for services the user want to add themselves.

Not necessarily the best or most in depth links, but should give some ideas.

https://wiki.debian.org/systemd/Services
https://www.unixsysadmin.com/systemd-user-services/
https://nts.strzibny.name/systemd-user-services/
https://wiki.archlinux.org/title/Systemd/User
https://www.freedesktop.org/software/sy ... rvice.html

Post Reply