Re: Where to set XDG_CACHE_HOME?

Michael Shaw <[email protected]> Wed, 11 Mar 2026 11:30:44 -0500
Newsgroups gmane.comp.kde.general
Message-ID <CAP-xWQ9=AZ6j8YTrXDPaC7E=_7GiNdDgCOFZ9dnL6b_Ypn-DJw@mail.gmail.com>
--0000000000000c231e064cc229c1
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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=E2=80=94before GDM launches Wayland, Plasma, or Mesa.

You just need to adapt your current script slightly. Instead of using expor=
t,
systemd generators expect you to echo the KEY=3Dvalue 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=3D"/home/local/${USER}"
if [[ "${HOME}" =3D~ ^/home/domain/.* ]]; then
    echo "NSS_SDB_USE_CACHE=3Dyes"

    if [ -w "${CACHEDIR}" ]; then
        echo "XDG_CACHE_HOME=3D${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=E2=80=AFPM Marek Gre=C5=A1ko <marek.gresko@pro=
tonmail.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=C3=A1ra 2026, 11:54, Marek Gre=C5=A1ko <marek.gresko@pro=
tonmail.com>
> nap=C3=ADsal/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 create=
d
> a file /etc/profile.d/nss-cache.sh containing
>
> #!/bin/bash
>
> CACHEDIR=3D"/home/local/${USER}"
>
> if [[ "${HOME}" =3D~ ^/home/domain/.*  ]]; then
>         export NSS_SDB_USE_CACHE=3Dyes
>         if [ -w "${CACHEDIR}" ]; then
>                 export XDG_CACHE_HOME=3D"${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 t=
o
> runing the script in /etc/xdg/plasma-workspace/env, and then aft4er loadi=
ng
> 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
>
>
>

--0000000000000c231e064cc229c1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div><p>Hi Marek,</p><p>Duncan hit the na=
il on the head here regarding how modern Plasma and systemd interact. The i=
ssue you&#39;re running into is purely a timing problem.</p><p>Because you&=
#39;re using GDM and a newer systemd-managed session, the traditional shell=
 scripts in <code>/etc/profile.d</code> or Plasma&#39;s <code>env</code> fo=
lders 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 t=
he early graphical components, and Mesa has already defaulted to creating <=
code>mesa_shader_cache</code> in the NFS <code>$HOME/.cache</code>.</p><p>S=
ince your logic is dynamic (checking if the user is on the domain and if th=
e local dir is writable), static systemd environment config files won&#39;t=
 work either.</p><p>The cleanest solution to beat Mesa to the punch is to u=
se a systemd User Environment Generator. These run the exact millisecond th=
e user authenticates=E2=80=94before GDM launches Wayland, Plasma, or Mesa.<=
/p><p>You just need to adapt your current script slightly. Instead of using=
 <code>export</code>, systemd generators expect you to <code>echo</code> th=
e KEY=3Dvalue pairs directly to standard output.</p><p>Create a file here:
<code>/etc/systemd/user-environment-generators/60-local-xdg-cache.sh</code>=
</p><p>And drop this in:</p><span class=3D"gmail-"><span class=3D"gmail-ng-=
tns-c3552361503-101 gmail-ng-star-inserted"><div class=3D"gmail-code-block =
gmail-ng-tns-c3552361503-101 gmail-ng-animate-disabled gmail-ng-trigger gma=
il-ng-trigger-codeBlockRevealAnimation"><div class=3D"gmail-code-block-deco=
ration gmail-header-formatted gmail-gds-title-s gmail-ng-tns-c3552361503-10=
1 gmail-ng-star-inserted"><span class=3D"gmail-ng-tns-c3552361503-101">Bash=
</span><div class=3D"gmail-buttons gmail-ng-tns-c3552361503-101 gmail-ng-st=
ar-inserted"><button aria-label=3D"Copy code" class=3D"gmail-mdc-icon-butto=
n gmail-mat-mdc-icon-button gmail-mat-mdc-button-base gmail-mat-mdc-tooltip=
-trigger gmail-copy-button gmail-ng-tns-c3552361503-101 gmail-mat-unthemed =
gmail-ng-star-inserted"><span class=3D"gmail-mat-mdc-button-persistent-ripp=
le gmail-mdc-icon-button__ripple"></span><span role=3D"img" class=3D"gmail-=
mat-icon gmail-notranslate gmail-gds-icon-s gmail-google-symbols gmail-mat-=
ligature-font gmail-mat-icon-no-color" aria-hidden=3D"true"></span><span cl=
ass=3D"gmail-mat-focus-indicator"></span><span class=3D"gmail-mat-mdc-butto=
n-touch-target"></span></button></div></div><div class=3D"gmail-formatted-c=
ode-block-internal-container gmail-ng-tns-c3552361503-101"><div class=3D"gm=
ail-animated-opacity gmail-ng-tns-c3552361503-101"><pre class=3D"gmail-ng-t=
ns-c3552361503-101"><code role=3D"text" class=3D"gmail-code-container gmail=
-formatted gmail-ng-tns-c3552361503-101"><span class=3D"gmail-hljs-meta">#!=
/bin/bash</span>

CACHEDIR=3D<span class=3D"gmail-hljs-string">&quot;/home/local/<span class=
=3D"gmail-hljs-variable">${USER}</span>&quot;</span>

<span class=3D"gmail-hljs-keyword">if</span> [[ <span class=3D"gmail-hljs-s=
tring">&quot;<span class=3D"gmail-hljs-variable">${HOME}</span>&quot;</span=
> =3D~ ^/home/domain/.* ]]; <span class=3D"gmail-hljs-keyword">then</span>
    <span class=3D"gmail-hljs-built_in">echo</span> <span class=3D"gmail-hl=
js-string">&quot;NSS_SDB_USE_CACHE=3Dyes&quot;</span>
   =20
    <span class=3D"gmail-hljs-keyword">if</span> [ -w <span class=3D"gmail-=
hljs-string">&quot;<span class=3D"gmail-hljs-variable">${CACHEDIR}</span>&q=
uot;</span> ]; <span class=3D"gmail-hljs-keyword">then</span>
        <span class=3D"gmail-hljs-built_in">echo</span> <span class=3D"gmai=
l-hljs-string">&quot;XDG_CACHE_HOME=3D<span class=3D"gmail-hljs-variable">$=
{CACHEDIR}</span>/.cache&quot;</span>
    <span class=3D"gmail-hljs-keyword">fi</span>
<span class=3D"gmail-hljs-keyword">fi</span>
</code></pre></div></div></div></span></span><p>Make sure to make it execut=
able, or systemd will silently ignore it:
<code>sudo chmod +x /etc/systemd/user-environment-generators/60-local-xdg-c=
ache.sh</code></p><p>Because the <code>systemd --user</code> instance colle=
cts these outputs to build the master environment block for the session, ev=
erything launched afterward (including Mesa) will natively inherit your loc=
al XDG_CACHE_HOME right out of the gate.</p><p>Give that a shot and let us =
know if it catches the cache creation in time!</p><p>Cheers,</p></div><div>=
<div dir=3D"ltr" class=3D"gmail_signature"><div dir=3D"ltr"><div><div><span=
 style=3D"background-color:rgb(255,255,255)"><font color=3D"#000000">Thanks=
,=C2=A0</font></span></div><div><span style=3D"background-color:rgb(255,255=
,255)"><font color=3D"#000000"><b>V/r</b></font></span></div><div><span sty=
le=3D"background-color:rgb(255,255,255)"><font color=3D"#000000">Mike Shaw=
=C2=A0</font></span></div><div><span style=3D"background-color:rgb(255,255,=
255)"><font color=3D"#000000">314-<b>650</b>-3097</font></span></div><div><=
span style=3D"background-color:rgb(255,255,255)"><font color=3D"#000000"><b=
>mike</b>@<a href=3D"http://castlefortress.co" target=3D"_blank">castlefort=
ress.co</a></font></span></div></div></div></div></div><br></div><br><img w=
idth=3D"0" height=3D"0" class=3D"mailtrack-img" alt=3D"" style=3D"display:f=
lex" src=3D"https://mailtrack.io/trace/mail/5ca1a3b0bc7192c9c15efbb6e0008ab=
3d0c3b23c.png?u=3D942777"><div class=3D"gmail_quote gmail_quote_container">=
<div dir=3D"ltr" class=3D"gmail_attr">On Sat, Feb 28, 2026 at 2:02=E2=80=AF=
PM Marek Gre=C5=A1ko &lt;<a href=3D"mailto:[email protected]">mar=
[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail=
_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204=
,204);padding-left:1ex"><div style=3D"font-family:Arial,sans-serif;font-siz=
e:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)">Hello,</div><div=
 style=3D"font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);back=
ground-color:rgb(255,255,255)"><br></div><div style=3D"font-family:Arial,sa=
ns-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)"=
>it is worth mentioning I use Fedora 43 and gdm login manager. I am thinkin=
g about mesa_shader_cache created in $HOME/.cache location whether it is cr=
eated by gdm or by early phase of plasma startup?</div><div style=3D"font-f=
amily:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb=
(255,255,255)"><br></div><div style=3D"font-family:Arial,sans-serif;font-si=
ze:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)">Thanks</div><di=
v style=3D"font-family:Arial,sans-serif;font-size:14px;color:rgb(0,0,0);bac=
kground-color:rgb(255,255,255)"><br></div><div style=3D"font-family:Arial,s=
ans-serif;font-size:14px;color:rgb(0,0,0);background-color:rgb(255,255,255)=
">Marek</div><div style=3D"font-family:Arial,sans-serif;font-size:14px;colo=
r:rgb(0,0,0);background-color:rgb(255,255,255)"><br></div><div>
        sobota 28. febru=C3=A1ra 2026, 11:54, Marek Gre=C5=A1ko &lt;<a href=
=3D"mailto:[email protected]" target=3D"_blank">marek.gresko@prot=
onmail.com</a>&gt; nap=C3=ADsal/a:<br>
        <blockquote type=3D"cite">
            <div style=3D"font-family:Arial,sans-serif;font-size:14px"></di=
v><span style=3D"background-color:rgb(255,255,255)">Hello,</span><div style=
=3D"background-color:rgb(255,255,255)"><br></div><div style=3D"background-c=
olor:rgb(255,255,255)">I am trying to find out where to set XDG_CACHE_HOME =
in Fedora 43 for plasma correctly.</div><div style=3D"background-color:rgb(=
255,255,255)"><br></div><div style=3D"background-color:rgb(255,255,255)">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=
=C2=A0<span>/etc/profile.d/nss-cache.sh</span>=C2=A0containing</div><div st=
yle=3D"background-color:rgb(255,255,255)"><br></div><div style=3D"backgroun=
d-color:rgb(255,255,255)"><span>#!/bin/bash</span><div><br></div><div><span=
>CACHEDIR=3D&quot;/home/local/${USER}&quot;</span></div><div><br></div><div=
><span>if [[ &quot;${HOME}&quot; =3D~ ^/home/domain/.* =C2=A0]]; then</span=
></div><div><span>=C2=A0 =C2=A0 =C2=A0 =C2=A0 export NSS_SDB_USE_CACHE=3Dye=
s</span></div><div><span>=C2=A0 =C2=A0 =C2=A0 =C2=A0 if [ -w &quot;${CACHED=
IR}&quot; ]; then</span></div><div><span>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 export XDG_CACHE_HOME=3D&quot;${CACHEDIR}/.cache&quot=
;</span></div><div><span>=C2=A0 =C2=A0 =C2=A0 =C2=A0 fi</span></div><div><s=
pan>fi</span></div><span><br></span></div><div style=3D"background-color:rg=
b(255,255,255)"><span>But it was not doing anything. Then I found out it wo=
rks when I run some applications from the terminal, so I realized plasma do=
es not use /etc/profile.d. Thereafter I tried to copy the file into the /et=
c/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_CAC=
HE_HOME. I think this is because the directory is created prior to runing t=
he script in /etc/xdg/plasma-workspace/env, and then aft4er loading the fil=
e the directory is created again.</span></div><div style=3D"background-colo=
r:rgb(255,255,255)"><span><br></span></div><div style=3D"background-color:r=
gb(255,255,255)"><span>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_c=
ache created?</span></div><div style=3D"background-color:rgb(255,255,255)">=
<span><br></span></div><div style=3D"background-color:rgb(255,255,255)"><sp=
an>Thanks</span></div><div style=3D"background-color:rgb(255,255,255)"><spa=
n><br></span></div><span style=3D"background-color:rgb(255,255,255)"><span>=
Marek</span></span><div style=3D"font-family:Arial,sans-serif;font-size:14p=
x"><div></div>
</div>

        </blockquote><br>
    </div></blockquote></div></div>

--0000000000000c231e064cc229c1--