Building with uenv¶
Uenv are user environments that provide scientific applications, libraries and tools on Alps. This article explains how to use them to build software.
For more documentation on how to find, download and use uenv in your workflow, see the uenv documentation.
Building software using Spack¶
Each uenv is tightly coupled with Spack and can be used as an upstream Spack instance, because the software in uenv is built with Spack using the Stackinator tool.
CSCS provides uenv-spack - a tool that can be used to quickly install software using the software and configuration provided inside a uenv, similarly to how module load loads software packages.
Installing uenv-spack¶
git clone https://github.com/eth-cscs/uenv-spack.git # (1)!
export PATH=$PWD/uenv-spack:$PATH # (2)!
-
Download the
uenv-spacktool from GitHub. -
Make the
uenv-spackexecutable available.
Requires uv
uenv-spack requires uv.
See our guide to setting up installation locations, before installing uv.
Select the uenv¶
The next step is to choose which uenv to use. The uenv will provide the compilers, Cray MPICH, and other libraries and tools.
graph TD
A[/is there a uenv for the application?\] -->|yes| B[use that image, e.g. **gromacs**]
A --> |no| C[/do I need OpenACC or CUDA Fortran?\]
C --> |no| D[use **prgenv-gnu**]
C --> |yes| E[/are you _really_ sure?\]
E --> |yes| F[use **prgenv-nvfortran**]
E --> |no| D
Use prgenv-gnu when in doubt
If you don’t know where to start, use the latest release of the prgenv-gnu on the system that you are targeting.
It provides the latest versions of gcc, cray-mpich, python and commonly used libraries like fftw and boost.
On systems that have NVIDIA GPUs (gh200 and a100 uarch), it also provides the latest version of cuda and nccl, and it is configured for GPU-aware MPI communication.
To use a uenv as an upstream Spack instance,
the uenv has to be started with the spack view:
What does the spack view do?
The spack view sets environment variables that provide information about the version of Spack that was used to build the uenv, and where the uenv Spack configuration is stored.
variable |
example |
description |
|---|---|---|
UENV_SPACK_CONFIG_PATH |
user-environment/config |
the path of the upstream spack configuration files. |
UENV_SPACK_REF |
releases/v0.23 |
the branch or tag used - this might be empty if a specific commit of Spack was used. |
UENV_SPACK_URL |
https://github.com/spack/spack.git |
The git repository for Spack - nearly always the main spack/spack repository. |
UENV_SPACK_COMMIT |
c6d4037758140fe...0cd1547f388ae51 |
The commit of Spack that was used |
Spack version 1 moved the Spack packages from inside the Spack repository to a standalone repository on GitHub. Uenvs that were built using Spack 1.0 and later will also set the following environment variables that provide information about the package versioning:
variable |
example |
description |
|---|---|---|
UENV_SPACK_PACKAGES_REF |
releases/v2025.07 |
the branch or tag used - this might be empty if a specific commit of Spack was used. |
UENV_SPACK_PACKAGES_URL |
https://github.com/spack/spack-packages.git |
The git repository - nearly always the main spack/spack-packages repository. |
UENV_SPACK_PACKAGES_COMMIT |
c6d4037758140fe...0cd1547f388ae51 |
The git commit of Spack-packages that was used |
Note
The environment variables set by the spack view are scoped by UENV_.
Therefore, they don’t change Spack-related environment variables.
You can use them to consistently set Spack-related environment variables.
Upstream Spack version
It is strongly recommended that your version of Spack and the version of Spack in the uenv match when building software on top of an uenv.
Advanced Spack users
The uenv-spack tool creates an empty Spack environment, configuration files and a build script that automates concretizing and installing the environment.
It is recommended that you take the time to review the environment and configuration, and modify it as needed for your project.
It is also possible to integrate uenv into your own Spack workflow.
For this, it is recommended to load the spack view, and use the UENV_SPACK_* environment variables.
Describing what to build¶
The next step is to describe what software to build. This is done using a Spack environment file and a Spack package repository.
The uenv-spack tool can be used to create a build directory with a template Spack environment file (spack.yaml) and a Spack package repository (repo/ directory).
Create a build directory with a Spack environment file and a Spack package repository
uenv-spack <build-path> --uarch=<uarch> --name=<env-name>
cd <build-path>
vim ./env/spack.yaml # (1)!
./build
- Edit the
spack.yamlfile to add package specs, set preferences, etc.
The arguments to uenv-spack arguments are:
- required:
<build-path>is the path in which the environment will be built:- typically in
$SCRATCH, e.g.$SCRATCH/builds/gromacs-24.11.
- typically in
- required:
--uarch=<uarch>: is the microarchitecture:- one of
zen2, zen3, gh200, a100; - used to set default variants in the Spack recipe.
- one of
- required:
--name=<env-name>: is the name of the environment:- must start with a letter, and may only contain letters, numbers, underscores
_and dashes-.
- must start with a letter, and may only contain letters, numbers, underscores
- optional:
--compiler=<compiler-name>: is the compiler toolchain to use in the generatedspack.yaml:- one of
gcc,nvhpc,llvm, orllvm-amdgpu. - default:
gcc - note that the compiler must be in the list of compilers provided by the uenv.
- one of
uenv-spack creates a directory tree with the following contents:
<build-path>
├─ build # (1)!
├─ spack # (2)!
├─ config # (3)!
│ ├─ meta.json # (4)!
│ ├─ user
│ │ ├─ config.yaml
│ │ ├─ modules.yaml
│ │ └─ repos.yaml
│ └─ system
│ ├─ compilers.yaml
│ ├─ packages.yaml
│ ├─ repos.yaml
│ └─ upstreams.yaml
└─ env # (5)!
├─ spack.yaml # (6)!
└─ repo # (7)!
├─ repo.yaml
└─ packages
- Script to build the software stack.
gitclone of the required version of Spack.- Spack configuration files for the software stack.
- Information about the uenv that was used to run
uenv-spack. - Description of the software to build.
- Template Spack environment file.
- Empty Spack package repository.
The env path contains a template spack.yaml file, and an empty Spack package repository:
where the spack.yaml file contains an empty list of specs:
Edit this file to add the specs that you wish to build, for example:
The step of adding a list of specs to the spack.yaml template can be skipped by providing them using the --specs argument to uenv-spack.
Create a build path and populate the spack.yaml file with some Spack specs
If you already have a directory with a complete spack.yaml file and custom repo,
you can provide it as an argument to uenv-spack:
Create a build path and use a pre-configured spack.yaml and repo
Create a build path and use your own spack.yaml
Build the software¶
Once specs have been added to spack.yaml, you can build the image using the build script that was generated in <build-path>:
This process will take a while, because the version of Spack that was downloaded needs to:
- bootstrap Spack;
- then concretise the environment;
- then build all of the packages.
The duration of the build depends on the specs: some specs may require a long time to build, or require installing many dependencies.
The build step generates multiple outputs, described below.
Installed packages¶
The packages built by Spack are installed in <build-path>/store.
Spack view¶
A Spack view is generated in <build-path>/view with an activation script <build-path>/view/activate.sh.
When the view is activated, all of the installed packages are available for use in the environment.
Activating the view
For an environment with build-path=$SCRATCH/software/tool that was built using prgenv-gnu/25.6:v2:
- Start the uenv: to use the software the
spackview does not need to be loaded. - The
activate.shscript sets environment variables that load the software.
Modules¶
Module files are generated in the module sub-directory of the <build-path>
To use them, add them to the module environment:
Use the modules
For an environment with build-path=$SCRATCH/software/tool that was built using prgenv-gnu/25.6:v2:
uenv start prgenv-gnu/25.6:v2 # (1)!
module use $SCRATCH/software/tool/modules # (2)!
module avail # (3)!
- Start the uenv: to use the software the
spackview does not need to be loaded. - Make modules available.
- Check that the modules are available.
Note
The generation of modules can be customised by editing the <build-path>/config/user/modules.yaml file before running build.
See the Spack modules documentation.