Skip to content

Instantly share code, notes, and snippets.

@hartzell
Created January 16, 2019 23:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hartzell/5a759b79b73c9e435cf1b8e3fa0a7370 to your computer and use it in GitHub Desktop.
Save hartzell/5a759b79b73c9e435cf1b8e3fa0a7370 to your computer and use it in GitHub Desktop.
A script to initialize a user's environment to use a tree of Spack packages
# -*- mode: sh -*-
# vim: set ft=sh
#
# The typical user's .bash_profile would include:
#
# APPS_MODULES="emacs git htop the-silver-searcher" # and etc....
# source /moose/apps/init.sh
#
# Even setting APPS_MODULES is optional if user is ok with default list...
#
# That will:
#
# 1. Fetch the name of the "current" spack tree from the Well Known
# File if the user hasn't explicitly provided one.
# 2. Use the spack executable in that tree to ask for the location of
# the Lmod directory in that tree.
# 3. Load the Lmod bash initialization file from within that Lmod dir.
# 4. Tell Lmod to use the Core dir that spack built.
# 5. Tell Lmod to use our directory of handcrafted module files.
# 6. Load the core compiler module, which makes the bulk of the
# modulefiles accessible.
# 7. Load the user's modulefiles.
#
# There are a few things that users can customize:
# Common:
# APPS_MODULES - your list of modules to load
# e.g. APPS_MODULES="emacs git htop etc etc etc..."
# Less common:
# APPS_DIR - path to top of a Spack apps tree, e.g. a team specific tree
# (must include lmod)
# APPS_SPECIAL_MODULES_DIR - path to dir of snowflake modulefiles
# Uncommon:
# APPS_CORE_COMPILER - Compiler choice for lmod hierarch. scheme
#
_APPS_TOP_DIR=/moose/apps
APPS_DIR=${APPS_DIR:-$(cat ${_APPS_TOP_DIR}/spack/current)}
_APPS_SPACK_EXE=${APPS_DIR}/bin/spack
_APPS_LMOD_INIT_DIR=$(${_APPS_SPACK_EXE} location -i lmod)/lmod/lmod/init
_APPS_LMOD_CORE_DIR=${APPS_DIR}/share/spack/lmod/linux-centos7-x86_64/Core
# The special modules are handled separately.
APPS_SPECIAL_MODULES_DIR=${APPS_SPECIAL_MODULES_DIR-${_APPS_TOP_DIR}/modulefiles}
# modules to load, core compiler will determine what's available
APPS_CORE_COMPILER=${APPS_CORE_COMPILER:-gcc}
APPS_MODULES=${APPS_MODULES:-"emacs git htop the-silver-searcher tree vim"}
# set up an empty MANPATH, so that when lmod adds to it we can still
# access the system man pages.
if [[ -z ${MANPATH:-} ]]; then
export MANPATH=":"
fi
# only do the full setup first time through
if [[ -z ${_INIT_LMOD:-} ]]; then
export _INIT_LMOD=1
export BASH_ENV=${_APPS_LMOD_INIT_DIR}/bash
source ${BASH_ENV} # load the init file into this shell
module use ${_APPS_LMOD_CORE_DIR} # hook up the Core modules directory
module use ${APPS_SPECIAL_MODULES_DIR} # and one for the special snowflakes
module load ${APPS_CORE_COMPILER}
module load ${APPS_MODULES}
else # otherwise just refresh things
source ${BASH_ENV}
module refresh
fi
# end of apps tree setup bits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment