How to get tmux resurrect to restore neovim sessions

Hi All,

I’ve recently moved to NixOS, as part of my workflow I use both tmux and neovim.
On Arch I was able to restore my neovim sessions automatically using tmux resurrect (and continuum) plugins. However I cannot seem to get it to work correctly on NixOS, specifically to restore my nvim session.

My current tmux config:

Taking a look at my resurrect/last file:

# bat ~/.tmux/resurrect/last --plain

pane    dotfiles    0   1   :*  0   nvim ~/dotfiles :/home/haseeb/dotfiles  1   nvim    :/home/haseeb/.nix-profile/bin/nvim --cmd lua vim.g.loaded_node_provider=0;vim.g.loaded_perl_provider=0;vim.g.loaded_python_provider=0;vim.g.python3_host_prog='/nix/store/4n4d0f1xd14gl4pfymdcqb9pmagcyyfj-neovim-0.9.1/bin/nvim-python3';vim.g.ruby_host_prog='/nix/store/4n4d0f1xd14gl4pfymdcqb9pmagcyyfj-neovim-0.9.1/bin/nvim-ruby'

Is it trying to run /home/haseeb/.nix-profile/bin/nvim --cmd lua vim.g.loaded_node_provider=0;vim.g.loaded_perl_provider=0;vim.g.loaded_python_provider=0;vim.g.python3_host_prog='/nix/store/4n4d0f1xd14gl4pfymdcqb9pmagcyyfj-neovim-0.9.1/bin/nvim-python3';vim.g.ruby_host_prog='/nix/store/4n4d0f1xd14gl4pfymdcqb9pmagcyyfj-neovim-0.9.1/bin/nvim-ruby' ?

Has anyone got tmux resurrect to work with nvim on NixOS?

Thanks in advance for any help!

Related Issues:

I came across the same issue and the problem is with the way that tmux-resurrect saves the names of the process it later needs to resurrect, This issue is not specific to NixOS and is caused once the name of the process deviates from the one tmux-resurrect plugin expects when it parses its state file(file named last that points at some tmux_resurrect_*).

The workaround is to leverage a tmux-resurrect hook that will be triggered each time tmux state is saved. I ended adding the
following 4 lines to the configurations of the tmux-resurrect plugin
as will be in the generated .tmux.conf

set -g @resurrect-dir $resurrect_dir
set -g @resurrect-hook-post-save-all ‘target=$(readlink -f $resurrect_dir/last); sed “s| --cmd .*-vim-pack-dir||g; s|/etc/profiles/per-user/$USER/bin/||g” $target | sponge $target’

You can see the actual code in my repo


Hi thanks for getting back to me!

I added it:

set -g @resurrect-dir $resurrect_dir
set -g @resurrect-hook-post-save-all 'target=$(readlink -f $resurrect_dir/last); sed "s| --cmd .*-vim-pack-dir||g; s|/etc/profiles/per-user/$USER/bin/||g" $target | sponge $target'

I then created a session.vim file using :mksession but when I kill and start the tmux server again, it doesnt auto load nvim still :/.

Where my resurrect file looks like:

bat ~/.tmux/resurrect/last --plain
pane    dooit   0   1   :*  0   ~/.l/s/dooit    :/home/haseebmajid/.local/share/dooit   1   fish    :
pane    dotfiles    0   1   :*  0   nvim ~/dotfiles :/home/haseebmajid/dotfiles 1   nvim    :/home/haseebmajid/.nix-profile/bin/nvim
pane    dotfiles    1   0   :-  0   ~/dotfiles  :/home/haseebmajid/dotfiles 1   fish    :
pane    notes   0   1   :*  0   ~/notes :/home/haseebmajid/notes    0   fish    :
pane    notes   0   1   :*  1   ~/p/blog    :/home/haseebmajid/projects/blog    1   fish    :
window  dooit   0   :fish   1   :*  bd3d,309x72,0,0,0   :
window  dotfiles    0   :nvim   1   :*  babe,152x72,0,0,1   :
window  dotfiles    1   :fish   0   :-  babf,152x72,0,0,2   :
window  notes   0   :fish   1   :*  68da,309x72,0,0{154x72,0,0,3,154x72,155,0,4}    :

tmux: home-manager/programs/multiplexers/tmux.nix · bugs-gix · Haseeb Majid / dotfiles · GitLab

Any ideas what I’m missing ? Thanks

Are you failing to restore nvim or you are failing to restore nvim with its session? and what about other software such as “man” and htop?

I tried both man and htop. Initially htop was restored fine however man (and neovim) were not!

iMy resurrect file looked like:

pane    dotfiles    0   1   :*  0   nvim ~/dotfiles :/home/haseeb/dotfiles  0   nvim    :/home/haseeb/.nix-profile/bin/nvim
pane    dotfiles    0   1   :*  1   man cat ~/dotfiles  :/home/haseeb/dotfiles  1   man :/home/haseeb/.nix-profile/bin/man cat
pane    dotfiles    0   1   :*  2   htop ~/dotfiles :/home/haseeb/dotfiles  0   htop    :htop

So I manually changed it to remove the .nix-profiles folder and leave it like htop like so (scroll across to see the final column):

pane    dotfiles    0   1   :*  0   nvim ~/dotfiles :/home/haseeb/dotfiles  0   nvim    :nvim
pane    dotfiles    0   1   :*  1   man cat ~/dotfiles  :/home/haseeb/dotfiles  1   man :man cat
pane    dotfiles    0   1   :*  2   htop ~/dotfiles :/home/haseeb/dotfiles  0   htop    :htop

Then it worked!

EDIT: The following lines in my tmux config fixed it :slight_smile:

set -g @resurrect-dir $resurrect_dir
set -g @resurrect-hook-post-save-all 'target=$(readlink -f $resurrect_dir/last); sed "s| --cmd .*-vim-pack-dir||g; s|/etc/profiles/per-user/$USER/bin/||g; s|/home/$USER/.nix-profile/bin/||g" $target | sponge $target'