Subject: [PATCH] gnu: add environment-modules

From: Ivan Gankevich <[email-masked]>
Date: Wed, 7 Jul 2021 11:59:33 +0300

---
 gnu/packages/parallel.scm | 64 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/gnu/packages/parallel.scm b/gnu/packages/parallel.scm
index 42826f49d6..f07ce02d33 100644
--- a/gnu/packages/parallel.scm
+++ b/gnu/packages/parallel.scm
@@ -41,8 +41,10 @@
   #:use-module (gnu packages admin)
   #:use-module (gnu packages autotools)
   #:use-module (gnu packages base)
+  #:use-module (gnu packages dejagnu)
   #:use-module (gnu packages flex)
   #:use-module (gnu packages freeipmi)
+  #:use-module (gnu packages less)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages mpi)
   #:use-module (gnu packages perl)
@@ -378,3 +380,65 @@ and output captured in the notebook.  Whatever arguments are accepted by a
 SLURM command line executable are also accepted by the corresponding magic
 command---e.g., @code{%salloc}, @code{%sbatch}, etc.")
       (license license:bsd-3))))
+
+(define-public environment-modules
+  (package
+    (name "environment-modules")
+    (version "4.7.1")
+    (source
+      (origin
+        (method url-fetch)
+        (uri (string-append "mirror://sourceforge/modules/Modules/modules-"
+                            version "/modules-" version ".tar.bz2"))
+        (sha256 (base32 "07r03vqskjxyjy5m2b6p2px42djnd2z1k4b5j9dxqv8prin01ax6"))))
+    (build-system gnu-build-system)
+    (arguments
+      `(#:configure-flags
+        (list (string-append "--with-bin-search-path="
+                             (assoc-ref %build-inputs "tcl") "/bin" ":"
+                             (assoc-ref %build-inputs "procps") "/bin" ":"
+                             (assoc-ref %build-inputs "less") "/bin" ":"
+                             (assoc-ref %build-inputs "coreutils") "/bin")
+              (string-append "--with-tcl=" (assoc-ref %build-inputs "tcl") "/lib")
+              "--disable-compat-version")
+        #:test-target "test"
+        #:phases
+        (modify-phases %standard-phases
+          (add-before 'configure 'patch-scripts-for-python-3
+            (lambda _
+              ;; patch the script for python-3
+              (substitute* "script/createmodule.py.in"
+                (("pathkeys.sort\\(\\)") "pathkeys = sorted(pathkeys)")
+                (("print\\(\"\\\\t\"\\*") "print(\"\\t\"*int")
+                (("@PYTHON@") (which "python3")))
+              #t))
+          (add-after 'configure 'patch-/bin/sh-in-tests
+            (lambda _
+              (for-each
+                (lambda (file)
+                  (substitute* file
+                    (("/bin/sh") (which "bash"))
+                    ;; For some reason "kvm" group cannot be resolved for
+                    ;; "nixbld" user. We remove "-n" switch here to not
+                    ;; resolve the groups at all.
+                    (("exec id -G -n -z") "exec id -G -z")
+                    (("exec id -G -n") "exec id -G")
+                    ))
+                '("testsuite/modules.00-init/005-init_ts.exp"
+                  "testsuite/install.00-init/005-init_ts.exp"))
+              #t)))))
+    (native-inputs
+      `(("dejagnu" ,dejagnu)
+        ("autoconf" ,autoconf)
+        ("which" ,which)))
+    (inputs
+      `(("tcl" ,tcl)
+        ("less" ,less)
+        ("procps" ,procps)
+        ("coreutils" ,coreutils)
+        ("python" ,python-3)))
+    (home-page "http://modules.sourceforge.net/")
+    (synopsis "Shell environment variables and aliases management")
+    (description "A tool that simplify shell initialization and lets users
+easily modify their environment during the session with modulefiles.")
+    (license license:gpl2+)))
-- 
2.32.0