]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/environment.d.xml
Merge pull request #30284 from YHNdnzj/fstab-wantedby-defaultdeps
[thirdparty/systemd.git] / man / environment.d.xml
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.2/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/lib/environment.d/*.conf</filename></member>
34 <member><filename>/etc/environment</filename></member>
35 </simplelist></para>
36 </refsynopsisdiv>
37
38 <refsect1>
39 <title>Description</title>
40
41 <para>Configuration files in the <filename>environment.d/</filename> directories contain lists of
42 environment variable assignments passed to services started by the systemd user instance.
43 <citerefentry><refentrytitle>systemd-environment-d-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>
44 parses them and updates the environment exported by the systemd user instance. See below for an
45 discussion of which processes inherit those variables.</para>
46
47 <para>It is recommended to use numerical prefixes for file names to simplify ordering.</para>
48
49 <para>For backwards compatibility, a symlink to <filename>/etc/environment</filename> is
50 installed, so this file is also parsed.</para>
51 </refsect1>
52
53 <xi:include href="standard-conf.xml" xpointer="confd" />
54
55 <refsect1>
56 <title>Configuration Format</title>
57
58 <para>The configuration files contain a list of
59 <literal><replaceable>KEY</replaceable>=<replaceable>VALUE</replaceable></literal> environment
60 variable assignments, separated by newlines. The right hand side of these assignments may
61 reference previously defined environment variables, using the <literal>${OTHER_KEY}</literal>
62 and <literal>$OTHER_KEY</literal> format. It is also possible to use
63 <literal>${<replaceable>FOO</replaceable>:-<replaceable>DEFAULT_VALUE</replaceable>}</literal>
64 to expand in the same way as <literal>${<replaceable>FOO</replaceable>}</literal> unless the
65 expansion would be empty, in which case it expands to <replaceable>DEFAULT_VALUE</replaceable>,
66 and use
67 <literal>${<replaceable>FOO</replaceable>:+<replaceable>ALTERNATE_VALUE</replaceable>}</literal>
68 to expand to <replaceable>ALTERNATE_VALUE</replaceable> as long as
69 <literal>${<replaceable>FOO</replaceable>}</literal> would have expanded to a non-empty value.
70 No other elements of shell syntax are supported.</para>
71
72 <para>Each <replaceable>KEY</replaceable> must be a valid variable name. Empty lines
73 and lines beginning with the comment character <literal>#</literal> are ignored.</para>
74
75 <refsect2>
76 <title>Example</title>
77 <example>
78 <title>Setup environment to allow access to a program installed in
79 <filename index="false">/opt/foo</filename></title>
80
81 <para><filename index="false">/etc/environment.d/60-foo.conf</filename>:
82 </para>
83 <programlisting>
84 FOO_DEBUG=force-software-gl,log-verbose
85 PATH=/opt/foo/bin:$PATH
86 LD_LIBRARY_PATH=/opt/foo/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
87 XDG_DATA_DIRS=/opt/foo/share:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}
88 </programlisting>
89 </example>
90 </refsect2>
91 </refsect1>
92
93 <refsect1>
94 <title>Applicability</title>
95
96 <para>Environment variables exported by the user service manager (<command>systemd --user</command>
97 instance started in the <filename>user@<replaceable>uid</replaceable>.service</filename> system service)
98 are passed to any services started by that service manager. In particular, this may include services
99 which run user shells. For example in the GNOME environment, the graphical terminal emulator runs as the
100 <filename>gnome-terminal-server.service</filename> user unit, which in turn runs the user shell, so that
101 shell will inherit environment variables exported by the user manager. For other instances of the shell,
102 not launched by the user service manager, the environment they inherit is defined by the program that
103 starts them. Hint: in general,
104 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> units
105 contain programs launched by systemd, and
106 <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry> units
107 contain programs launched by something else.</para>
108
109 <para>Note that these files do not affect the environment block of the service manager itself, but
110 exclusively the environment blocks passed to the services it manages. Environment variables set that way
111 thus cannot be used to influence behaviour of the service manager. In order to make changes to the
112 service manager's environment block the environment must be modified before the user's service manager is
113 invoked, for example from the system service manager or via a PAM module.</para>
114
115 <para>Specifically, for ssh logins, the
116 <citerefentry project='die-net'><refentrytitle>sshd</refentrytitle><manvolnum>8</manvolnum></citerefentry>
117 service builds an environment that is a combination of variables forwarded from the remote system and
118 defined by <command>sshd</command>, see the discussion in
119 <citerefentry project='die-net'><refentrytitle>ssh</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
120 A graphical display session will have an analogous mechanism to define the environment. Note that some
121 managers query the systemd user instance for the exported environment and inject this configuration into
122 programs they start, using <command>systemctl show-environment</command> or the underlying D-Bus call.
123 </para>
124 </refsect1>
125
126 <refsect1>
127 <title>See Also</title>
128 <para>
129 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
130 <citerefentry><refentrytitle>systemd-environment-d-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
131 <citerefentry><refentrytitle>systemd.environment-generator</refentrytitle><manvolnum>7</manvolnum></citerefentry>
132 </para>
133 </refsect1>
134
135 </refentry>