1

The goal

I'm running Arch Linux. I want to store all config/data/cache/state files in subdirectories of ~/local, like so:

~
├── downloads
├── documents
└── local
    ├── data
    ├── state
    ├── config
    └── cache

The attempt

In order to do this, I've set environment variables as follows:

# set up XDG directories
export XDG_DATA_HOME=$HOME/local/data
export XDG_CONFIG_HOME=$HOME/local/config
export XDG_STATE_HOME=$HOME/local/state
export XDG_CACHE_HOME=$HOME/local/cache

# enable compliance
export ZDOTDIR=$XDG_CONFIG_HOME/zsh
export HISTFILE=$XDG_STATE_HOME/zsh/history

This is currently placed in /etc/zsh/zshenv (as I use zsh), however, I've also tried placing this in ~/local/config/zsh/.zshenv and only setting $ZDOTDIR globally.

I can see the environment variables set in the shell:

% echo $XDG_CONFIG_HOME                                        
# /home/myuser/local/config

% echo $ZDOTDIR                                                
# /home/myuser/local/config/zsh

The problem

Many, but not all, programs that I run just don't seem to respect the variables I've set.

For instance, Hyprland ignores $XDG_CONFIG_HOME and creates a default configuration file at ~/.config/hypr/hyprland.conf, despite ~/local/config/hypr/hyprland.conf existing. It then reads the file it created and complains about my configuration not having been modified. The same applies to my terminal emulator, kitty, which explicitly implements XDG Base Directory.

Other programs however, like tealdeer and zsh itself, respect the variables and put files in the directories I specified.

Why is software that supposedly supports the standard not changing behaviour based on the environment variables I set?

5
  • What is the question here? Please ask a proper question ending with a ? character.
    – Destroy666
    Commented Jul 24, 2023 at 15:24
  • @Destroy666 Why is software that supposedly supports the standard not changing behaviour based on the environment variables I set?
    – theo
    Commented Jul 24, 2023 at 15:29
  • 1
    How did you verify that the variables were placed in the software's environment? Commented Jul 24, 2023 at 15:52
  • 1
    "Why does X software decide to not do something?" is opinion-based, which is not allowed here and might result in a closed question.
    – Destroy666
    Commented Jul 24, 2023 at 16:01
  • 2
    @u1686_grawity This ended up being the problem. Thanks for pointing me to it, and not just dismissing my question about software behaviour on a forum about software behaviour :p
    – theo
    Commented Jul 24, 2023 at 17:04

1 Answer 1

2

I solved the problem with all the helpful advice from the comments. Huzzah.

The issue was that because I defined the environment variables in /etc/zsh/zshenv, they would only be set in Zsh shells, and not during a graphical login, done through a display manager. Testing this theory by logging into a different TTY and starting Hyprland manually from the command line proved successful.

To solve it, I followed the advice in the Arch Wiki and defined variables in /etc/security/pam_env.conf:

# ...

XDG_CONFIG_HOME     DEFAULT=@{HOME}/local/config
XDG_STATE_HOME      DEFAULT=@{HOME}/local/state
XDG_DATA_HOME       DEFAULT=@{HOME}/local/data
XDG_CACHE_HOME      DEFAULT=@{HOME}/local/cache
ZDOTDIR             DEFAULT=${XDG_CONFIG_HOME}/zsh

Hence, these variables will now be loaded no matter the context and Hyprland (and by extension some programs run directly from it) will respect the preferences I set.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .