According to SystemD docs (emphasis added):
Processes started by the service manager are executed with an environment variable block assembled from multiple sources. Processes started by the system service manager generally do not inherit environment variables set for the service manager itself (but this may be altered via PassEnvironment=
), but processes started by the user service manager instances generally do inherit all environment variables set for the service manager itself.
For each invoked process the list of environment variables set is compiled from the following sources:
Variables globally configured for the service manager, using the DefaultEnvironment=
setting in systemd-system.conf(5)
, [...SNIP...]
Variables defined by the service manager itself (see the list below).
[...SNIP...]
The list of variables defined by the service manager only includes the following:
$PATH
$LANG
$USER
, $LOGNAME
, $HOME
, $SHELL
$INVOCATION_ID
$XDG_RUNTIME_DIR
$RUNTIME_DIRECTORY
, $STATE_DIRECTORY
, $CACHE_DIRECTORY
, $LOGS_DIRECTORY
, $CONFIGURATION_DIRECTORY
$CREDENTIALS_DIRECTORY
$MAINPID
$MANAGERPID
$LISTEN_FDS
, $LISTEN_PID
, $LISTEN_FDNAMES
$NOTIFY_SOCKET
$WATCHDOG_PID
, $WATCHDOG_USEC
$SYSTEMD_EXEC_PID
$TERM
$LOG_NAMESPACE
$JOURNAL_STREAM
$SERVICE_RESULT
$EXIT_CODE
, $EXIT_STATUS
$MONITOR_SERVICE_RESULT
, $MONITOR_EXIT_CODE
, $MONITOR_EXIT_STATUS
, $MONITOR_INVOCATION_ID
, $MONITOR_UNIT
$PIDFILE
$REMOTE_ADDR
, $REMOTE_PORT
$TRIGGER_UNIT
, $TRIGGER_PATH
, $TRIGGER_TIMER_REALTIME_USEC
, $TRIGGER_TIMER_MONOTONIC_USEC
$MEMORY_PRESSURE_WATCH
, $MEMORY_PRESSURE_WRITE
$FDSTORE
Notably, this list does not include XDG_SESSION_TYPE
, which it appears that the Gnome Shell user unit is trying to use in ConditionEnvironment=XDG_SESSION_TYPE=wayland
.
You will probably need to import this variable into the SystemD session. The systemctl --user import-environment
command should be able to import environment variables into the user service manager's environment. You will need to run this command in a place where the environment variable $XDG_SESSION_TYPE
is set. Usually it should be set at some point by the display or session manager that launches your desktop environment, or else inside the initialization of that desktop environment itself (for example: Sway does this on Arch Linux).
In your specific case for Gnome, I think this is gnome-session
which used to be able to execute a login shell (e.g. running ~/.profile
, ~/.bash_profile
, etc..) However, this may have changed given the discussion of phasing out the login shell functionality.
EDIT: Digging further into this^1, it seems that this previous login shell functionality has been reimplemented instead using SystemD's support for environment.d
drop-in files, as well as systemd.environment-generator
s. There is also a backwards-compatibility feature wherein the SystemD package includes a symlink to the older /etc/environment
file, named: /usr/lib/environment.d/99-environment.conf
. This /etc/environment
file is still apparently owned and used by the core/pam
package on ArchLinux, for example. In theory, the newer environment.d
and generators are probably the best place for any SystemD-based distro, such as Ubuntu, to be using for this type of thing. However, in practice, it may not be well-known or utilized enough by current distros and Wayland graphical session packages.
In any case, you'll need to find a way to set the XDG_SESSION_TYPE
variable appropriately so it can be used by the SystemD user service manager. One method would be to execute the following in an environment where XDG_SESSION_TYPE
has been set to wayland
by the session login process:
systemctl --user import-environment XDG_SESSION_TYPE XDG_CURRENT_DESKTOP
To test it manually from the tty console, you might be able to manually set these and run:
export XDG_SESSION_TYPE=wayland
export XDG_CURRENT_DESKTOP=ubuntu:GNOME
systemctl --user import-environment XDG_SESSION_TYPE XDG_CURRENT_DESKTOP
systemctl --user start [email protected]
# You can watch logs on another tty with:
journalctl -xen100 --user-unit -f
Optionally, you can switch to another tty (Ctrl + Alt + F2) and start the journalctl
command first to get the log following started. Then, switch back (Ctrl + Alt + F1) and run the rest of the export
and systemctl
commands to import environment vars and trigger the user service unit. Finally, switch back (Ctrl + Alt + F2) to check the resulting logs. Note: The initial tty
number may be different depending on the version of Ubuntu you're running (e.g. it used to be F7
for graphical sessions, but I think that may have changed back to F1
).