Tutorial setup

If you have not done the prior sections, you’ll need to set Spack up like this:

git clone https://github.com/spack/spack
. spack/share/spack/setup-env.sh
spack tutorial

See the Basic Installation Tutorial for full details on setup. For more help join us in the #tutorial channel on Slack – get an invitation at spackpm.herokuapp.com

Mirrors and Binary Caches Tutorial

This tutorial will guide you through the process of setting up a source mirror with a binary cache. Source mirrors and binary caches are extremely useful when using spack on a machine without internet access. Source mirrors allow you to fetch source code from a directory on your filesystem instead of accessing the outside internet, and binary caches allow you to install pre-compiled binaries to your spack installation path. Together, these two features can speed up builds when using spack within a larger development team.

We will use the filesystem for the mirrors in this tutorial, but mirrors can also be setup on web servers or s3 buckets – any URL that curl can access can be setup as a Spack mirror.

By default, Spack comes configured with a source mirror in the cloud to increase download reliability. We’ve also already set up a mirror in this tutorial for binary caches. We can see these mirrors are configured

$ spack mirror list
tutorial	file:///mirror
spack-public	https://mirror.spack.io

Setting up a source cache mirror

When you run spack install, spack goes out to the internet to grab the source code to build your packages. This works fine on most clusters, but what do you do if the cluster in question doesn’t have access to the outside internet? This could happen for a variety of reasons. Maybe you’re building on a compute node that isn’t connected to the greater internet, or maybe even the whole cluster has been isolated from the internet.

Spack has an easy answer to this – setting up a source mirror. When you use a source mirror, spack checks the mirror for the source code before going to the outside internet.

Building a source mirror is easy. Let’s start with the same simple environment. First, let’s build our software on a computer with external internet access.

$ cd ~
$ mkdir cache-env
$ cd cache-env
$ spack env create -d .
==> Created environment in /home/spack/cache-env
==> You can activate this environment with:
==>   spack env activate /home/spack/cache-env
$ spacktivate .
$ # for now, disable fortran support in all packages
$ spack config add "packages:all:variants: ~fortran"
$ spack add macsio+scr
==> Adding macsio+scr to environment /home/spack/cache-env
$ spack install
==> Starting concretization
==> Environment concretized in 21.00 seconds.
==> Concretized macsio+scr
[+]  c5sjc2l  macsio@1.1%gcc@7.5.0~exodus~hdf5~ipo+mpi~pdb+scr+silo~szip~typhonio~zfp~zlib build_type=RelWithDebInfo patches=59479b9 arch=linux-ubuntu18.04-x86_64
[+]  tulqz4n	  ^cmake@3.23.1%gcc@7.5.0~doc+ncurses+ownlibs~qt build_type=Release arch=linux-ubuntu18.04-x86_64
[+]  frwzsc4	      ^ncurses@6.2%gcc@7.5.0~symlinks+termlib abi=none arch=linux-ubuntu18.04-x86_64
[+]  i5po27g		  ^pkgconf@1.8.0%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  hqlqpsn	      ^openssl@1.1.1o%gcc@7.5.0~docs~shared certs=system arch=linux-ubuntu18.04-x86_64
[+]  pn5mtes		  ^perl@5.34.1%gcc@7.5.0+cpanm+shared+threads arch=linux-ubuntu18.04-x86_64
[+]  q6tqmmm		      ^berkeley-db@18.1.40%gcc@7.5.0+cxx~docs+stl patches=b231fcc arch=linux-ubuntu18.04-x86_64
[+]  cyn2yam		      ^bzip2@1.0.8%gcc@7.5.0~debug~pic+shared arch=linux-ubuntu18.04-x86_64
[+]  k22pe4r			  ^diffutils@3.8%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  dr56jt4			      ^libiconv@1.16%gcc@7.5.0 libs=shared,static arch=linux-ubuntu18.04-x86_64
[+]  xub4jsy		      ^gdbm@1.19%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  ls6erxw			  ^readline@8.1%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  fntvsj6		      ^zlib@1.2.12%gcc@7.5.0+optimize+pic+shared patches=0d38234 arch=linux-ubuntu18.04-x86_64
[+]  la2ibsb	  ^json-cwx@0.12%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  hlj3ujm	      ^autoconf@2.69%gcc@7.5.0 patches=35c4492,7793209,a49dd5b arch=linux-ubuntu18.04-x86_64
[+]  uadbn2a		  ^m4@1.4.19%gcc@7.5.0+sigsegv patches=9dc5fbd,bfdffa7 arch=linux-ubuntu18.04-x86_64
[+]  ubezeyc		      ^libsigsegv@2.13%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  6vk5ehd	      ^automake@1.16.5%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  7fhdrxx	      ^libtool@2.4.7%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  jfxctqw	  ^openmpi@4.1.3%gcc@7.5.0~atomics~cuda~cxx~cxx_exceptions~gpfs~internal-hwloc~java~legacylaunchers~lustre~memchecker~pmi+romio+rsh~singularity+static+vt+wrapper-rpath fabrics=none schedulers=none arch=linux-ubuntu18.04-x86_64
[+]  oixja6d	      ^hwloc@2.7.1%gcc@7.5.0~cairo~cuda~gl~libudev+libxml2~netloc~nvml~opencl+pci~rocm+shared arch=linux-ubuntu18.04-x86_64
[+]  csp5gvq		  ^libpciaccess@0.16%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  vkk73ww		      ^util-macros@1.19.3%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  4run532		  ^libxml2@2.9.13%gcc@7.5.0~python arch=linux-ubuntu18.04-x86_64
[+]  olptpbs		      ^xz@5.2.5%gcc@7.5.0~pic libs=shared,static arch=linux-ubuntu18.04-x86_64
[+]  wfnw532	      ^numactl@2.0.14%gcc@7.5.0 patches=4e1d78c,62fc8a8,ff37630 arch=linux-ubuntu18.04-x86_64
[+]  3ez3d3j	      ^openssh@9.0p1%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  zc56lv6		  ^libedit@3.1-20210216%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  e4fax47	      ^pmix@4.1.2%gcc@7.5.0~docs+pmi_backwards_compatibility~restful arch=linux-ubuntu18.04-x86_64
[+]  hlnkgmr		  ^libevent@2.1.12%gcc@7.5.0+openssl arch=linux-ubuntu18.04-x86_64
[+]  txizals	  ^scr@2.0.0%gcc@7.5.0+dtcmp~fortran~ipo+libyogrt async_api=NONE build_type=RelWithDebInfo cache_base=/dev/shm cntl_base=/dev/shm copy_config=none file_lock=FLOCK resource_manager=SLURM scr_config=scr.conf arch=linux-ubuntu18.04-x86_64
[+]  hy5wusa	      ^dtcmp@1.1.4%gcc@7.5.0+shared arch=linux-ubuntu18.04-x86_64
[+]  vbl4vci		  ^lwgrp@1.0.5%gcc@7.5.0+shared arch=linux-ubuntu18.04-x86_64
[+]  hiyjovc	      ^libyogrt@1.27%gcc@7.5.0~static scheduler=slurm arch=linux-ubuntu18.04-x86_64
[+]  w7ebjng		  ^slurm@21-08-8-2%gcc@7.5.0~gtk~hdf5~hwloc~mariadb~pmix+readline~restd sysconfdir=PREFIX/etc arch=linux-ubuntu18.04-x86_64
[+]  7fafhiv		      ^curl@7.83.0%gcc@7.5.0~gssapi~ldap~libidn2~librtmp~libssh~libssh2~nghttp2 libs=shared,static tls=openssl arch=linux-ubuntu18.04-x86_64
[+]  6zbu2np		      ^glib@2.72.1%gcc@7.5.0~libmount patches=b3fd450 tracing=none arch=linux-ubuntu18.04-x86_64
[+]  wuasyuu			  ^gettext@0.21%gcc@7.5.0+bzip2+curses+git~libunistring+libxml2+tar+xz arch=linux-ubuntu18.04-x86_64
[+]  3f62loj			      ^tar@1.34%gcc@7.5.0 zip=pigz arch=linux-ubuntu18.04-x86_64
[+]  i74tgiq				  ^pigz@2.7%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  w4beu34				  ^zstd@1.5.2%gcc@7.5.0+programs compression=none libs=shared,static arch=linux-ubuntu18.04-x86_64
[+]  tkru6n3			  ^libffi@3.4.2%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  ex7yt4h			  ^meson@0.62.1%gcc@7.5.0 patches=aa6c50d arch=linux-ubuntu18.04-x86_64
[+]  uzsjh5q			      ^ninja@1.10.2%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  t3ey2ga				  ^python@3.9.12%gcc@7.5.0+bz2+ctypes+dbm~debug+ensurepip+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4+uuid+zlib patches=0d98e93,4c24573,f2fd060 arch=linux-ubuntu18.04-x86_64
[+]  5grv4ow				      ^expat@2.4.8%gcc@7.5.0+libbsd arch=linux-ubuntu18.04-x86_64
[+]  zliunm4					  ^libbsd@0.11.5%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  llu53co					      ^libmd@1.0.4%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  zbjzhle				      ^sqlite@3.38.5%gcc@7.5.0+column_metadata+dynamic_extensions+fts~functions+rtree arch=linux-ubuntu18.04-x86_64
[+]  7fulw7l				      ^util-linux-uuid@2.37.4%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  7oj7aer			      ^py-pip@21.3.1%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  s4xj57d			      ^py-setuptools@59.4.0%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  gbfkdty				  ^py-wheel@0.37.0%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  fjffevr			  ^pcre@8.45%gcc@7.5.0~jit+multibyte+utf arch=linux-ubuntu18.04-x86_64
[+]  kesugzv		      ^json-c@0.15%gcc@7.5.0~ipo build_type=RelWithDebInfo arch=linux-ubuntu18.04-x86_64
[+]  fneymg5		      ^lz4@1.9.3%gcc@7.5.0 libs=shared,static arch=linux-ubuntu18.04-x86_64
[+]  f7lz2ay		      ^munge@0.5.14%gcc@7.5.0 localstatedir=PREFIX/var arch=linux-ubuntu18.04-x86_64
[+]  hyy5p47			  ^libgcrypt@1.9.4%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  3zqjdtu			      ^libgpg-error@1.43%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  gyjxwt5				  ^gawk@5.1.1%gcc@7.5.0~nls arch=linux-ubuntu18.04-x86_64
[+]  lf7yoxu				      ^gmp@6.2.1%gcc@7.5.0 libs=shared,static arch=linux-ubuntu18.04-x86_64
[+]  3txoqc5				      ^mpfr@4.1.0%gcc@7.5.0 libs=shared,static arch=linux-ubuntu18.04-x86_64
[+]  uk63mel					  ^autoconf-archive@2022.02.11%gcc@7.5.0 patches=130cd48 arch=linux-ubuntu18.04-x86_64
[+]  ot5b2ak					  ^texinfo@6.5%gcc@7.5.0 patches=12f6edb,1732115 arch=linux-ubuntu18.04-x86_64
[+]  aszdbjy	      ^pdsh@2.31%gcc@7.5.0+ssh+static_modules arch=linux-ubuntu18.04-x86_64
[+]  dcsbgpf	  ^silo@4.10.2%gcc@7.5.0~fortran+fpzip+hdf5+hzip+mpi+pic+shared~silex patches=3a1e831,7b5a1dc,eb2a3a0,fa050e0 arch=linux-ubuntu18.04-x86_64
[+]  rh2gilz	      ^hdf5@1.12.2%gcc@7.5.0~cxx~fortran~hl~ipo~java+mpi+shared~szip~threadsafe+tools api=default build_type=RelWithDebInfo arch=linux-ubuntu18.04-x86_64

==> Installing environment /home/spack/cache-env
==> All of the packages are already installed

Once we’ve created and installed this environment, we can easily upload source code needed to reproduce this build to a mirror. The following command both creates the mirror and uploads the source code for the scr package included in our environment. The -d flag (short for --directory) tells spack where to place the mirrored source code files.

$ spack mirror create -d ~/mirror scr
==> Adding package scr@2.0.0 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/47/471978ae0afb56a20847d3989b994fbd680d1dea21e77a5a46a964b6e3deed6b.tar.gz
==> Successfully created mirror in file:///home/spack/mirror
  Archive stats:
    0	 already present
    1	 added
    0	 failed to fetch.

We can configure spack to use this source mirror by adding a few lines to your spack.yaml file.

$ spack mirror add mymirror ~/mirror

Manually uploading every package in an environment can be tedious. Luckily, when run within an environment, spack mirror create with the --all flag will upload every source used to build the current environment to the specified directory.

$ spack mirror create -d ~/mirror --all
==> Adding package autoconf@2.69 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/95/954bd69b391edc12d6a4a51a2dd1476543da5c6bbf05a95b59dc0dd6fd4c2969.tar.gz
==> Fetching https://mirror.spack.io/_source-cache/archive/ea/eaa3f69d927a853313a0b06e2117c51adab6377a2278549b05abc5df93643e16
==> Fetching https://mirror.spack.io/_source-cache/archive/77/7793209b33013dc0f81208718c68440c5aae80e7a1c4b8d336e382525af791a7
==> Fetching https://mirror.spack.io/_source-cache/archive/35/35c449281546376449766f92d49fc121ca50e330e60fefcfc9be2af3253082c2
==> Fetching https://mirror.spack.io/_source-cache/archive/a4/a49dd5bac3b62daa0ff688ab4d508d71dbd2f4f8d7e2a02321926346161bf3ee
==> Adding package autoconf-archive@2022.02.11 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/78/78a61b611e2eeb55a89e0398e0ce387bcaf57fe2dd53c6fe427130f777ad1e8c.tar.xz
==> Adding package automake@1.16.5 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/07/07bd24ad08a64bc17250ce09ec56e921d6343903943e99ccf63bbf0705e34605.tar.gz
==> Adding package berkeley-db@18.1.40 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/0c/0cecb2ef0c67b166de93732769abdeba0555086d51de1090df325e18ee8da9c8.tar.gz
==> Adding package bzip2@1.0.8 to mirror
==> Using cached archive: /home/spack/spack/var/spack/cache/_source-cache/archive/ab/ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269.tar.gz
==> Adding package cmake@3.23.1 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/33/33fd10a8ec687a4d0d5b42473f10459bb92b3ae7def2b745dc10b192760869f3.tar.gz
==> Adding package curl@7.83.0 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/24/247c7ec7521c4258e65634e529270d214fe32969971cccb72845e7aa46831f96.tar.bz2
==> Adding package diffutils@3.8 to mirror
==> Using cached archive: /home/spack/spack/var/spack/cache/_source-cache/archive/a6/a6bdd7d1b31266d11c4f4de6c1b748d4607ab0231af5188fc2533d0ae2438fec.tar.xz
==> Adding package dtcmp@1.1.4 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/dd/dd83d8cecd68e13b78b68e88675cc5847cde06742b7740e140b98f4a08127dd3.tar.gz
==> Adding package expat@2.4.8 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/a2/a247a7f6bbb21cf2ca81ea4cbb916bfb9717ca523631675f99b3d4a5678dcd16.tar.bz2
==> Adding package gawk@5.1.1 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/d8/d87629386e894bbea11a5e00515fc909dc9b7249529dad9e6a3a2c77085f7ea2.tar.xz
==> Adding package gdbm@1.19 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/37/37ed12214122b972e18a0d94995039e57748191939ef74115b1d41d8811364bc.tar.gz
==> Adding package gettext@0.21 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/d2/d20fcbb537e02dcf1383197ba05bd0734ef7bf5db06bdb241eb69b7d16b73192.tar.xz
==> Adding package glib@2.72.1 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/c0/c07e57147b254cef92ce80a0378dc0c02a4358e7de4702e9f403069781095fe2.tar.xz
==> Adding package gmp@6.2.1 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/ea/eae9326beb4158c386e39a356818031bd28f3124cf915f8c5b1dc4c7a36b4d7c.tar.bz2
==> Adding package hdf5@1.12.2 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/2a/2a89af03d56ce7502dcae18232c241281ad1773561ec00c0f0e8ee2463910f14.tar.gz
==> Fetching https://mirror.spack.io/_source-cache/archive/57/57cee5ff1992b4098eda079815c36fc2da9b10e00a9056df054f2384c4fc7523
==> Adding package hwloc@2.7.1 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/4c/4cb0a781ed980b03ad8c48beb57407aa67c4b908e45722954b9730379bc7f6d5.tar.gz
==> Adding package json-c@0.15 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/b8/b8d80a1ddb718b3ba7492916237bbf86609e9709fb007e7f7d4322f02341a4c6.tar.gz
==> Adding package json-cwx@0.12 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/3b/3bfae1f23eacba53ee130dbd1a6acf617af4627a9b4e4581d64b20a99b4e2b60.tar.gz
==> Adding package libbsd@0.11.5 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/1a/1a9c952525635c1bb6770cb22e969b938d8e6a9d7912362b98ee8370599b0efd.tar.xz
==> Adding package libedit@3.1-20210216 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/22/2283f741d2aab935c8c52c04b57bf952d02c2c02e651172f8ac811f77b1fc77a.tar.gz
==> Adding package libevent@2.1.12 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/92/92e6de1be9ec176428fd2367677e61ceffc2ee1cb119035037a27d346b0403bb.tar.gz
==> Adding package libffi@3.4.2 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/54/540fb721619a6aba3bdeef7d940d8e9e0e6d2c193595bc243241b77ff9e93620.tar.gz
==> Adding package libgcrypt@1.9.4 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/ea/ea849c83a72454e3ed4267697e8ca03390aee972ab421e7df69dfe42b65caaf7.tar.bz2
==> Adding package libgpg-error@1.43 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/a9/a9ab83ca7acc442a5bd846a75b920285ff79bdb4e3d34aa382be88ed2c3aebaf.tar.bz2
==> Adding package libiconv@1.16 to mirror
==> Using cached archive: /home/spack/spack/var/spack/cache/_source-cache/archive/e6/e6a1b1b589654277ee790cce3734f07876ac4ccfaecbee8afa0b649cf529cc04.tar.gz
==> Adding package libmd@1.0.4 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/f5/f51c921042e34beddeded4b75557656559cf5b1f2448033b4c1eec11c07e530f.tar.xz
==> Adding package libpciaccess@0.16 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/84/84413553994aef0070cf420050aa5c0a51b1956b404920e21b81e96db6a61a27.tar.gz
==> Adding package libsigsegv@2.13 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/be/be78ee4176b05f7c75ff03298d84874db90f4b6c9d5503f0da1226b3a3c48119.tar.gz
==> Adding package libtool@2.4.7 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/04/04e96c2404ea70c590c546eba4202a4e12722c640016c12b9b2f1ce3d481e9a8.tar.gz
==> Adding package libxml2@2.9.13 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/27/276130602d12fe484ecc03447ee5e759d0465558fbc9d6bd144e3745306ebf0e.tar.xz
==> Fetching https://mirror.spack.io/_source-cache/archive/96/96151685cec997e1f9f3387e3626d61e6284d4d6e66e0e440c209286c03e9cc7.tar.gz
==> Adding package libyogrt@1.27 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/c5/c57ce60770b61aa20bc83fe34ff52b5e444964338df3786f282d0d9bcdd26138.tar.gz
==> Adding package lwgrp@1.0.5 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/16/16b579e13b8a5218f4fe1b8715f6aafb09133a0cefbcd6b2eaf73802955dee6b.tar.gz
==> Adding package lz4@1.9.3 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/03/030644df4611007ff7dc962d981f390361e6c97a34e5cbc393ddfbe019ffe2c1.tar.gz
==> Adding package m4@1.4.19 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/3b/3be4a26d825ffdfda52a56fc43246456989a3630093cced3fbddf4771ee58a70.tar.gz
==> Fetching https://mirror.spack.io/_source-cache/archive/fc/fc9b61654a3ba1a8d6cd78ce087e7c96366c290bc8d2c299f09828d793b853c8
==> Adding package macsio@1.1 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/a8/a86249b0f10647c0b631773db69568388094605ec1a0af149d9e61e95e6961ec.tar.gz
==> Adding package meson@0.62.1 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/9f/9fb52e66dbc613479a5f70e46cc2e8faf5aa65e09313f2c71fa63b8afd018107.tar.gz
==> Adding package mpfr@4.1.0 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/fe/feced2d430dd5a97805fa289fed3fc8ff2b094c02d05287fd6133e7f1f0ec926.tar.bz2
==> Fetching https://mirror.spack.io/_source-cache/archive/3f/3f80b836948aa96f8d1cb9cc7f3f55973f19285482a96f9a4e1623d460bcccf0
==> Fetching https://mirror.spack.io/_source-cache/archive/52/5230aab653fa8675fc05b5bdd3890e071e8df49a92a9d58c4284024affd27739
==> Fetching https://mirror.spack.io/_source-cache/archive/7a/7a6dd71bcda4803d6b89612706a17b8816e1acd5dd9bf1bec29cf748f3b60008
==> Fetching https://mirror.spack.io/_source-cache/archive/1a/1ae14fb3a54ae8e0faed20801970255b279eee9e5ac624891ab5d29727f0bc04
==> Fetching https://mirror.spack.io/_source-cache/archive/11/113705d5333ef0d0ad3eb136a85404ba6bd1cc524dece5ce902c536aa2e29903
==> Fetching https://mirror.spack.io/_source-cache/archive/41/4152a780b3cc6e9643283e59093b43460196d0fea9302d8c93b2496f6679f4e4
==> Fetching https://mirror.spack.io/_source-cache/archive/1b/1b9fdb515efb09a506a01e1eb307b1464455f5ca63d6c193db3a3da371ab3220
==> Adding package munge@0.5.14 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/66/6606a218f18090fa1f702e3f6fb608073eb6aafed534cf7dd81b67b2e0d30640.tar.xz
==> Adding package ncurses@6.2 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/30/30306e0c76e0f9f1f0de987cf1c82a5c21e1ce6568b9227f7da5b71cbea86c9d.tar.gz
==> Adding package ninja@1.10.2 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/ce/ce35865411f0490368a8fc383f29071de6690cbadc27704734978221f25e2bed.tar.gz
==> Adding package numactl@2.0.14 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/1e/1ee27abd07ff6ba140aaf9bc6379b37825e54496e01d6f7343330cf1a4487035.tar.gz
==> Adding package openmpi@4.1.3 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/3d/3d81d04c54efb55d3871a465ffb098d8d72c1f48ff1cbaf2580eb058567c0a3b.tar.bz2
==> Adding package openssh@9.0p1 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/03/03974302161e9ecce32153cfa10012f1e65c8f3750f573a73ab1befd5972a28a.tar.gz
==> Adding package openssl@1.1.1o to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/93/9384a2b0570dd80358841464677115df785edb941c71211f75076d72fe6b438f.tar.gz
==> Adding package pcre@8.45 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/4d/4dae6fdcd2bb0bb6c37b5f97c33c2be954da743985369cddac3546e3218bffb8.tar.bz2
==> Adding package pdsh@2.31 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/0e/0ee066ce395703285cf4f6cf00b54b7097d12457a4b1c146bc6f33d8ba73caa7.tar.gz
==> Adding package perl@5.34.1 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/35/357951a491b0ba1ce3611263922feec78ccd581dddc24a446b033e25acf242a1.tar.gz
==> Fetching https://mirror.spack.io/_source-cache/archive/9d/9da50e155df72bce55cb69f51f1dbb4b62d23740fb99f6178bb27f22ebdf8a46.tar.gz
==> Fetching https://mirror.spack.io/_source-cache/archive/8c/8cf4302ca8b480c60ccdcaa29ec53d9d50a71d4baf469ac8c6fca00ca31e58a2
==> Fetching https://mirror.spack.io/_source-cache/archive/3b/3bbd7d6f9933d80b9571533867b444c6f8f5a1ba0575bfba1fba4db9d885a71a
==> Fetching https://mirror.spack.io/_source-cache/archive/0e/0eac10ed90aeb0459ad8851f88081d439a4e41978e586ec743069e8b059370ac
==> Adding package pigz@2.7 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/d2/d2045087dae5e9482158f1f1c0f21c7d3de6f7cdc7cc5848bdabda544e69aa58.tar.gz
==> Adding package pkgconf@1.8.0 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/ef/ef9c7e61822b7cb8356e6e9e1dca58d9556f3200d78acab35e4347e9d4c2bbaf.tar.xz
==> Adding package pmix@4.1.2 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/67/670d3a02b39fb2126fe8084174cf03c484e027b5921b5c98a851108134e2597a.tar.bz2
==> Adding package py-pip@21.3.1 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/de/deaf32dcd9ab821e359cd8330786bcd077604b5c5730c0b096eda46f95c24a2d
==> Adding package py-setuptools@59.4.0 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/b4/b4c634615a0cf5b02cf83c7bedffc8da0ca439f00e79452699454da6fbd4153d.tar.gz
==> Adding package py-wheel@0.37.0 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/21/21014b2bd93c6d0034b6ba5d35e4eb284340e09d63c59aef6fc14b0f346146fd
==> Adding package python@3.9.12 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/70/70e08462ebf265012bd2be88a63d2149d880c73e53f1712b7bbbe93750560ae8.tgz
==> Adding package readline@8.1 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/f8/f8ceb4ee131e3232226a17f51b164afc46cd0b9e6cef344be87c65962cb82b02.tar.gz
==> Adding package scr@2.0.0 to mirror
==> Adding package silo@4.10.2 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/3a/3af87e5f0608a69849c00eb7c73b11f8422fa36903dd14610584506e7f68e638.tgz
==> Adding package slurm@21-08-8-2 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/87/876d7dfa716990d7e579cfb9c6ffc123258e03a1450e993ade596d2ee90afcdd.tar.gz
==> Adding package sqlite@3.38.5 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/5a/5af07de982ba658fd91a03170c945f99c971f6955bc79df3266544373e39869c.tar.gz
==> Adding package tar@1.34 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/03/03d908cf5768cfe6b7ad588c921c6ed21acabfb2b79b788d1330453507647aed.tar.gz
==> Adding package texinfo@6.5 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/d3/d34272e4042c46186ddcd66bd5d980c0ca14ff734444686ccf8131f6ec8b1427.tar.gz
==> Adding package util-linux-uuid@2.37.4 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/c8/c8b7b4fa541f974cc32c1c6559d9bfca33651020a456ad6ee5fc9b0cacd00151.tar.gz
==> Adding package util-macros@1.19.3 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/0f/0f812e6e9d2786ba8f54b960ee563c0663ddbe2434bf24ff193f5feab1f31971.tar.bz2
==> Adding package xz@5.2.5 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/51/5117f930900b341493827d63aa910ff5e011e0b994197c3b71c08a20228a42df.tar.bz2
==> Adding package zlib@1.2.12 to mirror
==> Using cached archive: /home/spack/spack/var/spack/cache/_source-cache/archive/91/91844808532e5ce316b3c010929493c0244f3d37593afd6de04f71821d5136d9.tar.gz
==> Adding package zstd@1.5.2 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/f7/f7de13462f7a82c29ab865820149e778cbfe01087b3a55b5332707abf9db4a6e.tar.gz
==> Successfully updated mirror in file:///home/spack/mirror
  Archive stats:
    1	 already present
    66	 added
    0	 failed to fetch.

This directory can be shared between users on a shared filesystem and protected with typical unix file permissions. If you’re making a spack mirror on a shared filesystem, remember to fix the file permissions every time you update the mirror, or update your umask settings so any new files you create have the appropriate permissions. Here you would replace the word spack to the appropriate unix group.

$ umask 750
$ chmod -R g+rs ~/mirror
$ chgrp -R spack ~/mirror

As long as spack can read from the mirror directory, spack will attempt to read source packages from the mirror instead of accessing the internet. This can be a huge boon for computers that can’t access the external internet but can access a shared filesystem. If you need to use spack on a system that is isolated from the external internet, you must bundle the whole spack mirror directory and unbundle it on the isolated system. From there, you follow the same steps to use the spack mirror as you would on any computer that can’t access the external internet.

If you need to add more sources to the mirror, you can re-run the command you used to create the mirror. For example, assume we want to add unzip to our environment.

$ spack add unzip
==> Adding unzip to environment /home/spack/cache-env
$ spack install
==> Starting concretization
==> Environment concretized in 0.82 seconds.
==> Concretized macsio+scr
[+]  c5sjc2l  macsio@1.1%gcc@7.5.0~exodus~hdf5~ipo+mpi~pdb+scr+silo~szip~typhonio~zfp~zlib build_type=RelWithDebInfo patches=59479b9 arch=linux-ubuntu18.04-x86_64
[+]  tulqz4n	  ^cmake@3.23.1%gcc@7.5.0~doc+ncurses+ownlibs~qt build_type=Release arch=linux-ubuntu18.04-x86_64
[+]  frwzsc4	      ^ncurses@6.2%gcc@7.5.0~symlinks+termlib abi=none arch=linux-ubuntu18.04-x86_64
[+]  i5po27g		  ^pkgconf@1.8.0%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  hqlqpsn	      ^openssl@1.1.1o%gcc@7.5.0~docs~shared certs=system arch=linux-ubuntu18.04-x86_64
[+]  pn5mtes		  ^perl@5.34.1%gcc@7.5.0+cpanm+shared+threads arch=linux-ubuntu18.04-x86_64
[+]  q6tqmmm		      ^berkeley-db@18.1.40%gcc@7.5.0+cxx~docs+stl patches=b231fcc arch=linux-ubuntu18.04-x86_64
[+]  cyn2yam		      ^bzip2@1.0.8%gcc@7.5.0~debug~pic+shared arch=linux-ubuntu18.04-x86_64
[+]  k22pe4r			  ^diffutils@3.8%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  dr56jt4			      ^libiconv@1.16%gcc@7.5.0 libs=shared,static arch=linux-ubuntu18.04-x86_64
[+]  xub4jsy		      ^gdbm@1.19%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  ls6erxw			  ^readline@8.1%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  fntvsj6		      ^zlib@1.2.12%gcc@7.5.0+optimize+pic+shared patches=0d38234 arch=linux-ubuntu18.04-x86_64
[+]  la2ibsb	  ^json-cwx@0.12%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  hlj3ujm	      ^autoconf@2.69%gcc@7.5.0 patches=35c4492,7793209,a49dd5b arch=linux-ubuntu18.04-x86_64
[+]  uadbn2a		  ^m4@1.4.19%gcc@7.5.0+sigsegv patches=9dc5fbd,bfdffa7 arch=linux-ubuntu18.04-x86_64
[+]  ubezeyc		      ^libsigsegv@2.13%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  6vk5ehd	      ^automake@1.16.5%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  7fhdrxx	      ^libtool@2.4.7%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  jfxctqw	  ^openmpi@4.1.3%gcc@7.5.0~atomics~cuda~cxx~cxx_exceptions~gpfs~internal-hwloc~java~legacylaunchers~lustre~memchecker~pmi+romio+rsh~singularity+static+vt+wrapper-rpath fabrics=none schedulers=none arch=linux-ubuntu18.04-x86_64
[+]  oixja6d	      ^hwloc@2.7.1%gcc@7.5.0~cairo~cuda~gl~libudev+libxml2~netloc~nvml~opencl+pci~rocm+shared arch=linux-ubuntu18.04-x86_64
[+]  csp5gvq		  ^libpciaccess@0.16%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  vkk73ww		      ^util-macros@1.19.3%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  4run532		  ^libxml2@2.9.13%gcc@7.5.0~python arch=linux-ubuntu18.04-x86_64
[+]  olptpbs		      ^xz@5.2.5%gcc@7.5.0~pic libs=shared,static arch=linux-ubuntu18.04-x86_64
[+]  wfnw532	      ^numactl@2.0.14%gcc@7.5.0 patches=4e1d78c,62fc8a8,ff37630 arch=linux-ubuntu18.04-x86_64
[+]  3ez3d3j	      ^openssh@9.0p1%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  zc56lv6		  ^libedit@3.1-20210216%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  e4fax47	      ^pmix@4.1.2%gcc@7.5.0~docs+pmi_backwards_compatibility~restful arch=linux-ubuntu18.04-x86_64
[+]  hlnkgmr		  ^libevent@2.1.12%gcc@7.5.0+openssl arch=linux-ubuntu18.04-x86_64
[+]  txizals	  ^scr@2.0.0%gcc@7.5.0+dtcmp~fortran~ipo+libyogrt async_api=NONE build_type=RelWithDebInfo cache_base=/dev/shm cntl_base=/dev/shm copy_config=none file_lock=FLOCK resource_manager=SLURM scr_config=scr.conf arch=linux-ubuntu18.04-x86_64
[+]  hy5wusa	      ^dtcmp@1.1.4%gcc@7.5.0+shared arch=linux-ubuntu18.04-x86_64
[+]  vbl4vci		  ^lwgrp@1.0.5%gcc@7.5.0+shared arch=linux-ubuntu18.04-x86_64
[+]  hiyjovc	      ^libyogrt@1.27%gcc@7.5.0~static scheduler=slurm arch=linux-ubuntu18.04-x86_64
[+]  w7ebjng		  ^slurm@21-08-8-2%gcc@7.5.0~gtk~hdf5~hwloc~mariadb~pmix+readline~restd sysconfdir=PREFIX/etc arch=linux-ubuntu18.04-x86_64
[+]  7fafhiv		      ^curl@7.83.0%gcc@7.5.0~gssapi~ldap~libidn2~librtmp~libssh~libssh2~nghttp2 libs=shared,static tls=openssl arch=linux-ubuntu18.04-x86_64
[+]  6zbu2np		      ^glib@2.72.1%gcc@7.5.0~libmount patches=b3fd450 tracing=none arch=linux-ubuntu18.04-x86_64
[+]  wuasyuu			  ^gettext@0.21%gcc@7.5.0+bzip2+curses+git~libunistring+libxml2+tar+xz arch=linux-ubuntu18.04-x86_64
[+]  3f62loj			      ^tar@1.34%gcc@7.5.0 zip=pigz arch=linux-ubuntu18.04-x86_64
[+]  i74tgiq				  ^pigz@2.7%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  w4beu34				  ^zstd@1.5.2%gcc@7.5.0+programs compression=none libs=shared,static arch=linux-ubuntu18.04-x86_64
[+]  tkru6n3			  ^libffi@3.4.2%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  ex7yt4h			  ^meson@0.62.1%gcc@7.5.0 patches=aa6c50d arch=linux-ubuntu18.04-x86_64
[+]  uzsjh5q			      ^ninja@1.10.2%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  t3ey2ga				  ^python@3.9.12%gcc@7.5.0+bz2+ctypes+dbm~debug+ensurepip+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4+uuid+zlib patches=0d98e93,4c24573,f2fd060 arch=linux-ubuntu18.04-x86_64
[+]  5grv4ow				      ^expat@2.4.8%gcc@7.5.0+libbsd arch=linux-ubuntu18.04-x86_64
[+]  zliunm4					  ^libbsd@0.11.5%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  llu53co					      ^libmd@1.0.4%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  zbjzhle				      ^sqlite@3.38.5%gcc@7.5.0+column_metadata+dynamic_extensions+fts~functions+rtree arch=linux-ubuntu18.04-x86_64
[+]  7fulw7l				      ^util-linux-uuid@2.37.4%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  7oj7aer			      ^py-pip@21.3.1%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  s4xj57d			      ^py-setuptools@59.4.0%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  gbfkdty				  ^py-wheel@0.37.0%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  fjffevr			  ^pcre@8.45%gcc@7.5.0~jit+multibyte+utf arch=linux-ubuntu18.04-x86_64
[+]  kesugzv		      ^json-c@0.15%gcc@7.5.0~ipo build_type=RelWithDebInfo arch=linux-ubuntu18.04-x86_64
[+]  fneymg5		      ^lz4@1.9.3%gcc@7.5.0 libs=shared,static arch=linux-ubuntu18.04-x86_64
[+]  f7lz2ay		      ^munge@0.5.14%gcc@7.5.0 localstatedir=PREFIX/var arch=linux-ubuntu18.04-x86_64
[+]  hyy5p47			  ^libgcrypt@1.9.4%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  3zqjdtu			      ^libgpg-error@1.43%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
[+]  gyjxwt5				  ^gawk@5.1.1%gcc@7.5.0~nls arch=linux-ubuntu18.04-x86_64
[+]  lf7yoxu				      ^gmp@6.2.1%gcc@7.5.0 libs=shared,static arch=linux-ubuntu18.04-x86_64
[+]  3txoqc5				      ^mpfr@4.1.0%gcc@7.5.0 libs=shared,static arch=linux-ubuntu18.04-x86_64
[+]  uk63mel					  ^autoconf-archive@2022.02.11%gcc@7.5.0 patches=130cd48 arch=linux-ubuntu18.04-x86_64
[+]  ot5b2ak					  ^texinfo@6.5%gcc@7.5.0 patches=12f6edb,1732115 arch=linux-ubuntu18.04-x86_64
[+]  aszdbjy	      ^pdsh@2.31%gcc@7.5.0+ssh+static_modules arch=linux-ubuntu18.04-x86_64
[+]  dcsbgpf	  ^silo@4.10.2%gcc@7.5.0~fortran+fpzip+hdf5+hzip+mpi+pic+shared~silex patches=3a1e831,7b5a1dc,eb2a3a0,fa050e0 arch=linux-ubuntu18.04-x86_64
[+]  rh2gilz	      ^hdf5@1.12.2%gcc@7.5.0~cxx~fortran~hl~ipo~java+mpi+shared~szip~threadsafe+tools api=default build_type=RelWithDebInfo arch=linux-ubuntu18.04-x86_64

==> Concretized unzip
 -   qos6nfh  unzip@6.0%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64

==> Installing environment /home/spack/cache-env
==> Waiting for unzip-6.0-qos6nfhjj5mdkrpwqrpb3hl6n5wi3woj
==> Installing unzip-6.0-qos6nfhjj5mdkrpwqrpb3hl6n5wi3woj
==> Fetching file:///mirror/build_cache/linux-ubuntu18.04-x86_64-gcc-7.5.0-unzip-6.0-qos6nfhjj5mdkrpwqrpb3hl6n5wi3woj.spec.json.sig
==> Fetching file:///mirror/build_cache/linux-ubuntu18.04-x86_64/gcc-7.5.0/unzip-6.0/linux-ubuntu18.04-x86_64-gcc-7.5.0-unzip-6.0-qos6nfhjj5mdkrpwqrpb3hl6n5wi3woj.spack
==> Extracting unzip-6.0-qos6nfhjj5mdkrpwqrpb3hl6n5wi3woj from binary cache
[+] /home/spack/spack/opt/spack/linux-ubuntu18.04-x86_64/gcc-7.5.0/unzip-6.0-qos6nfhjj5mdkrpwqrpb3hl6n5wi3woj
==> Updating view at /home/spack/cache-env/.spack-env/view

Now that we’ve added unzip, we need to update the mirror.

$ spack mirror create -d ~/mirror --all
==> Adding package autoconf@2.69 to mirror
==> Adding package autoconf-archive@2022.02.11 to mirror
==> Adding package automake@1.16.5 to mirror
==> Adding package berkeley-db@18.1.40 to mirror
==> Adding package bzip2@1.0.8 to mirror
==> Adding package cmake@3.23.1 to mirror
==> Adding package curl@7.83.0 to mirror
==> Adding package diffutils@3.8 to mirror
==> Adding package dtcmp@1.1.4 to mirror
==> Adding package expat@2.4.8 to mirror
==> Adding package gawk@5.1.1 to mirror
==> Adding package gdbm@1.19 to mirror
==> Adding package gettext@0.21 to mirror
==> Adding package glib@2.72.1 to mirror
==> Adding package gmp@6.2.1 to mirror
==> Adding package hdf5@1.12.2 to mirror
==> Adding package hwloc@2.7.1 to mirror
==> Adding package json-c@0.15 to mirror
==> Adding package json-cwx@0.12 to mirror
==> Adding package libbsd@0.11.5 to mirror
==> Adding package libedit@3.1-20210216 to mirror
==> Adding package libevent@2.1.12 to mirror
==> Adding package libffi@3.4.2 to mirror
==> Adding package libgcrypt@1.9.4 to mirror
==> Adding package libgpg-error@1.43 to mirror
==> Adding package libiconv@1.16 to mirror
==> Adding package libmd@1.0.4 to mirror
==> Adding package libpciaccess@0.16 to mirror
==> Adding package libsigsegv@2.13 to mirror
==> Adding package libtool@2.4.7 to mirror
==> Adding package libxml2@2.9.13 to mirror
==> Adding package libyogrt@1.27 to mirror
==> Adding package lwgrp@1.0.5 to mirror
==> Adding package lz4@1.9.3 to mirror
==> Adding package m4@1.4.19 to mirror
==> Adding package macsio@1.1 to mirror
==> Adding package meson@0.62.1 to mirror
==> Adding package mpfr@4.1.0 to mirror
==> Adding package munge@0.5.14 to mirror
==> Adding package ncurses@6.2 to mirror
==> Adding package ninja@1.10.2 to mirror
==> Adding package numactl@2.0.14 to mirror
==> Adding package openmpi@4.1.3 to mirror
==> Adding package openssh@9.0p1 to mirror
==> Adding package openssl@1.1.1o to mirror
==> Adding package pcre@8.45 to mirror
==> Adding package pdsh@2.31 to mirror
==> Adding package perl@5.34.1 to mirror
==> Adding package pigz@2.7 to mirror
==> Adding package pkgconf@1.8.0 to mirror
==> Adding package pmix@4.1.2 to mirror
==> Adding package py-pip@21.3.1 to mirror
==> Adding package py-setuptools@59.4.0 to mirror
==> Adding package py-wheel@0.37.0 to mirror
==> Adding package python@3.9.12 to mirror
==> Adding package readline@8.1 to mirror
==> Adding package scr@2.0.0 to mirror
==> Adding package silo@4.10.2 to mirror
==> Adding package slurm@21-08-8-2 to mirror
==> Adding package sqlite@3.38.5 to mirror
==> Adding package tar@1.34 to mirror
==> Adding package texinfo@6.5 to mirror
==> Adding package unzip@6.0 to mirror
==> Fetching https://mirror.spack.io/_source-cache/archive/03/036d96991646d0449ed0aa952e4fbe21b476ce994abc276e49d30e686708bd37.tar.gz
==> Adding package util-linux-uuid@2.37.4 to mirror
==> Adding package util-macros@1.19.3 to mirror
==> Adding package xz@5.2.5 to mirror
==> Adding package zlib@1.2.12 to mirror
==> Adding package zstd@1.5.2 to mirror
==> Successfully updated mirror in file:///home/spack/mirror
  Archive stats:
    67	 already present
    1	 added
    0	 failed to fetch.

Spack will skip uploading source code packages that are already included in the spack mirror. Mirrors can be shared across different environments, meaning one mirror can house all the source code needed to build your team’s dependencies.

Setting up a binary cache mirror

If you’re going to be setting up a team to use spack as part of their development practice, you’ll run up against the biggest disadvantage to using spack: building all your packages from scratch is slow. Recompiling the software dependencies for a large project can take hours to complete. If every developer is rebuilding their own software stack, that leads to a massive waste of computational resources and a loss of developer productivity.

Spack has two ways to help alleviate this problem: chained spack instances and spack binary caches. For now, we’re going to discuss spack binary caches as a way of solving this issue.

A spack binary cache is made up of spack binary packages. Each spack binary package, ending with a *.spack extension, is a tarball of an installed spack package signed with a gpg signature. When you install a package from a mirror with a binary cache, spack

  • Checks to see if there is a spack binary package that exactly matches the hash of the spec you want to build.
  • If a binary package is found, spack checks to see if the signature on the spack binary package is trusted. If the signature isn’t trusted or no package was found, spack builds the package from source.
  • If the signature is trusted, then spack unzips and relocates the spack package.

For the user, spack binary caches are transparent to use. This is a clear departure from systems like conda, where you need to chose separate workflows for binary and source packages. We’ve already demonstrated using spack binary caches earlier in the tutorial when we set up spack to use a binary mirror. As a reminder, we ran:

$ spack mirror add tutorial /mirror
$ spack buildcache keys --install --trust
gpg: key A8E0CA3C1C2ADA2F: 7 signatures not checked due to missing keys
gpg: key A8E0CA3C1C2ADA2F: public key "Spack Project Official Binaries <maintainers@spack.io>" imported
gpg: Total number processed: 1
gpg:		   imported: 1
gpg: no ultimately trusted keys found
gpg: inserting ownertrust of 6

Building a spack binary cache has some gotchas, but is almost as easy as building a source mirror. We’ll start by making a new environment for ourselves. Since we’re intending to publish to a binary cache, we’ll need to compile all these packages ourselves. This can take some time, so we’ll make a new environment with some packages that compile quickly.

$ cd ~
$ mkdir cache-binary
$ cd cache-binary
$ spack env create -d .
==> Created environment in /home/spack/cache-binary
==> You can activate this environment with:
==>   spack env activate /home/spack/cache-binary
$ spacktivate .
$ spack add bzip2
==> Adding bzip2 to environment /home/spack/cache-binary
$ spack add zlib
==> Adding zlib to environment /home/spack/cache-binary

Before we build anything, we need to modify the following line in our spack configuration file. Then, just to be sure, we’ll initiate a build of this environment and force ourselves to not use any cache.

$ spack config add "config:install_tree:padded_length:128"
$ spack install --no-cache
==> Starting concretization pool with 2 processes
==> Environment concretized in 1.23 seconds.
==> Concretized bzip2
 -   cyn2yam  bzip2@1.0.8%gcc@7.5.0~debug~pic+shared arch=linux-ubuntu18.04-x86_64
 -   k22pe4r	  ^diffutils@3.8%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
 -   dr56jt4	      ^libiconv@1.16%gcc@7.5.0 libs=shared,static arch=linux-ubuntu18.04-x86_64

==> Concretized zlib
 -   fntvsj6  zlib@1.2.12%gcc@7.5.0+optimize+pic+shared patches=0d38234 arch=linux-ubuntu18.04-x86_64

==> Installing environment /home/spack/cache-binary
==> Waiting for libiconv-1.16-dr56jt456uiebij2mkueldmejdxftigc
==> Installing libiconv-1.16-dr56jt456uiebij2mkueldmejdxftigc
==> Using cached archive: /home/spack/spack/var/spack/cache/_source-cache/archive/e6/e6a1b1b589654277ee790cce3734f07876ac4ccfaecbee8afa0b649cf529cc04.tar.gz
==> No patches needed for libiconv
==> libiconv: Executing phase: 'autoreconf'
==> libiconv: Executing phase: 'configure'
==> libiconv: Executing phase: 'build'
==> libiconv: Executing phase: 'install'
==> libiconv: Successfully installed libiconv-1.16-dr56jt456uiebij2mkueldmejdxftigc
  Fetch: 0.02s.  Build: 22.62s.  Total: 22.64s.
[+] /home/spack/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeh/linux-ubuntu18.04-x86_64/gcc-7.5.0/libiconv-1.16-dr56jt456uiebij2mkueldmejdxftigc
==> Waiting for zlib-1.2.12-fntvsj6xevbz5gyq7kfa4xg7oxnaolxs
==> Installing zlib-1.2.12-fntvsj6xevbz5gyq7kfa4xg7oxnaolxs
==> Using cached archive: /home/spack/spack/var/spack/cache/_source-cache/archive/91/91844808532e5ce316b3c010929493c0244f3d37593afd6de04f71821d5136d9.tar.gz
==> Applied patch /home/spack/spack/var/spack/repos/builtin/packages/zlib/configure-cc.patch
==> zlib: Executing phase: 'install'
==> zlib: Successfully installed zlib-1.2.12-fntvsj6xevbz5gyq7kfa4xg7oxnaolxs
  Fetch: 0.01s.  Build: 3.88s.	Total: 3.89s.
[+] /home/spack/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeh/linux-ubuntu18.04-x86_64/gcc-7.5.0/zlib-1.2.12-fntvsj6xevbz5gyq7kfa4xg7oxnaolxs
==> Waiting for diffutils-3.8-k22pe4rhr7yllf5pojl75veh5gkjdglq
==> Installing diffutils-3.8-k22pe4rhr7yllf5pojl75veh5gkjdglq
==> Using cached archive: /home/spack/spack/var/spack/cache/_source-cache/archive/a6/a6bdd7d1b31266d11c4f4de6c1b748d4607ab0231af5188fc2533d0ae2438fec.tar.xz
==> No patches needed for diffutils
==> diffutils: Executing phase: 'autoreconf'
==> diffutils: Executing phase: 'configure'
==> diffutils: Executing phase: 'build'
==> diffutils: Executing phase: 'install'
==> diffutils: Successfully installed diffutils-3.8-k22pe4rhr7yllf5pojl75veh5gkjdglq
  Fetch: 0.01s.  Build: 31.62s.  Total: 31.63s.
[+] /home/spack/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeh/linux-ubuntu18.04-x86_64/gcc-7.5.0/diffutils-3.8-k22pe4rhr7yllf5pojl75veh5gkjdglq
==> Waiting for bzip2-1.0.8-cyn2yamiu26ofxwgxzxbioreuwigzl6f
==> Installing bzip2-1.0.8-cyn2yamiu26ofxwgxzxbioreuwigzl6f
==> Using cached archive: /home/spack/spack/var/spack/cache/_source-cache/archive/ab/ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269.tar.gz
==> Ran patch() for bzip2
==> bzip2: Executing phase: 'install'
==> bzip2: Successfully installed bzip2-1.0.8-cyn2yamiu26ofxwgxzxbioreuwigzl6f
  Fetch: 0.01s.  Build: 2.18s.	Total: 2.19s.
[+] /home/spack/spack/opt/spack/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeh/linux-ubuntu18.04-x86_64/gcc-7.5.0/bzip2-1.0.8-cyn2yamiu26ofxwgxzxbioreuwigzl6f
==> Updating view at /home/spack/cache-binary/.spack-env/view

This configuration change ensures that spack installs all our packages to a path that is at least 128 characters. We need this change because of how spack relocates packages. Relocation consists of the following steps:

  • Search all text files to replace the package builder’s path with your specific local installation path.
  • Use patchelf to replace all the RPATHs in your binaries to point to your specific local installation path.
  • Search all binaries to replace hard-coded C strings of the package builder’s path with your specific local installation path.

Adding padding ensures that any paths hard-coded as C strings in our binaries will be large enough to hold our user’s eventual install path. We advise picking 128 because longer strings occasionally cause compilation problems with some software packages. If the user’s install path is too long, spack will give you a warning. All scripts and and RPATHs will still be properly relocated, but C strings within any binaries will not be modified. Depending on the package, this may cause problems when you try and use the software.

We also need to create a gpg key to sign all our packages. You should back up the secret and public keys to a secure place so they can be re-used in the future.

$ spack gpg create "My Name" "<my.email@my.domain.com>"
gpg: key 718DD98D63235873 marked as ultimately trusted
gpg: directory '/home/spack/spack/opt/spack/gpg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/home/spack/spack/opt/spack/gpg/openpgp-revocs.d/A74BD2559C7EAFFF1B48ECAC718DD98D63235873.rev'
$ mkdir ~/private_gpg_backup
$ cp ~/spack/opt/spack/gpg/*.gpg ~/private_gpg_backup
$ cp ~/spack/opt/spack/gpg/pubring.* ~/mirror

With this setup done, we’re ready to fill a binary cache with binary packages. Binary packages are attached to an existing source mirror. We follow the same steps we used for the source mirror – making an environment, creating the source mirror, and building the packages to a spack installation with our padded path. To upload a spec to a binary cache, simply use the command spack buildcache create --only=package spec. We use this here in a for loop to create binary packages for every non-external package in our environment. We do this by writing a find command that will return a hash of each spec in this environment and filtering out the external packages.

$
for ii in $(spack find --format "yyy {version} /{hash}" |
	    grep -v -E "^(develop^master)" |
	    grep "yyy" |
	    cut -f3 -d" ")
do
  spack buildcache create --allow-root --force -d ~/mirror --only=package $ii
done
==> Pushing binary packages to file:///home/spack/mirror/build_cache
gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:	2  signed:   0	trust: 0-, 0q, 0n, 0m, 0f, 2u
gpg: using "A74BD2559C7EAFFF1B48ECAC718DD98D63235873" as default secret key for signing
==> Pushing binary packages to file:///home/spack/mirror/build_cache
gpg: using "A74BD2559C7EAFFF1B48ECAC718DD98D63235873" as default secret key for signing
==> Pushing binary packages to file:///home/spack/mirror/build_cache
gpg: using "A74BD2559C7EAFFF1B48ECAC718DD98D63235873" as default secret key for signing
==> Pushing binary packages to file:///home/spack/mirror/build_cache
gpg: using "A74BD2559C7EAFFF1B48ECAC718DD98D63235873" as default secret key for signing

Voila, done! Our spack mirror has now been augmented with a binary cache. This cache can be used on systems without external internet access, just like with a spack source mirror. As always, remember to update the file permissions after updating the mirror.

$ umask 750
$ chmod -R g+rs ~/mirror
$ chgrp -R spack ~/mirror

Though it’s outside the scope of this tutorial, spack mirrors and build caches can also be hosted over https:// and s3:// as well. Consult the spack documentation for more information on how to do this.

Before a user can use this binary cache, they will need to make sure that they trust all the packages listed in the binary cache. If you’re sharing files between trusted users on a filesystem, you can do this with the following command:

$ spack buildcache keys --install --trust --force
==> Fetching file:///mirror/build_cache/_pgp/2C8DD3224EF3573A42BD221FA8E0CA3C1C2ADA2F.pub
gpg: key A8E0CA3C1C2ADA2F: 7 signatures not checked due to missing keys
gpg: key A8E0CA3C1C2ADA2F: "Spack Project Official Binaries <maintainers@spack.io>" not changed
gpg: Total number processed: 1
gpg:		  unchanged: 1

Together, this means download all the keys on the binary cache and trust them. Have your users run the above command on a new spack instance before they initiate a build.

Cache Summary

If you’re using spack within a development team, consider setting up source mirrors with binary caches. Source mirrors will let you replicate a spack environment on a machine without external internet access, and binary mirrors free you from the burden of recompiling everything from scratch and save you development time.