3 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
4 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1-or-later
8 Copyright © 2016 Red Hat, Inc.
10 <refentry id="environment.d" conditional='ENABLE_ENVIRONMENT_D'
11 xmlns:xi="http://www.w3.org/2001/XInclude">
14 <title>environment.d</title>
15 <productname>systemd</productname>
19 <refentrytitle>environment.d</refentrytitle>
20 <manvolnum>5</manvolnum>
24 <refname>environment.d</refname>
25 <refpurpose>Definition of user service environment</refpurpose>
30 <member><filename>~/.config/environment.d/*.conf</filename></member>
31 <member><filename>/etc/environment.d/*.conf</filename></member>
32 <member><filename>/run/environment.d/*.conf</filename></member>
33 <member><filename>/usr/local/lib/environment.d/*.conf</filename></member>
34 <member><filename>/usr/lib/environment.d/*.conf</filename></member>
35 <member><filename>/etc/environment</filename></member>
40 <title>Description</title>
42 <para>Configuration files in the <filename>environment.d/</filename> directories contain lists of
43 environment variable assignments passed to services started by the systemd user instance.
44 <citerefentry><refentrytitle>systemd-environment-d-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>
45 parses them and updates the environment exported by the systemd user instance. See below for an
46 discussion of which processes inherit those variables.</para>
48 <para>It is recommended to use numerical prefixes for file names to simplify ordering.</para>
50 <para>For backwards compatibility, a symlink to <filename>/etc/environment</filename> is
51 installed, so this file is also parsed.</para>
54 <xi:include href="standard-conf.xml" xpointer="confd" />
57 <title>Configuration Format</title>
59 <para>The configuration files contain a list of
60 <literal><replaceable>KEY</replaceable>=<replaceable>VALUE</replaceable></literal> environment
61 variable assignments, separated by newlines. The right hand side of these assignments may
62 reference previously defined environment variables, using the <literal>${OTHER_KEY}</literal>
63 and <literal>$OTHER_KEY</literal> format. It is also possible to use
64 <literal>${<replaceable>FOO</replaceable>:-<replaceable>DEFAULT_VALUE</replaceable>}</literal>
65 to expand in the same way as <literal>${<replaceable>FOO</replaceable>}</literal> unless the
66 expansion would be empty, in which case it expands to <replaceable>DEFAULT_VALUE</replaceable>,
68 <literal>${<replaceable>FOO</replaceable>:+<replaceable>ALTERNATE_VALUE</replaceable>}</literal>
69 to expand to <replaceable>ALTERNATE_VALUE</replaceable> as long as
70 <literal>${<replaceable>FOO</replaceable>}</literal> would have expanded to a non-empty value.
71 No other elements of shell syntax are supported.</para>
73 <para>Each <replaceable>KEY</replaceable> must be a valid variable name. Empty lines
74 and lines beginning with the comment character <literal>#</literal> are ignored.</para>
77 <title>Example</title>
79 <title>Setup environment to allow access to a program installed in
80 <filename index="false">/opt/foo</filename></title>
82 <para><filename index="false">/etc/environment.d/60-foo.conf</filename>:
85 FOO_DEBUG=force-software-gl,log-verbose
86 PATH=/opt/foo/bin:$PATH
87 LD_LIBRARY_PATH=/opt/foo/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
88 XDG_DATA_DIRS=/opt/foo/share:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}
95 <title>Applicability</title>
97 <para>Environment variables exported by the user service manager (<command>systemd --user</command>
98 instance started in the <filename>user@<replaceable>uid</replaceable>.service</filename> system service)
99 are passed to any services started by that service manager. In particular, this may include services
100 which run user shells. For example in the GNOME environment, the graphical terminal emulator runs as the
101 <filename>gnome-terminal-server.service</filename> user unit, which in turn runs the user shell, so that
102 shell will inherit environment variables exported by the user manager. For other instances of the shell,
103 not launched by the user service manager, the environment they inherit is defined by the program that
104 starts them. Hint: in general,
105 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> units
106 contain programs launched by systemd, and
107 <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry> units
108 contain programs launched by something else.</para>
110 <para>Note that these files do not affect the environment block of the service manager itself, but
111 exclusively the environment blocks passed to the services it manages. Environment variables set that way
112 thus cannot be used to influence behaviour of the service manager. In order to make changes to the
113 service manager's environment block the environment must be modified before the user's service manager is
114 invoked, for example from the system service manager or via a PAM module.</para>
116 <para>Specifically, for ssh logins, the
117 <citerefentry project='man-pages'><refentrytitle>sshd</refentrytitle><manvolnum>8</manvolnum></citerefentry>
118 service builds an environment that is a combination of variables forwarded from the remote system and
119 defined by <command>sshd</command>, see the discussion in
120 <citerefentry project='man-pages'><refentrytitle>ssh</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
121 A graphical display session will have an analogous mechanism to define the environment. Note that some
122 managers query the systemd user instance for the exported environment and inject this configuration into
123 programs they start, using <command>systemctl show-environment</command> or the underlying D-Bus call.
128 <title>See Also</title>
129 <para><simplelist type="inline">
130 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
131 <member><citerefentry><refentrytitle>systemd-environment-d-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>
132 <member><citerefentry><refentrytitle>systemd.environment-generator</refentrytitle><manvolnum>7</manvolnum></citerefentry></member>