Where to set XDG_CACHE_HOME?

Michael Shaw mike at castlefortress.co
Wed Mar 11 16:30:44 GMT 2026


Hi Marek,

Duncan hit the nail on the head here regarding how modern Plasma and
systemd interact. The issue you're running into is purely a timing problem.

Because you're using GDM and a newer systemd-managed session, the
traditional shell scripts in /etc/profile.d or Plasma's env folders are
simply being executed too late in the login process. By the time your
script runs and exports those variables, systemd has already spun up the
early graphical components, and Mesa has already defaulted to creating
mesa_shader_cache in the NFS $HOME/.cache.

Since your logic is dynamic (checking if the user is on the domain and if
the local dir is writable), static systemd environment config files won't
work either.

The cleanest solution to beat Mesa to the punch is to use a systemd User
Environment Generator. These run the exact millisecond the user
authenticates—before GDM launches Wayland, Plasma, or Mesa.

You just need to adapt your current script slightly. Instead of using export,
systemd generators expect you to echo the KEY=value pairs directly to
standard output.

Create a file here:
/etc/systemd/user-environment-generators/60-local-xdg-cache.sh

And drop this in:
Bash

#!/bin/bash

CACHEDIR="/home/local/${USER}"
if [[ "${HOME}" =~ ^/home/domain/.* ]]; then
    echo "NSS_SDB_USE_CACHE=yes"

    if [ -w "${CACHEDIR}" ]; then
        echo "XDG_CACHE_HOME=${CACHEDIR}/.cache"
    fifi

Make sure to make it executable, or systemd will silently ignore it: sudo
chmod +x /etc/systemd/user-environment-generators/60-local-xdg-cache.sh

Because the systemd --user instance collects these outputs to build the
master environment block for the session, everything launched afterward
(including Mesa) will natively inherit your local XDG_CACHE_HOME right out
of the gate.

Give that a shot and let us know if it catches the cache creation in time!

Cheers,
Thanks,
*V/r*
Mike Shaw
314-*650*-3097
*mike*@castlefortress.co


On Sat, Feb 28, 2026 at 2:02 PM Marek Greško <marek.gresko at protonmail.com>
wrote:

> Hello,
>
> it is worth mentioning I use Fedora 43 and gdm login manager. I am
> thinking about mesa_shader_cache created in $HOME/.cache location whether
> it is created by gdm or by early phase of plasma startup?
>
> Thanks
>
> Marek
>
> sobota 28. februára 2026, 11:54, Marek Greško <marek.gresko at protonmail.com>
> napísal/a:
>
> Hello,
>
> I am trying to find out where to set XDG_CACHE_HOME in Fedora 43 for
> plasma correctly.
>
> I have setup an environment where users have home directories on a nfs
> share. I wanted to create local directory for XDG_CACHE_HOME. So I created
> a file /etc/profile.d/nss-cache.sh containing
>
> #!/bin/bash
>
> CACHEDIR="/home/local/${USER}"
>
> if [[ "${HOME}" =~ ^/home/domain/.*  ]]; then
>         export NSS_SDB_USE_CACHE=yes
>         if [ -w "${CACHEDIR}" ]; then
>                 export XDG_CACHE_HOME="${CACHEDIR}/.cache"
>         fi
> fi
>
> But it was not doing anything. Then I found out it works when I run some
> applications from the terminal, so I realized plasma does not use
> /etc/profile.d. Thereafter I tried to copy the file into the
> /etc/xdg/plasma-workspace/env/ directory. It mostly works. But I get the
> mesa_shader_cache directory created in the $HOME/.cache and also in the
> $XDG_CACHE_HOME. I think this is because the directory is created prior to
> runing the script in /etc/xdg/plasma-workspace/env, and then aft4er loading
> the file the directory is created again.
>
> Do you have any clue where should be the script run from to be started
> soon enough I do not have the $HOME/.cache/mesa_shader_cache created?
>
> Thanks
>
> Marek
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde/attachments/20260311/087bdc85/attachment.htm>


More information about the kde mailing list