summaryrefslogtreecommitdiff
path: root/lib/spack/docs/configuration.rst
blob: 32e1a8c17065d179835f5d828621f1c75026bd93 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
.. _configuration:

==============================
Configuration Files in Spack
==============================

Spack has many configuration files.  Here is a quick list of them, in
case you want to skip directly to specific docs:

* :ref:`compilers.yaml <compiler-config>`
* :ref:`config.yaml <config-yaml>`
* :ref:`mirrors.yaml <mirrors>`
* :ref:`modules.yaml <modules>`
* :ref:`packages.yaml <build-settings>`
* :ref:`repos.yaml <repositories>`

-------------------------
YAML Format
-------------------------

Spack configuration files are written in YAML.  We chose YAML because
it's human readable, but also versatile in that it supports dictionaries,
lists, and nested sections. For more details on the format, see `yaml.org
<http://yaml.org>`_ and `libyaml <http://pyyaml.org/wiki/LibYAML>`_.
Here is an example ``config.yaml`` file:

.. code-block:: yaml

   config:
     install_tree: $spack/opt/spack
     module_roots:
       lmod:   $spack/share/spack/lmod
     build_stage:
       - $tempdir
       - /nfs/tmp2/$user

Each spack configuration files is nested under a top-level section
corresponding to its name. So, ``config.yaml`` starts with ``config:``,
and ``mirrors.yaml`` starts with ``mirrors:``, etc.

.. _configuration-scopes:

-------------------------
Configuration Scopes
-------------------------

Spack pulls configuration data from files in several directories. There
are three configuration scopes.  From lowest to highest:

1. **defaults**: Stored in ``$(prefix)/etc/spack/defaults/``. These are
   the "factory" settings. Users should generally not modify the settings
   here, but should override them in other configuration scopes. The
   defaults here will change from version to version of Spack.

2. **site**: Stored in ``$(prefix)/etc/spack/``.  Settings here affect
   only *this instance* of Spack, and they override defaults.  The site
   scope can can be used for per-project settings (one spack instance per
   project) or for site-wide settings on a multi-user machine (e.g., for
   a common spack instance).

3. **user**: Stored in the home directory: ``~/.spack/``. These settings
   affect all instances of Spack and take the highest precedence.

Each configuration directory may contain several configuration files,
such as ``config.yaml``, ``compilers.yaml``, or ``mirrors.yaml``.  When
configurations conflict, settings from higher-precedence scopes override
lower-precedence settings.

Commands that modify scopes (e.g., ``spack compilers``, ``spack repo``,
etc.) take a ``--scope=<name>`` parameter that you can use to control
which scope is modified.  By default they modify the highest-precedence
scope.

.. _platform-scopes:

-------------------------
Platform-specific scopes
-------------------------

For each scope above, there can *also* be platform-specific settings.
For example, on Blue Gene/Q machines, Spack needs to know the location of
cross-compilers for the compute nodes.  This configuration is in
``etc/spack/defaults/bgq/compilers.yaml``.  It will take precedence over
settings in the ``defaults`` scope, but can still be overridden by
settings in ``site``, ``site/bgq``, ``user``, or ``user/bgq``. So, the
full scope precedence is:

1. ``defaults``
2. ``defaults/<platform>``
3. ``site``
4. ``site/<platform>``
5. ``user``
6. ``user/<platform>``

You can get the name to use for ``<platform>`` by running ``spack arch
--platform``.

-------------------------
Scope precedence
-------------------------

When spack queries for configuration parameters, it searches in
higher-precedence scopes first.  So, settings in a higher-precedence file
can override those with the same key in a lower-precedence one.  For
list-valued settings, Spack *prepends* higher-precedence settings to
lower-precedence settings. Completely ignoring higher-level configuration
options is supported with the ``::`` notation for keys (see
:ref:`config-overrides` below).

^^^^^^^^^^^^^^^^^^^^^^^^
Simple keys
^^^^^^^^^^^^^^^^^^^^^^^^

Let's look at an example of overriding a single key in a Spack file.  If
your configurations look like this:

**defaults** scope:

.. code-block:: yaml

   config:
     install_tree: $spack/opt/spack
     module_roots:
       lmod:   $spack/share/spack/lmod
     build_stage:
       - $tempdir
       - /nfs/tmp2/$user

**site** scope:

.. code-block:: yaml

   config:
     install_tree: /some/other/directory

Spack will only override ``install_tree`` in the ``config`` section, and
will take the site preferences for other settings.  You can see the
final, combined configuration with the ``spack config get <configtype>``
command:

.. code-block:: console
   :emphasize-lines: 3

   $ spack config get config
   config:
     install_tree: /some/other/directory
     module_roots:
       lmod:   $spack/share/spack/lmod
     build_stage:
       - $tempdir
       - /nfs/tmp2/$user
   $ _

.. _config-overrides:

^^^^^^^^^^^^^^^^^^^^^^^^^^
Overriding entire sections
^^^^^^^^^^^^^^^^^^^^^^^^^^

Above, the site ``config.yaml`` only overrides specific settings in the
default ``config.yaml``.  Sometimes, it is useful to *completely*
override lower-precedence settings.  To do this, you can use *two* colons
at the end of a key in a configuration file.  For example, if the
**site** ``config.yaml`` above looks like this:

.. code-block:: yaml
   :emphasize-lines: 1

   config::
     install_tree: /some/other/directory

Spack will ignore all lower-precedence configuration under the
``config::`` section:

.. code-block:: console

   $ spack config get config
   config:
     install_tree: /some/other/directory

^^^^^^^^^^^^^^^^^^^^^^
List-valued settings
^^^^^^^^^^^^^^^^^^^^^^

Let's revisit the ``config.yaml`` example one more time.  The
``build_stage`` setting's value is an ordered list of directories:

**defaults**

.. code-block:: yaml

   build_stage:
     - $tempdir
     - /nfs/tmp2/$user

Suppose the user configuration adds its *own* list of ``build_stage``
paths:

**user**

.. code-block:: yaml

   build_stage:
     - /lustre-scratch/$user
     - ~/mystage

Spack will first look at the paths in the site ``config.yaml``, then the
paths in the user's ``~/.spack/config.yaml``.  The list in the
higher-precedence scope is *prepended* to the defaults.  ``spack config
get config`` shows the result:

.. code-block:: console
   :emphasize-lines: 7-10

   $ spack config get config
   config:
     install_tree: /some/other/directory
     module_roots:
       lmod:   $spack/share/spack/lmod
     build_stage:
       - /lustre-scratch/$user
       - ~/mystage
       - $tempdir
       - /nfs/tmp2/$user
   $ _

As in :ref:`config-overrides`, the higher-precedence scope can
*completely* override the lower-precedence scope using `::`.  So if the
user config looked like this:

**user**

.. code-block:: yaml
   :emphasize-lines: 1

   build_stage::
     - /lustre-scratch/$user
     - ~/mystage

The merged configuration would look like this:

.. code-block:: console
   :emphasize-lines: 7-8

   $ spack config get config
   config:
     install_tree: /some/other/directory
     module_roots:
       lmod:   $spack/share/spack/lmod
     build_stage:
       - /lustre-scratch/$user
       - ~/mystage
   $ _