Skip to content

Creating a spack.yaml file

Let's create a spack.yaml file that will allow us to create a Spack environment for installing the sndfile PyPi package.

Below is a spack.yaml file which you can also find in the spack-config-templates repository inside the environment-templates sub-directory for the version of Spack you are using - called spack-python.yaml. Either copy and paste the below or grab the example from the repository, make sure it is named spack.yaml and save it into a directory of your choice for your environment. For the purposes of this tutorial I am going to save it as:

/data/scratch/${USER}/spack-environments/spack-python/spack.yaml

(please create the directory first if it doesn't exist). This means the Spack environment will also be stored in /data/scratch/${USER}/spack-environments/spack-python. You may wish to store your own environments in an alternative location if you need to keep them for longer. Please refer back to the Configuration overview page for further information.

Contents of spack.yaml (click to expand)
spack:
  compilers:
  - compiler:
      spec: gcc@=11.4.1
      paths:
        cc: /bin/gcc
        cxx: /bin/g++
        f77: /bin/gfortran
        fc: /bin/gfortran
      flags: {}
      operating_system: rocky9
      target: x86_64
      modules: []
      environment: {}
      extra_rpaths: []
  - compiler:
      spec: gcc@=12.2.0
      paths:
        cc: /share/apps/rocky9/spack/apps/linux-rocky9-x86_64_v4/gcc-11.4.1/gcc/12.2.0-6frskzg/bin/gcc
        cxx: /share/apps/rocky9/spack/apps/linux-rocky9-x86_64_v4/gcc-11.4.1/gcc/12.2.0-6frskzg/bin/g++
        f77: /share/apps/rocky9/spack/apps/linux-rocky9-x86_64_v4/gcc-11.4.1/gcc/12.2.0-6frskzg/bin/gfortran
        fc: /share/apps/rocky9/spack/apps/linux-rocky9-x86_64_v4/gcc-11.4.1/gcc/12.2.0-6frskzg/bin/gfortran
      flags: {}
      operating_system: rocky9
      target: x86_64
      modules: []
      environment: {}
      extra_rpaths: []
  concretizer:
    unify: true
  config:
    install_tree:
      root: /data/scratch/${USER}/spack/apps
      projections:
        ^mpi: '{architecture}/{compiler.name}-{compiler.version}/{name}/{version}-{^mpi.name}-{^mpi.version}-{hash:7}'
        all: '{architecture}/{compiler.name}-{compiler.version}/{name}/{version}-{hash:7}'
    license_dir: /data/scratch/${USER}/spack/licenses
    source_cache: /data/scratch/${USER}/spack/cache
  modules:
    prefix_inspections:
      ./share/aclocal:
      - ACLOCAL_PATH
      ./lib:
      - LD_LIBRARY_PATH
      - LIBRARY_PATH
      ./lib64:
      - LD_LIBRARY_PATH
      - LIBRARY_PATH
      ./include:
      - C_INCLUDE_PATH
      - CPLUS_INCLUDE_PATH
  packages:
    all:
      target: [x86_64_v4]
    openmpi:
      buildable: false
      prefer:
      - '+gpfs'
      externals:
      - spec: "openmpi@5.0.3%gcc@12.2.0"
        prefix: /share/apps/rocky9/general/libs/openmpi/gcc/12.2.0/5.0.3
    ucx:
      buildable: false
      externals:
      - spec: "ucx@1.16.0%gcc@12.2.0"
        prefix: /share/apps/rocky9/general/libs/ucx/gcc/12.2.0/1.16.0
  specs:
    - libsndfile
    - python@3.12
    - py-pip
  upstreams:
    apocrita:
      install_tree: /share/apps/rocky9/spack/apps
  view:
    default:
      root: .spack-env/view

It's basically identical to our previous example, but two things have changed:

First, the specs list (which now has libsndfile, Python 3.12 and py-pip).

You'll also see that there is now a new modules section. This doesn't actually create any modulefiles, but instead, this is where we define our traditional environment variables such as LD_LIBRARY_PATH, C_INCLUDE_PATH etc. via the prefix_inspections: sub-section. For more detailed information about this section, please refer to the official Spack documentation.