diff --git a/install_spack_env.sh b/install_spack_env.sh
index e0cd249fb03a773041a8113f80081f69ba6a0a56..4917a134e2f1b46d329a63fc59179e521245367b 100644
--- a/install_spack_env.sh
+++ b/install_spack_env.sh
@@ -48,10 +48,12 @@ fi
 
 if [[ $UPSTREAM_INSTANCE ]]
 then
+  UPSTREAM_PREFIX=$(find $UPSTREAM_INSTANCE/spack/opt/spack/ -type d -name ".spack-db" 2>/dev/null | xargs -I {} dirname {})
+  echo $UPSTREAM_PREFIX
   cat <<EOF > ${CI_SPACK_ROOT}/etc/spack/defaults/upstreams.yaml
 upstreams:
   upstream-spack-instance:
-    install_tree: $UPSTREAM_INSTANCE/spack/opt/spack
+    install_tree: $UPSTREAM_PREFIX
 EOF
 fi