I'm trying to setup tmux using nix and home-manager on macOS.
However whenever I refresh the tmux config, I get the following errors:
'/nix/store/6iq9z3wnacxqhja3r93b7lsdl1kvcp11-tmuxplugin-sensible-unstable-2017-09-05/share/tmux-plugins/sensible/sensible.tmux' returned 127 [0/0]
'/nix/store/6iq9z3wnacxqhja3r93b7lsdl1kvcp11-tmuxplugin-sensible-unstable-2017-09-05/share/tmux-plugins/sensible/sensible.tmux' returned 127
'/nix/store/8cqfwlqfxp21fwbcvl8dyyahdm4klmxj-tmuxplugin-catppuccin-unstable-2024-05-15/share/tmux-plugins/catppuccin/catppuccin.tmux' returned 127
'/nix/store/87czlf8i2q2bzk1xikhx20d80g9kpdi9-tmuxplugin-resurrect-unstable-2022-05-01/share/tmux-plugins/resurrect/resurrect.tmux' returned 127
'/nix/store/aqs7gq94wd4ldbbsnrrm232jifbywwjy-tmuxplugin-continuum-unstable-2022-01-25/share/tmux-plugins/continuum/continuum.tmux' returned 127
'/nix/store/ixmqzdn5yck23fi1d824a04mvxkb7jk6-tmuxplugin-yank-unstable-2021-06-20/share/tmux-plugins/yank/yank.tmux' returned 127
I looked at the generated tmux.conf
file and found that there's several run-shell
commands such as the following:
# ============================================= #
# Start with defaults from the Sensible plugin #
# --------------------------------------------- #
run-shell /nix/store/6iq9z3wnacxqhja3r93b7lsdl1kvcp11-tmuxplugin-sensible-unstable-2017-09-05/share/tmux-plugins/sensible/sensible.tmux
# ============================================= #
These run-shell
commands match the programs with 127 errors in the tmux logs.
According to this GitHub issue, 127 errors means the program was not found. Howevern when I explicitly try running those programs or cat
them out, I see them.
So this tells me that for some reason I can manually run the generated programs, but tmux cannot.
I found this post: tmux run fish shell functions returns error 127. So I also tried running the generated .tmux
programs using /bin/sh
and could successfully run them there.
Here's my entire nix configuration for tmux.
{ pkgs, ... }:
{
programs.tmux = {
enable = true;
terminal = "tmux-256color";
historyLimit = 100000;
shell = "${pkgs.zsh}/bin/zsh";
plugins = with pkgs;
[
tmuxPlugins.sensible
{
plugin = tmuxPlugins.catppuccin;
extraConfig = ''
set-option -sa terminal-features "screen-256color,:RGB"
set -g @catppuccin_flavour 'mocha'
set -g @catppuccin_status_modules_right "session"
set -g @catppuccin_status_modules_left " "
set -g @catppuccin_status_fill "icon"
set -g @catppuccin_window_number_position "right"
set -g @catppuccin_window_left_separator ""
set -g @catppuccin_window_right_separator " "
set -g @catppuccin_window_middle_separator " █"
set -g @catppuccin_window_number_position "right"
set -g @catppuccin_window_default_fill "none"
set -g @catppuccin_window_default_text "#W"
set -g @catppuccin_window_current_fill "number"
set -g @catppuccin_window_current_text "#W"
set -g @catppuccin_pane_active_border_style "fg=#313244"
set -g status-bg "#11111b" # also duplicated at the bottom of the file
'';
}
{
plugin = tmuxPlugins.resurrect;
extraConfig = ''
set -g @resurrect-strategy-nvim 'session'
set -g @resurrect-capture-pane-contents 'on'
'';
}
{
plugin = tmuxPlugins.continuum;
extraConfig = ''
set -g @continuum-restore 'on'
set -g @continuum-boot 'on'
set -g @continuum-boot-options 'alacritty,fullscreen'
set -g @continuum-save-interval '5' # save every 5 minutes
'';
}
tmuxPlugins.yank
];
extraConfig = ''
#
# Keyboard shortcuts
#
# set the leader to control-a
set -g prefix C-a
unbind C-b
bind-key C-a send-prefix
# use \ to create horizontal panes
unbind %
bind '\' split-window -h
# use - to split the window horizontally
unbind '"'
bind - split-window -v
# resize panes
bind -r j resize-pane -D 5
bind -r k resize-pane -U 5
bind -r l resize-pane -R 5
bind -r h resize-pane -L 5
# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?|fzf)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'
tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'"
bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l
# set visual styling
set-option -sa terminal-features "screen-256color,:RGB"
set-option -g status-position top
# easily refresh tmux configuration
unbind r
bind r source-file ~/.config/tmux/tmux.conf
set -g status-bg "#11111b"
'';
};
}
Because of Yeshwanth's answer, I realized that I could try killing tmux and restarting it.
tmux kill-server
This fixed my problem. No idea why, but turning it off then on again often works.