tmux-plugins / tmux-resurrect

Persists tmux environment across system restarts.
MIT License
10.99k stars 412 forks source link

Help me getting this to work on NixOS? #247

Open mkaito opened 6 years ago

mkaito commented 6 years ago

I'm not sure how to get this to work on NixOS, due to the way paths are handled on it.

I've got the following in my tmux.conf:

set -g @resurrect-processes '~nvim->nvim'

When I create a test session with just one pane and an nvim session, these are the contents of resurrect/last:

pane    mkaito/shell    1   :nvim   1   :*  1   :/home/chris    1   nvim    :/run/current-system/sw/bin/zsh -l
/nix/store/3z7jkdskc6k62q2s10pfjvkarnzgng9a-neovim-unwrapped-0.2.2/bin/nvim --cmd let g:python_host_prog='/nix/store/mflbq5vhr0hv277sdr0zi33w8b8lry7f-neovim/bin/nvim-python' --cmd let g:python3_host_prog='/nix/store/mflbq5vhr0hv277sdr0zi33w8b8lry7f-neovim/bin/nvim-python3' --cmd let g:ruby_host_prog='/nix/store/mflbq5vhr0hv277sdr0zi33w8b8lry7f-neovim/bin/nvim-ruby'
window  mkaito/shell    1   1   :*  b75d,234x52,0,0,0
state   mkaito/shell    

Which does not restore nvim. What am I doing wrong?

Of interest, might be this auto-generated wrapper that runs nvim on NixOS:

❮ cat $(which nvim)
#! /nix/store/zqh3l3lyw32q1ayb15bnvg9f24j5v2p0-bash-4.4-p12/bin/bash -e
unset PYTHONPATH
export PATH=$PATH${PATH:+':'}'/nix/store/nq3nnv6ylgqzfqqdrbaz835bjmrr5iyf-neovim-ruby-env/bin'
export GEM_HOME='/nix/store/nq3nnv6ylgqzfqqdrbaz835bjmrr5iyf-neovim-ruby-env/lib/ruby/gems/2.4.0'
exec "/nix/store/3z7jkdskc6k62q2s10pfjvkarnzgng9a-neovim-unwrapped-0.2.2/bin/nvim"   --cmd "let g:python_host_prog='/nix/store/mflbq5vhr0hv277sdr0zi33w8b8lry7f-neovim/bin/nvim-python'" --cmd "let g:python3_host_prog='/nix/store/mflbq5vhr0hv277sdr0zi33w8b8lry7f-neovim/bin/nvim-python3'" --cmd "let g:ruby_host_prog='/nix/store/mflbq5vhr0hv277sdr0zi33w8b8lry7f-neovim/bin/nvim-ruby'"  "${extraFlagsArray[@]}" "$@"
Soundtoxin commented 5 years ago

This also doesn't work on GuixSD, likely for the same reasons since the distros are similar. I haven't done anything advanced trying to get it to work. I just did my usual steps and noticed that the bind to save a session did nothing visually. Hopefully someone interested can get this working on both distros. I think they are the future of GNU/Linux, so I'd love it if I could carry over the workflow I'm used to.

austinbutler commented 3 years ago

This plugin works for me on NixOS with the following home-manager config:

{
  home-manager.users.austin = { pkgs, ... }: {
    programs.tmux = {
      enable = true;
      plugins = with pkgs.tmuxPlugins; [{
        plugin = resurrect;
        extraConfig = "set -g @resurrect-strategy-nvim 'session'";
      }];
    };
  };
}
Gediminas commented 1 year ago

For me this worked:

~/.tmux.conf

resurrect_dir="~/.local/share/tmux/resurrect"

set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @resurrect-strategy-vim 'session'
set -g @resurrect-strategy-nvim 'session'
set -g @resurrect-processes 'vim nvim hx cat less more tail watch'
set -g @resurrect-dir $resurrect_dir
set -g @resurrect-hook-post-save-all '~/.tmux/post_save.sh $resurrect_dir/last'

~/.tmux/post_save.sh

sed -ie "s| --cmd .*-vim-pack-dir||g" $1
sed -i 's|fish  :\[fish\] <defunct>|fish    :|g' $1
sed -i ':a;N;$!ba;s|\[fish\] <defunct>\n||g' $1
sed -i "s|/run/current-system/sw/bin/||g" $1
sed -i "s| $HOME| ~|g" $1
sed -ie "s|:bash .*/tmp/nix-shell-.*/rc|:nix-shell|g" $1
p3t33 commented 11 months ago

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 tmuxresurrect*).

I used a shorter version then the one suggested by @Gediminas , without the use of separate script and a bit safer with the use of "sponge".

    {
        plugin = resurrect;
        extraConfig = ''
          set -g @resurrect-capture-pane-contents 'on'

          resurrect_dir="$HOME/.tmux/resurrect"
          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'
        '';
    }