Skip to content

Commit 2d9d97d

Browse files
committed
add env var docs
1 parent 6fa602c commit 2d9d97d

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

docs/recipes.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,73 @@ cuda-env:
359359
add_compilers: true
360360
prefix_paths:
361361
LD_LIBRARY_PATH: [lib, lib64]
362+
env_vars:
363+
set:
364+
- WOMBAT: null
365+
- NOCOLOR: "1"
366+
- JULIAUP_INSTALLDIR: "${@SCRATCH@}/.julia/gh200/juliaup"
367+
- PKG_CONFIG_PATH: null
368+
prepend_path:
369+
- PATH: "${@HOME@}/.local/x86_4/bin/"
370+
append_path:
371+
- PKG_CONFIG_PATH: /usr/lib/pkgconfig
372+
- PKG_CONFIG_PATH: /opt/cray/libfabric/1.15.2.0/lib64/pkgconfig
362373
```
363374

364375
* `add_compilers` (default `true`): by default Spack will not add compilers to the `PATH` variable. Stackinator automatically adds the `gcc` and/or `nvhpc` to path. This option can be used to explicitly disable or enable this feature.
365376
* `prefix_paths` (default empty): this option can be used to customise prefix style environment variables (`PATH`, `LD_LIBRARY_PATH`, `PKG_CONFIG_PATH`, `PYTHONPATH`, etc).
366377
* the key is the environment variable, and the value is a list of paths to search for in the environment view. All paths that match an entry in the list will be prepended to the prefix path environment variable.
367378
* the main use for this feature is to opt-in to setting `LD_LIBRARY_PATH`. By default Spack does not add `lib` and `lib64` to `LD_LIBRARY_PATH` because that can break system installed applications that depend on `LD_LIBRARY_PATH` or finding their dependencies in standard locations like `/usr/lib`.
379+
* `env_vars`: see below for a more detailed explanation of how to fine tune environment variables in the view.
368380

369-
See the [interfaces documentation](interfaces.md#environment-views) for more information about how the environment views are provided to users of a stack.
381+
!!! info
382+
See the [interfaces documentation](interfaces.md#environment-views) for more information about how the environment views are provided.
383+
384+
#### Setting environment variables with `env_vars`
385+
386+
The `views:<view_name>:uenv:env_vars` field can be used to further fine-tune the environment variables that are set when the view is started.
387+
There are three environment variable "operation" that can be specified - `set`, `prepend_path`, and `append_path` - as demonstrated in the example above.
388+
389+
The `set` field is a list of environment variables key-value pairs that specify the variable name and the value to set it to.
390+
391+
* Setting a field to `null` will unset the variable if it was set by the parent environment.
392+
* `set` is a list, and values will be applied in the order that they are provided.
393+
It is possible to provide two values for a variable, and the last value will be the one used.
394+
* It is not possible to set an initial value that is not `null` for a prefix path variable.
395+
Set such variables to `null` (unset it), then provide `append_path` and `prefix_path` operations below to set the individual paths.
396+
397+
!!! note "using `${@VAR@}` to use environment variables"
398+
Sometimes you want to compase an environment variable **that has been set in the runtime environment** in your environment variable definition.
399+
For example, every user has a different `HOME` or `SCRATCH` value, and you might want to configure your view to store / read configuration from this path.
400+
The special syntax `${@VAR@}` will defer expanding the environment variable `VAR` until the view is loaded by uenv.
401+
The example above shows how to set the Juliaup install directory to be in the user's local scratch, i.e. a personalised private location for each user.
402+
403+
The `prepend_path` field takes a list of key-value pairs that define paths to prepend to a prefix path variable.
404+
405+
* Each entry is a single path
406+
* To prepend more than one path to a variable, pass multiple values (see `PKG_CONFIG_PATH` in `append_path` above)
407+
* The order in the list matters: paths will be prepended in the order that they appear in the list.
408+
409+
The `prepend_path` field is the same as `prepend_path`, except it appends instead of prepending.
410+
411+
!!! question "What are prefix path variables?"
412+
Prefix path variables are variables are environment variables that are `:`-separated list of paths, like `PATH`, `LD_LIBRARY_PATH`, `PYTHONPATH` etc that provide a list of paths that typically searched in order.
413+
414+
Currently the set of supported prefix path variables is hard coded in stackinator.
415+
If you need to set a prefix path that isn't on this list, contact the stackinator devs and we can implement support for user-defined prefix paths.
416+
417+
??? info "the hard-coded prefix paths"
418+
419+
* `ACLOCAL_PATH`
420+
* `CMAKE_PREFIX_PATH`
421+
* `CPATH`
422+
* `LD_LIBRARY_PATH`
423+
* `LIBRARY_PATH`
424+
* `MANPATH`
425+
* `MODULEPATH`
426+
* `PATH`
427+
* `PKG_CONFIG_PATH`
428+
* `PYTHONPATH`
370429

371430
## Modules
372431

0 commit comments

Comments
 (0)