6

I'm using systemctl --user for a lot of user services on my Linux desktop.

One of the things I'm doing (per "Starting A DBus Session Application from systemd User Mode") as a hack to get my environment variables from my session is that I'm running a manual script on startup of the graphical session which calls systemctl --user import-environment. I then have a dummy service which I start via systemctl --user start environment.service. All of my other services which are enabled depend on environment.service.

I figure this would probably make a better target than a service. Is there a way to create a target which must be explicitly started via systemctl --user start user-login-graphical.target?

JdeBP
  • 68,745
Naftuli Kay
  • 39,676
  • Wouldn't it be simpler to just fix your session so you didn't have to employ bizarre hacks? – jasonwryan Dec 21 '17 at 19:58
  • There's nothing wrong with my session. systemd by default strips out environment variables and so the only way for me to get them into the environment is via the import-environment command. – Naftuli Kay Dec 21 '17 at 20:01
  • 1
    Err, no. Not at all. – jasonwryan Dec 21 '17 at 20:02
  • 2
    Feel free to disagree with the facts: variables from my graphical session are not imported into systemd userspace units. If I use show-environment, I can see only four or five environment variables. After import, it's closer to 20. I want to be able to launch things in my desktop session from systemd. – Naftuli Kay Dec 21 '17 at 20:54
  • Like I said above, fix your broken session. It's not a systemd issue. – jasonwryan Dec 21 '17 at 21:00
  • 1
    I don't see this as a bug. Why should the systemd user session inherit environment variables from the graphical session? The systemd user session is not dependent on any graphical session. – Naftuli Kay Dec 21 '17 at 21:03

1 Answers1

8

I was able to accomplish this via the following unit file:

[Unit]
Description=User Graphical Login
Requires=default.target
After=default.target

I will then manually start the target as it has no Install section and will not get started on its own.

systemctl --user start user-graphical-login.target
Naftuli Kay
  • 39,676