Make Snaps ignore /etc/environment?

Ubuntu Version

Ubuntu 26.04 LTS

Desktop Environment (if applicable)

KDE Plasma

Problem Description

Im wondering if there is a way to tell snaps to just ignore variables in /etc/environment.

I have a few variables forced there I.E

KWIN_DISABLE_VULKAN=1
KWIN_DRM_DEVICES=“/dev/dri/by-path/pci-0000:00:02.0-card:/dev/dri/by-path/pci-0000:02:00.0-card”
GSK_RENDERER=opengl
__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json
VK_DRIVER_FILES=/usr/share/vulkan/icd.d/intel_icd.json
__GLX_VENDOR_LIBRARY_NAME=mesa
KWIN_USE_OVERLAYS=1

These are there to prevent applications (expecially GTK ones) from constantly waking my laptops dGPU for no reason. The problem is that this causes for instance the security center and firmware snaps to simply not launch. Ive been going through the snap documents and there doesnt seem to be any way to actually fix this but to simply not use snaps that cant handle these variables.

The snap documentation is kind of hard to go through and seems to assume youre making a snap not using one (kinda stange). While i didnt think to save which pages do this some of the documentation pages are dead links which makes it even more difficult to figure out if this is possible.

Any snap experts able to chime in on this? can the user even tell a snap to ignore variables set outside the snap?

Snaps take variables from /etc/environment, but those driver file paths do not exist inside the snap sandbox.

Just move those lines to ~/.config/plasma-workspace/env/gpu.sh -so they only work for Plasma and leave snaps alone

will gtk and other applications still read these then? The issue isnt necessarily plasma itself but GTK applications in particular (and Gnome when i was using it) absolutely refuse to stop waking the dGPU without these set.

Yeap, any app started in your Plasma session inherits from that env folder, including GTK apps

The reason snaps died was strictly the hardcoded /usr/share paths. If you want GTK and other appps to stay on your integrated Intel GPU without breaking snaps, use DRI_PRIME=0 instead of pointing to static files. It keeps your dGPU asleep and snaps can still find their own drivers

DRI_PRIME doesnt work with GTK apps or Gnome to stop this (they select the right gpu most of the time with it), GTK apps will parse all the GPUs every single time on application launch even waking the GPU with DRI_PRIME and Gnome has a long standing issue of running a gnome-shell on the dGPU that keeps it awake when it shouldnt.

Ill give that a try later and see if that works to stop them doing that in a plasma session

Fingers crossed! :wink:

Let us know how it goes…

so unfortunately the snaps still pick it up and fail to launch :expressionless_face:

Ok… my bad - snapd reads /etc/environment directly, PAM not invited to the party

The killers are:

__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json

VK_DRIVER_FILES=/usr/share/vulkan/icd.d/intel_icd.json

Inside the snap, /usr/share is the snap’s own - not yours. So it looks for your Intel ICD in a place it will never find it.

Remove those two from /etc/environment, put them in ~/.config/plasma-workspace/env/gpu.sh instead.

i did do that, and unfortunately it seems like the snaps still pickup that env variable even if its not in /etc/environment but in the session env too

I know what the cause is, but i havent found a way to tell the snaps to ignore the env variables. Flatpaks just ignore it so they have no problems.

I can specifically override the variables per snap in the .desktop files to ones that the snap expects. That is a fragile way to handle it as if anything with snap changes that changes those paths in any way im back to square one. Theres also the fact that doesnt work from terminal unless i export those each time or create an alias

You should file a wishlist bug at:

2 Likes

is that to say currently snaps just dont have a way to handle this at the moment then?

EDIT: Ill file a bug soon then if thats the case, itd be nice to be able to tell your snaps to ignore env variables if needed

1 Like

Yes and I think it is quite a corner case, I would expect most users to expect the exact opposite (which is the current default as you noticed already) i.e. that all user environment is handed to the snap by default … snapd would likely have to grow some system setting to allow you to override this globally…

https://snapcraft.io/docs/reference/administration/system-options/

1 Like

it is somewhat, but being relatively new to snaps and having used Flatpak for a long time Im use to Flatpak which this is the default behavior and you can override them per flatpak or for flatpaks globally.

Seems to me like having the snaps pickup env variables on default (especially ones they cant handle and will break them) is a good way to have them break on users that need to deal with things that way that arent snap related.

Ill look at making a wishlist bug but in the mean time I think id rather just limit my snap usage. They keep ending up being more of a nuisance than a benefit when I use them unfortunately and that means i just cant use security-center as i havent found a deb for it.

Right, but you can copy its .desktop file into ~/.local/share/applications and unset the env var in there … (as you also found out above already)

Unfortunately then i have to maintain the paths that it expects through any snap changes that might break that which requires me entering the snap sandbox and figuring out what paths the snap expects when it does inevitably break. :sweat_smile:

doesnt feel worth the effort :melting_face: and idk how either of these applications are effected beyond that I.E if they run in the background but just end up crashing instead of doing their job.

While this is true, the .desktop files pretty much never change …
I mean, you are only adding another env entry there and the freedesktop spec makes sure your local .desktop is always preferred

Well, the flatpak documentation does not agree with it :slight_smile: Notably

Environment variables are generally passed on to the sandboxed application, with certain exceptions

Exceptions being __EGL_VENDOR_LIBRARY_FILENAMES and VK_DRIVER_FILES (from the variables shown earlier).

Maybe snap could adopt the same approach and block (by default) some variables known to cause problems.

That would have to be discussed in the bug (or would have to be brought to the architects by the snapd devs for a proper design after they processed the bug… a bug is definitely the necessary entry point here to start something in that direction)

1 Like

variables are passed if you explicitly launch a flatpak with the variables, but not one of my flatpaks picks up anything i have in /etc/environment

I dont have a single flatpak that has ever picked up variables that i didnt explicitly pass to it. Its possible i have never used the right combo of variables for this to happen i will admit though but its simply never been an issue for me with flatpaks.

EDIT: Figured out why, /etc is a reserved path and unless you explicitly add the host-etc (or full host access) sandbox permission it isnt used in the sandbox and even then it isnt in the sandbox /etc but in a separate sub folder /run/host/etc

that seems like a very good idea to me, have snap exclude/ignore variables that are possible sources of breakage would make this a non issue