# Instructions on using additional spack packages with the DUNE DAQ release
###### tags: `Software Management` `DUNE-DAQ`
The code snippet below are copyable with two modifications:
1. `${SPACK_EXTRAS}` should point to a directory you own;
2. `${NIGHTLY}` should be the nightly release name you want to use.
```bash=
export SPACK_EXTERNALS=/cvmfs/dunedaq.opensciencegrid.org/spack-externals
export NIGHTLY="N22-05-10"
export SPACK_EXTRAS=/nfs/home/pding/newer_trace # change pding to your username
mkdir -p $SPACK_EXTRAS
docker run --rm -it --net=host \
-v /cvmfs:/cvmfs -v $SPACK_EXTRAS:$SPACK_EXTRAS \
-e SPACK_EXTRAS=$SPACK_EXTRAS \
-e SPACK_EXTERNALS=$SPACK_EXTERNALS \
-e NIGHTLY=$NIGHTLY \
dunedaq/sl7-minimal:spack
# Within docker container
# if on np04-srv-011, set up the web_proxy
export http_proxy=http://np04-web-proxy.cern.ch:3128
export https_proxy=http://np04-web-proxy.cern.ch:3128
cd $SPACK_EXTRAS
# enable proxy if, for example, on np04
wget https://github.com/spack/spack/archive/refs/tags/v0.17.1.tar.gz
tar xf v0.17.1.tar.gz
rm -f v0.17.1.tar.gz
ln -s spack-0.17.1 spack-installation
# The following two lines are not needed if the package is found in spack's built-in repository.
cp -pr ${SPACK_EXTERNALS}/spack-repo-externals ./spack-repo-externals-local
sed -i 's/dunedaq-externals/dunedaq-externals-local/g' spack-repo-externals-local/repo.yaml
cat $SPACK_EXTERNALS/spack-0.17.1/etc/spack/defaults/config.yaml >|spack-0.17.1/etc/spack/defaults/config.yaml
cp $SPACK_EXTERNALS/spack-0.17.1/etc/spack/defaults/linux/compilers.yaml spack-0.17.1/etc/spack/defaults/linux/
source ${SPACK_EXTRAS}/spack-0.17.1/share/spack/setup-env.sh
cat <<EOT >| $SPACK_ROOT/etc/spack/defaults/repos.yaml
repos:
- ${SPACK_EXTRAS}/spack-repo-externals-local
- /cvmfs/dunedaq-development.opensciencegrid.org/spack-nightly/${NIGHTLY}/spack-repo
- ${SPACK_EXTERNALS}/spack-repo-externals
- \$spack/var/spack/repos/builtin
EOT
cat <<EOT >| $SPACK_ROOT/etc/spack/defaults/upstreams.yaml
upstreams:
spack-nightly:
install_tree: /cvmfs/dunedaq-development.opensciencegrid.org/spack-nightly/${NIGHTLY}/spack-0.17.1/opt/spack
spack-externals:
install_tree: ${SPACK_EXTERNALS}/spack-0.17.1/opt/spack
EOT
```
### Add new version of a package, `TRACE` for example
`package.py` for `trace` should be modified to the following (`${SPACK_EXTRAS}/spack-repo-externals-local/packages/trace/package.py`). It can be opened via `spack edit trace`.
Modifying `package.py` is not needed if the external pacakge is found in the spack built-in repository.
```python=
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from spack import *
import os
from spack.util.environment import EnvironmentModifications
class Trace(CMakePackage):
"""FIXME: Put a proper description of your package here."""
homepage = "https://github.com/art-daq/trace"
git = "https://github.com/art-daq/trace.git"
version('3.16.02', commit='570d91139f7277966ae5259b0a11d85f8574e5dc') # JCF, Sep-9-2021: v3_16_02 is used in the dunedaq-v2.8.0 suite
version('3.17.03', commit='a1c3d7db117e8d965a181a73cedf4d4e45144025') # DPF, May-10-2022: v3_17_03
patch('disable_cetmodules.diff', sha256='640816dfe077382bdb5345c8b5568c92e1ccb36274887e57241d826522ba5686', when='@3.16.02')
patch('install-exec.diff', sha256='882deacf74407e1c83fb88ae8b2d16286751a49096682e441dc53175268ddcd9', when='@3.16.02')
patch('install-scripts.diff', sha256='bac65a9fe92314596b18257583ad60cf0a5eab4baa34e7740fc16edde447bd9f', when='@3.16.02')
```
Run the following to install the new trace
```
# install the new version of trace
spack install --reuse trace@3.17.03%gcc@8.2.0
```
## Use packages in the local spack instance with the DUNE DAQ release
### Modify `daq-buildtools`
```bash=
git clone https://github.com/DUNE-DAQ/daq-buildtools
# edit scripts/dbt-setup-tools.sh
```
Change the `spack_setup_env` function in `dbt-setup-tools.sh` to use the setup script of `$SPACK_EXTRAS/spack-0.17.1/share/spack/setup-env.sh`.
### Load the extra packages
1. source the `env.sh` in the locally cloned `daq-buildtools` repo;
2. create a local workarea, and run `dbt-workarea-env` in it;
4. optional `spack unload <package>` to unload existing version of a package loaded by calling `dbt-workarea-evn`;
5. `spack load <package@newer_version>` to load the newer version of a package or a new external package;
7. Now the new package is ready to be used when you call `dbt-build`.