Okay, I'm sure a lot of people already know about this one, but it's new to me. I just found out you can do one of these in your systemd service itself:
Environment=SOME_SILLY_NAME=%i
And then reference that specific variable from inside of that environment, instead of using whatever variable was already there anyway, that usually works even though it's not actually made for that.
The problem I've been running into is that X11 cares about $DISPLAY, and so usually if you're gonna reference %i from a script from within an X11 environment, you would use that and it would work; but then if you're on Wayland, that doesn't mean anything to Wayland itself, because it calls it $WAYLAND_DISPLAY instead; WHICH MEANS that if you're on a Wayland compositor to start with, but you're also running XWayland, then you have both variables set automatically.
I'm on Niri with xwayland-satellite, and so I have both (I never had $DISPLAY in Niri until after I installed xwayland-satellite). This is a huge problem because neither of those variables actually have anything to do with the systemd instance by design, and I can't just make one of them go away (without giving myself more problems). There is no variable that's ever set by default, that is specifically put there to refer to the exact same thing as %i does in the unit itself, that I know of.
Now I can just do this instead, and never have to worry about my stuff getting mixed up with my other stuff. 😀
#systemd #BashScript #Linux