| 1 |
<?xml version="1.0"?> |
| 2 |
<!--*-nxml-*--> |
| 3 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 4 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 5 |
<!-- |
| 6 |
SPDX-License-Identifier: LGPL-2.1-or-later |
| 7 |
|
| 8 |
Copyright © 2016 Red Hat, Inc. |
| 9 |
--> |
| 10 |
<refentry id="environment.d" conditional='ENABLE_ENVIRONMENT_D' |
| 11 |
xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 12 |
|
| 13 |
<refentryinfo> |
| 14 |
<title>environment.d</title> |
| 15 |
<productname>systemd</productname> |
| 16 |
</refentryinfo> |
| 17 |
|
| 18 |
<refmeta> |
| 19 |
<refentrytitle>environment.d</refentrytitle> |
| 20 |
<manvolnum>5</manvolnum> |
| 21 |
</refmeta> |
| 22 |
|
| 23 |
<refnamediv> |
| 24 |
<refname>environment.d</refname> |
| 25 |
<refpurpose>Definition of user service environment</refpurpose> |
| 26 |
</refnamediv> |
| 27 |
|
| 28 |
<refsynopsisdiv> |
| 29 |
<para><simplelist> |
| 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> |
| 36 |
</simplelist></para> |
| 37 |
</refsynopsisdiv> |
| 38 |
|
| 39 |
<refsect1> |
| 40 |
<title>Description</title> |
| 41 |
|
| 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> |
| 47 |
|
| 48 |
<para>It is recommended to use numerical prefixes for file names to simplify ordering.</para> |
| 49 |
|
| 50 |
<para>For backwards compatibility, a symlink to <filename>/etc/environment</filename> is |
| 51 |
installed, so this file is also parsed.</para> |
| 52 |
</refsect1> |
| 53 |
|
| 54 |
<xi:include href="standard-conf.xml" xpointer="confd" /> |
| 55 |
|
| 56 |
<refsect1> |
| 57 |
<title>Configuration Format</title> |
| 58 |
|
| 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>, |
| 67 |
and use |
| 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 |
You can escape a literal dollar sign <literal>$</literal> by doubling it, as in |
| 72 |
<literal>$$</literal>.</para> |
| 73 |
|
| 74 |
<para>A backslash character <literal>\</literal> followed by a newline acts as a line |
| 75 |
continuation (both characters are discarded); in all other cases, the backslash is consumed and |
| 76 |
the following character is included literally in the value. This can be used to preserve |
| 77 |
leading/trailing whitespace or include literal backslashes.</para> |
| 78 |
|
| 79 |
<para>You may optionally enclose the right hand side of assignments in pairs of either |
| 80 |
<constant>'</constant>single quotes<constant>'</constant> or <constant>"</constant>double |
| 81 |
quotes<constant>"</constant>; these will be stripped from the value before saving it. Using |
| 82 |
either quoting style does not affect variable expansion; however, single quotes disable |
| 83 |
backslash escaping entirely, while double quoting removes backslashes that precede double quotes |
| 84 |
<literal>"</literal>, dollar signs <literal>$</literal>, backslashes <literal>\</literal>, |
| 85 |
backticks <literal>`</literal>, and newlines, and leaves all other backslashes in place.</para> |
| 86 |
|
| 87 |
<para>Leading and trailing whitespace characters are stripped from both the left and right hand |
| 88 |
sides of the assignment. To preserve such spaces in the value, you can either enclose the entire |
| 89 |
value in quotes, or escape the space characters with backslashes. You can also include literal |
| 90 |
newlines in the value by enclosing it in quotes.</para> |
| 91 |
|
| 92 |
<para>Each <replaceable>KEY</replaceable> must be a valid variable name. Empty lines and lines |
| 93 |
beginning with the comment characters <literal>#</literal> or <literal>;</literal> are ignored. |
| 94 |
No other elements of shell syntax are supported.</para> |
| 95 |
|
| 96 |
<refsect2> |
| 97 |
<title>Examples</title> |
| 98 |
<example> |
| 99 |
<title>Setup environment to allow access to a program installed in |
| 100 |
<filename index="false">/opt/foo</filename></title> |
| 101 |
|
| 102 |
<para><filename index="false">/etc/environment.d/60-foo.conf</filename>: |
| 103 |
</para> |
| 104 |
<programlisting> |
| 105 |
FOO_DEBUG=force-software-gl,log-verbose |
| 106 |
PATH=/opt/foo/bin:$PATH |
| 107 |
LD_LIBRARY_PATH=/opt/foo/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} |
| 108 |
XDG_DATA_DIRS=/opt/foo/share:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/} |
| 109 |
</programlisting> |
| 110 |
</example> |
| 111 |
|
| 112 |
<example> |
| 113 |
<title>Escaping and variable expansion</title> |
| 114 |
|
| 115 |
<para><filename index="false">/etc/environment.d/70-bar.conf</filename>: |
| 116 |
</para> |
| 117 |
<programlisting> |
| 118 |
# A comment |
| 119 |
test_var=(variable) |
| 120 |
; Another comment |
| 121 |
test_comment=value # This is a part of the variable, and not a comment! |
| 122 |
|
| 123 |
test_none= \ before\ |
| 124 |
after "" '' \${test_var} |
| 125 |
test_double=" \ before\ |
| 126 |
after "" '' \${test_var}" |
| 127 |
test_single=' \ before\ |
| 128 |
after "" '' \${test_var}' |
| 129 |
|
| 130 |
# The above example produces the following environment variables, written using |
| 131 |
# C-style string escapes: |
| 132 |
# |
| 133 |
# test_var="(variable)" |
| 134 |
# test_comment="value # This is a part of the variable, and not a comment!" |
| 135 |
# test_none=" beforeafter \"\" '' (variable)" |
| 136 |
# test_double=" \\ beforeafter '' (variable)" |
| 137 |
# test_single=" \\ before\\\nafter \"\" \\(variable)" |
| 138 |
</programlisting> |
| 139 |
</example> |
| 140 |
</refsect2> |
| 141 |
</refsect1> |
| 142 |
|
| 143 |
<refsect1> |
| 144 |
<title>Applicability</title> |
| 145 |
|
| 146 |
<para>Environment variables exported by the user service manager (<command>systemd --user</command> |
| 147 |
instance started in the <filename>user@<replaceable>uid</replaceable>.service</filename> system service) |
| 148 |
are passed to any services started by that service manager. In particular, this may include services |
| 149 |
which run user shells. For example in the GNOME environment, the graphical terminal emulator runs as the |
| 150 |
<filename>gnome-terminal-server.service</filename> user unit, which in turn runs the user shell, so that |
| 151 |
shell will inherit environment variables exported by the user manager. For other instances of the shell, |
| 152 |
not launched by the user service manager, the environment they inherit is defined by the program that |
| 153 |
starts them. Hint: in general, |
| 154 |
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> units |
| 155 |
contain programs launched by systemd, and |
| 156 |
<citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry> units |
| 157 |
contain programs launched by something else.</para> |
| 158 |
|
| 159 |
<para>Note that these files do not affect the environment block of the service manager itself, but |
| 160 |
exclusively the environment blocks passed to the services it manages. Environment variables set that way |
| 161 |
thus cannot be used to influence behaviour of the service manager. In order to make changes to the |
| 162 |
service manager's environment block the environment must be modified before the user's service manager is |
| 163 |
invoked, for example from the system service manager or via a PAM module.</para> |
| 164 |
|
| 165 |
<para>Specifically, for ssh logins, the |
| 166 |
<citerefentry project='man-pages'><refentrytitle>sshd</refentrytitle><manvolnum>8</manvolnum></citerefentry> |
| 167 |
service builds an environment that is a combination of variables forwarded from the remote system and |
| 168 |
defined by <command>sshd</command>, see the discussion in |
| 169 |
<citerefentry project='man-pages'><refentrytitle>ssh</refentrytitle><manvolnum>1</manvolnum></citerefentry>. |
| 170 |
A graphical display session will have an analogous mechanism to define the environment. Note that some |
| 171 |
managers query the systemd user instance for the exported environment and inject this configuration into |
| 172 |
programs they start, using <command>systemctl show-environment</command> or the underlying D-Bus call. |
| 173 |
</para> |
| 174 |
</refsect1> |
| 175 |
|
| 176 |
<refsect1> |
| 177 |
<title>See Also</title> |
| 178 |
<para><simplelist type="inline"> |
| 179 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 180 |
<member><citerefentry><refentrytitle>systemd-environment-d-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry></member> |
| 181 |
<member><citerefentry><refentrytitle>systemd.environment-generator</refentrytitle><manvolnum>7</manvolnum></citerefentry></member> |
| 182 |
</simplelist></para> |
| 183 |
</refsect1> |
| 184 |
|
| 185 |
</refentry> |