Reproducible HPC Stacks with Spack Environments and Lock Files
Use spack.yaml and spack.lock to pin dependency versions and build hashes so your HPC software stack builds the same way across sessions and clusters.
21 Dec 2025, 17:59 UTC

The problem: dependency drift on shared clusters
You build an HPC application successfully on one cluster, then share the same Spack spec with a colleague. Their build resolves a different dependency version, compiler, or build flag, and the install fails or behaves differently. Without a pinned dependency graph, "reproducible" often means "rebuild and hope."
The useful takeaway: use spack.yaml to declare what you want and spack.lock to freeze exactly how Spack resolved it. The same environment should then produce the same build hashes across sessions and machines.
What spack.yaml and spack.lock actually do
spack.yaml is the human-edited manifest for a directory-scoped Spack environment. You list packages, compiler preferences, and virtual dependency choices such as an MPI or BLAS provider. spack.lock is generated by concretization, Spack's process of turning an abstract request like "hdf5" into a concrete build: an exact version, variants, compiler, and a dependency hash for every package in the graph.
Terms to know first
- Spec: Spack's description of a package and its constraints.
- Concretization: resolving abstract specs into concrete builds with hashes.
- Hash: a build fingerprint identifying a specific dependency combination.
Worked example: lock a stack and reuse it
These steps assume a recent Spack release; behavior can differ across versions.
Step 1: Create the environment
Run in a shell where Spack is initialized:
spack env create demo
This creates a directory-scoped project. You need write access to the location Spack uses for environments.
Step 2: Declare packages in spack.yaml
Open spack.yaml in the environment directory and add packages. Adjust versions and variants to what your system supports:
spack:
packages:
hdf5:
variants: +mpi
compilers:
- gcc@11.4.0
Step 3: Concretize and inspect the lock
From the environment directory, or after activating it:
spack concretize -f
The -f flag rewrites spack.lock even if it already exists, so use it only when you intend to replace the pinned graph. Open spack.lock and confirm every dependency lists a concrete version and a hash. You can also verify from the command line:
spack spec --format '{hash} {name}@{version}'
If every line shows a hash and a pinned version, concretization succeeded. Missing or abstract hashes mean the graph is not fully locked.
Step 4: Install with reuse and verify activation
spack env activate demo
spack install --reuse
--reuse tells Spack to check the local install tree and build cache for binaries matching the locked concrete spec before compiling from source. Reuse requires matching target architecture, compiler, and build-cache signatures; otherwise Spack builds from source even if a similar package exists.
After installation, run:
which h5cc
Replace h5cc with a command provided by one of your installed packages. The path should point inside the environment's install tree, not a system directory. Activation is session-specific, so repeat it in each new shell.
Trade-offs and limitations
- Changing a variant or version in
spack.yamlcan invalidatespack.lockand force rebuilds of dependent packages. - Binary reuse is strict: a mismatched architecture, compiler, or cache signature forces a source build.
- Concretization can slow down on large dependency graphs, and resolved specs may differ across Spack versions.
spack.lockpins exact build hashes, but it does not guarantee identical runtime behavior if system libraries differ between clusters.
Pre-flight checklist before committing the lock
- Run
spack concretize -fand confirmspack.lockcontains hashes for every dependency. - Run
spack spec --format '{hash} {name}@{version}'and confirm no abstract specs remain. - Run
spack install --reuseand confirm packages install or reuse as expected. - Activate the environment and confirm
whichresolves to the environment install path.
Rollback
spack install --reuse writes to the Spack install tree. To undo, deactivate the environment and remove the environment directory, or uninstall packages individually. There is no single command guaranteed to remove a locked graph and all transitive dependencies cleanly.
Closing
Start small: lock one environment, share spack.yaml and spack.lock with your team, and make concretization part of your continuous integration check. The lock file is not a substitute for testing on each target cluster, but it removes one entire class of "it worked yesterday" failures.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.