When TRAMP runs a shell command on the remote host, it calls /bin/sh -c
. There doesn't seem to be a way to tell sh
to source any files at initialization when it is called like that. So let's instead configure TRAMP to call /bin/bash -c
. Then bash
will source BASH_ENV
, which we can point at a custom file that configures the modules.
So, first, configure TRAMP to use /bin/bash
. To do this, we need to modify the tramp-methods
variable. It's an alist, where the keys are strings denoting the connection type. I use the "scpx"
connection type, but you can change that to a whichever connection type you use.
(let ((scpx-method (cdr (assoc "scpx" tramp-methods))))
(add-to-list 'scpx-method '(tramp-remote-shell "/bin/bash"))
(add-to-list 'tramp-methods (cons "scpx" scpx-method)))
Then, we can configure tramp-remote-process-environment
to point at a file that will contain our module configuration.
(add-to-list 'tramp-remote-process-environment "BASH_ENV=~/.bash_env")
Then, open up the ~/.bash_env
file on the remote machine. You'll need to source the files that set up your module system. We use a different module system, so I'm not entirely sure what file you'll need, but perhaps you'll find it in /etc/profile.d
. Here's what my file contains:
source /etc/profile.d/z00_lmod.sh
module -q restore
Again, I'm not familiar with your module system, but that second line simply loads up my default set of modules.
Lastly, since the module system configures your PATH
, we need to get TRAMP to use it. By default, TRAMP just uses the contents of tramp-remote-path
. But if you add tramp-own-remote-path
, it will pull in the contents of PATH
.
(add-to-list 'tramp-remote-path 'tramp-own-remote-path)