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