Tmux
tmux is a "terminal multiplexer: it enables a number of terminals (or windows), each running a separate program, to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached."
Installation
Shell
To temporarily use tmux in a shell environment without modifying your system configuration, you can run:
$ nix-shell -p tmux
This makes the tmux available in your current shell. You can then launch tmux by typing tmux.
System setup
To install tmux system-wide, making it available to all users, add the following to your configuration:
environment.systemPackages = [
pkgs.tmux
];
Alternatively, enable the NixOS module to manage tmux declaratively:
programs.tmux.enable = true;
After rebuilding your system with nixos-rebuild switch, tmux will be installed and accessible.
Configuration
tmux can be configured globally from /etc/nixos/configuration.nix.
As an example:
programs.tmux = {
enable = true;
clock24 = true;
extraConfig = '' # used for less common options, intelligently combines if defined in multiple places.
...
'';
};
Note that extraConfig writes directly to /etc/tmux.conf
Using Plugins
Tmux plugins can be also configured using programs.tmux.plugins. They can be found as NixOS packages: tmuxPlugins. Each of the tmux plugin is run via run-shell automatically.
Some plugins need to be run after having had some custom configuration done>, but extraConfig gets executed after. For example tmuxPlugins.cpu needs the status line be declared before the plugin is run. For that scenario, run-shell can be added within extraConfig:
programs.tmux = {
enable = true;
extraConfig = ''
...
set -g status-right '#[fg=black,bg=color15] #{cpu_percentage} %H:%M '
run-shell ${pkgs.tmuxPlugins.cpu}/share/tmux-plugins/cpu/cpu.tmux
'';
};
Per-user configuration
However, if you want to configure per user, you could use Home Manager. This also grants you with more options available directly through nix, as opposed to through an extra config option. Though it should be noted that a few of the options have different names.