Nix-shell + tmux workflow---preserve environment variables from shellHook?


I’m trying to figure out the best way to use tmux with nix-shell --pure so I don’t have to use multiple terminals and download dependencies multiple times.

The reason for the multiple dependency downloads is a very specific node setup that I can’t seem to get right with node2nix because of some webpack + electron issues. This means each invocation of nix-shell runs npm install and then the shellHook sets some environment variables that I need tmux to recognize.

Does anyone have any recommendations for how to get tmux to pick up the whole environment setup by nix-shell whenever I open a new pane? I don’t have a lot of tmux experience and after a good deal of searching I’m still a bit lost when it comes to making it play nicely with this nix-shell workflow.



Hello i know it’s been a while, but in case of other people or stumbling on this problem.
I did a script bash that is invoke in the shellHook of a nix-shell to launch my tmux configuration and the option that let me inherit the shell variable was the -L

> tmux -L # make it able to inherit the shell variable

It’s the first line that help, i can’t really explain why, i am new to tmux and was just trying to finaly make it works.



sessioExist=$(tmux list-sessions | grep $session)

if [ "$sessioExist" != "" ]; then
    tmux kill-session -t $session

tmux -L # make it able to inherit the shell variable

tmux new-session -d -s $session
tmux set -g mouse on
tmux set -g mouse-select-window on

tmux split-window -h -t $session:$window.0
tmux split-window -v -t $session:$window.0
tmux split-window -v -t $session:$window.1

tmux attach-session -t $session

And it is called for example like this in a nix file:

stdenv.mkDerivation {
  name = "nodejs-env";
  [do all the things you need in your shell]
shellHook = ''