From a62b2ce19dcf6a600964cf6c653fb34724cb3d99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eric=20M=C3=BCller?= <mueller@kip.uni-heidelberg.de>
Date: Mon, 29 Jul 2024 16:45:58 +0200
Subject: [PATCH] fix: generate_modules.sh for non-apptainer builds

Change-Id: I8bef8290fd95908d16630e8239830d26c3b01b2d
---
 lib/yashchiki/generate_modules.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/yashchiki/generate_modules.sh b/lib/yashchiki/generate_modules.sh
index 84a020ce..83bfe28f 100755
--- a/lib/yashchiki/generate_modules.sh
+++ b/lib/yashchiki/generate_modules.sh
@@ -33,7 +33,7 @@ source "${PATH_MODULES}/\$(readlink -f /proc/\$\$/exe | xargs -r basename)"
 EOF
 
 # Provide MODULESHOME for all singularity environments
-cat <<EOF >> ${SINGULARITY_ENVIRONMENT}
+cat <<EOF >> ${SINGULARITY_ENVIRONMENT:-/environment.sh}
 MODULESHOME=${MODULESHOME}
 export MODULESHOME
 EOF
@@ -42,9 +42,11 @@ EOF
 # to use after sourcing /opt/init/modules.sh
 (
 IFS=$'\n'
+if [ -d "/opt/spack/share/spack/modules" ]; then
 for moduledir in $(find /opt/spack/share/spack/modules -mindepth 1 -maxdepth 1 -type d); do
 cat <<EOF >> "${TARGET}"
 export MODULEPATH="${moduledir}\${MODULEPATH:+:\${MODULEPATH}}"
 EOF
 done
+fi
 )
-- 
GitLab