Adding a Package Repository

Spack comes with thousands of built-in package recipes where each recipe resides in a package repository. By default, all packages are placed in var/spack/repos/builtin/ ,where builtin is a package repository. Spack searches the repositories when it needs to find a package by name. You may need to maintain packages for restricted, proprietary, or experimental software, which don’t affect the built-in repository. Spack allows you to configure local repositories using either the repos.yaml file or the spack repo command.

Package repositories allow you to:

  1. Maintain your own packages individually from Spack.

  2. Share your packages without committing them to the built-in Spack package repository.

  3. Override built-in Spack packages with your own implementation.

For more details, check the Spack Documentation.

Creating a New Repository

Spack allows users to create new package repositories and use them to maintain packages. The following is the general syntax for adding a new package repository:

spack repo create <package_name>

For example, to create a repository called myproject in $SPACK_ROOT/var/Spack/repos, you type:

spack repo create $SPACK_ROOT/var/spack/repos/myproject

How Spack Finds Repositories?

Spack uses the repos.yaml file, which is stored in $SPACK_ROOT/etc/spack/defaults/, to find repositories. The file by default looks like:

repos:
  - $spack/var/spack/repos/builtin

The file starts with repos: and contains the list of paths to repositories. The current file contains only one path, which starts with -, where - represents an item of a list. You can add a repository by inserting another path in a new line. For example, to add $SPACK_ROOT/var/spack/repos/myproject you first copy the repos.yaml file from $SPACK_ROOT/etc/spack/defaults/ to ~/.spack:

cp $SPACK_ROOT/etc/spack/defaults/repos.yaml ~/.spack

Then, you edit repos.yaml and add the path as follows:

vim ~/.spack/repos.yaml

Then you add the path $SPACK_ROOT/var/spack/repos/myproject to the file.

repos:
  - $spack/var/spack/repos/builtin
  - $SPACK_ROOT/var/spack/repos/myproject

When you try to install a package, Spack searches these repositories in order (first to last) to resolve each package name. For example, to install mpich, Spack will look for the following packages based on the repos.yaml and use the first valid file:

$spack/var/spack/repos/builtin/mpich/package.py
$SPACK_ROOT/var/spack/repos/myproject/mpich/package.py

namespaces

When you create a new package repository, it will be associated with a namespace. By default, the namespace will be the same as the name of the repository. For example, the myproject repository has myproject namespace. To find the namespace of a repository, you can show the repo.yaml file which is located in the package repository. For instance, to show repo.yaml of the myproject repository, you type:

cat $SPACK_ROOT/var/spack/repos/myproject/repo.yaml

The following output shows that myproject is the namespace of the myproject repository.

repo:
  namespace: 'myproject'

Spack records the repository namespace of each installed package. For example, if you install the mpich package from the builtin repository, Spack records its fully qualified name as builtin.mpich.

As stated before, each created repository has a default namespace that’s the same as the repository’s name. Sometimes you may create different repositories in different locations with the same name. This means that you may have more than a repository with the same namespace. Spack requires you to choose a namespace that uniquely identifies your package repository. For example, you can create a repository for packages to be used in your project, and you could use your project name as the namespace. You can also nest namespaces using periods. Alternatively, you might use discovery.hpcteams as a namespace for your repository.

Registering a Repository with Spack

Once you have created a package, you can register it with Spack using the spack repo add command:

spack repo add <Repo_Path>

Where Repo_Path is the path to the created repository. For example, to add the myproject repository, you type:

spack repo add  $SPACK_ROOT/var/spack/repos/myproject

Output:

==> Added repo with namespace 'myproject'.

Removing Registered Repositories

You can remove an already-registered repository using the spack repo remove command as follows:

spack repo remove <path_or_namespace>

You can either use the path or the namespace of the repository. For example, to remove myproject from Spack, type:

spack repo remove  $SPACK_ROOT/var/spack/repos/myproject

Or,

spack repo remove myproject