You are not logged in.

#1 2024-03-16 13:38:30

fueradeservicio
Member
Registered: 2024-02-13
Posts: 7

[SOLVED] Best place to put XDG environment variables

Hi,

I'd like to build a system that respects XDG as much as it can. I've been reading the XDG wiki in https://wiki.archlinux.org/title/XDG_Base_Directory . So, I'd like to set these variables for all the current and future users in my system:

export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_RUNTIME_DIR="/run/user/$UID"
#export XAUTHORITY="$XDG_RUNTIME_DIR/Xauthority"

What I didn't find as a fact is where should be the best place to write them? I think /etc/profile.d/xdg.sh could be a good place, but I can see most of people just define them in their .bashrc or .zshenv files, and I can't understand why.

Also, I have had to comment the last file of the vars because I was unable to use gdm, nor lightdm or sddm (I was expecting to prevent the .Xauthority file to be on the user's home folder), but I think it's an issue for another post (I would be glad if someone could let me know some information about why that variable is so anoying ;-) )


Thanks a lor for your help

regards

Last edited by fueradeservicio (2024-03-17 13:09:51)

Offline

#2 2024-03-16 20:30:12

espresso
Member
Registered: 2023-05-15
Posts: 6

Re: [SOLVED] Best place to put XDG environment variables

The spec seems to leave 'where to set the variables' up to the distribution/administration.  As to why some users set them only in shell environments or whatever, some login scripts are sourced by display managers or DEs, or maybe they have some/no reason..

Perhaps some more familiar with these can offer better advice, but here goes.

https://wiki.archlinux.org/title/XDG_user_directories , which may already be present as a dependency of DE and applications, facilitates setting directory defaults (/etc/xdg/user-dirs.defaults).


XDG_RUNTIME_DIR should already default to /run/user/$UID.

Moving .Xauthority: There was a previous topic that may be informative. https://bbs.archlinux.org/viewtopic.php?id=229407

Last edited by espresso (2024-03-19 10:02:22)

Offline

#3 2024-03-16 20:54:11

fueradeservicio
Member
Registered: 2024-02-13
Posts: 7

Re: [SOLVED] Best place to put XDG environment variables

Hi, thanks a lot for your response.

I hadn't read the "Environment_variables" wiki. It's very interesting.

When you say "XDG_RUNTIME_DIR should already default to /run/user/$UID" you are saying that I don't need to export that env variable, as by default it's already done, right? If that's true, "who/what" is setting that variable?

Regarding Xauthority and SDDM, I use GDM, and it stops working fine when I set that env variable to $XDG_RUNTIME_DIR/Xauthority. I'd like to know why, but I would need some advices in order to try to "debug" why it doesn't work as expected. What kind of files to look for and read... Actually, I would use any display manager that respects the xdm standard, but I have tried SDDM, gdm and lightdm, and for some reasons they weren't able to open my user's sessions. If somebody could let me know what filex to inspect, I could try to do some research.


Thanks a lot for your response, and thanks in advance for further help from anybody smile

Regards

Last edited by fueradeservicio (2024-03-16 20:54:41)

Offline

#4 2024-03-16 21:17:45

fueradeservicio
Member
Registered: 2024-02-13
Posts: 7

Re: [SOLVED] Best place to put XDG environment variables

espresso wrote:

The spec seems to leave 'where to set the variables' up to the distribution/administration.  As to why some users set them only in shell environments or whatever, maybe they are less bothered by the implications, or have their own reasons or none in particular.

Perhaps some more familiar with these can offer better advice, but here goes.

https://wiki.archlinux.org/title/XDG_user_directories , which may already be present as a dependency of DE and applications, facilitates setting directory defaults (/etc/xdg/user-dirs.defaults).

Alternatively, https://wiki.archlinux.org/title/Enviro … ng_pam_env allows defaults and use of HOME and SHELL; although I'm not aware of it supporting drop-in configuration files like the systemd method, https://wiki.archlinux.org/title/Enviro … s#Per_user

XDG_RUNTIME_DIR should already default to /run/user/$UID.

Moving .Xauthority: There was a previous topic that may be informative. https://bbs.archlinux.org/viewtopic.php?id=229407

I was thinking that, as the "Environment_variables" link you provided states, it should be a better idea to define the XDG variables in the /etc/environment file and not in /etc/profile.d, right? And, in case that any user need to set a different value for these vars, it wouldn't be any problem if she/he defines them in their personal config files.

I'm now starting to realize that it's not so easy to use the correct places to build a XDG system...

Offline

#5 2024-03-16 23:52:57

espresso
Member
Registered: 2023-05-15
Posts: 6

Re: [SOLVED] Best place to put XDG environment variables

fueradeservicio wrote:

When you say "XDG_RUNTIME_DIR should already default to /run/user/$UID" you are saying that I don't need to export that env variable, as by default it's already done, right? If that's true, "who/what" is setting that variable?

Yes, and XDG_RUNTIME_DIR is set by default through pam_systemd. https://wiki.archlinux.org/title/XDG_Base_Directory

fueradeservicio wrote:

I was thinking that, as the "Environment_variables" link you provided states, it should be a better idea to define the XDG variables in the /etc/environment file and not in /etc/profile.d, right?

/etc/profile.d is just for login shells; https://wiki.archlinux.org/title/Enviro … tion_files

That leaves at least the other methods mentioned earlier.

And, in case that any user need to set a different value for these vars, it wouldn't be any problem if she/he defines them in their personal config files.

Generally no problem, as that is intended possible scenario: ~/.config/user-dirs.dirs  or  systemd user environment.

Last edited by espresso (2024-03-19 10:03:18)

Offline

#6 2024-03-17 11:13:53

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,744
Website

Re: [SOLVED] Best place to put XDG environment variables

There is no need to set those variables explicitly, the values listed are the assumed defaults.

Offline

#7 2024-03-17 11:35:22

fueradeservicio
Member
Registered: 2024-02-13
Posts: 7

Re: [SOLVED] Best place to put XDG environment variables

Thanks to both for your answers. I think my doubts are already solved smile

Should I solve this post anywhere? I can't see any button to close the trhead


Regards!

Offline

#8 2024-03-17 13:02:59

espresso
Member
Registered: 2023-05-15
Posts: 6

Re: [SOLVED] Best place to put XDG environment variables

You can mark threads '[SOLVED]' by editing your initial post subject that way.
Regards!

Offline

#9 2024-03-23 13:18:49

webcapcha
Member
Registered: 2019-02-14
Posts: 137

Re: [SOLVED] Best place to put XDG environment variables

and what is the solution?


Ukrainian

Offline

#10 2024-03-23 13:21:23

fueradeservicio
Member
Registered: 2024-02-13
Posts: 7

Re: [SOLVED] Best place to put XDG environment variables

Actually, the solution is that everything dependns on what you are trying to achieve...
What dop you need?

Offline

#11 2024-03-23 15:27:22

webcapcha
Member
Registered: 2019-02-14
Posts: 137

Re: [SOLVED] Best place to put XDG environment variables

Actually, what does the title say.


Ukrainian

Offline

#12 2024-03-23 17:19:43

fueradeservicio
Member
Registered: 2024-02-13
Posts: 7

Re: [SOLVED] Best place to put XDG environment variables

You need to be clear about which parts of the system those variables you want to define should affect. For example, if only at the shell command level, or at the Xwindows level, etc... The closest thing to enabling those variables globally and affecting practically all system applications seems to be using PAM or systemd files, or at least that's what I have understood. However, since it's not as simple as writing all the variables in a single file, I have decided to write each group of variables in their respective places (zsh, xorg, etc...).

Offline

Board footer

Powered by FluxBB