2016-03-23 07:33:28 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
let
|
2023-03-19 20:44:31 +00:00
|
|
|
inherit (lib) mkOption mkIf types optionalString;
|
2016-03-23 07:33:28 +00:00
|
|
|
|
|
|
|
cfg = config.programs.tmux;
|
|
|
|
|
2016-03-31 15:22:17 +00:00
|
|
|
defaultKeyMode = "emacs";
|
|
|
|
defaultResize = 5;
|
|
|
|
defaultShortcut = "b";
|
|
|
|
defaultTerminal = "screen";
|
|
|
|
|
|
|
|
boolToStr = value: if value then "on" else "off";
|
|
|
|
|
|
|
|
tmuxConf = ''
|
|
|
|
set -g default-terminal "${cfg.terminal}"
|
|
|
|
set -g base-index ${toString cfg.baseIndex}
|
|
|
|
setw -g pane-base-index ${toString cfg.baseIndex}
|
2024-07-28 19:15:53 +00:00
|
|
|
set -g history-limit ${toString cfg.historyLimit}
|
2016-03-31 15:22:17 +00:00
|
|
|
|
2023-03-19 20:44:31 +00:00
|
|
|
${optionalString cfg.newSession "new-session"}
|
2016-03-31 15:22:17 +00:00
|
|
|
|
2023-03-19 20:44:31 +00:00
|
|
|
${optionalString cfg.reverseSplit ''
|
2016-03-31 15:22:17 +00:00
|
|
|
bind v split-window -h
|
|
|
|
bind s split-window -v
|
2023-03-19 20:44:31 +00:00
|
|
|
''}
|
2016-03-31 15:22:17 +00:00
|
|
|
|
|
|
|
set -g status-keys ${cfg.keyMode}
|
|
|
|
set -g mode-keys ${cfg.keyMode}
|
|
|
|
|
2023-03-19 20:44:31 +00:00
|
|
|
${optionalString (cfg.keyMode == "vi" && cfg.customPaneNavigationAndResize) ''
|
2016-03-31 15:22:17 +00:00
|
|
|
bind h select-pane -L
|
|
|
|
bind j select-pane -D
|
|
|
|
bind k select-pane -U
|
|
|
|
bind l select-pane -R
|
|
|
|
|
|
|
|
bind -r H resize-pane -L ${toString cfg.resizeAmount}
|
|
|
|
bind -r J resize-pane -D ${toString cfg.resizeAmount}
|
|
|
|
bind -r K resize-pane -U ${toString cfg.resizeAmount}
|
|
|
|
bind -r L resize-pane -R ${toString cfg.resizeAmount}
|
2023-03-19 20:44:31 +00:00
|
|
|
''}
|
2016-03-31 15:22:17 +00:00
|
|
|
|
2023-03-19 20:44:31 +00:00
|
|
|
${optionalString (cfg.shortcut != defaultShortcut) ''
|
2016-03-31 15:22:17 +00:00
|
|
|
# rebind main key: C-${cfg.shortcut}
|
|
|
|
unbind C-${defaultShortcut}
|
|
|
|
set -g prefix C-${cfg.shortcut}
|
|
|
|
bind ${cfg.shortcut} send-prefix
|
|
|
|
bind C-${cfg.shortcut} last-window
|
2023-03-19 20:44:31 +00:00
|
|
|
''}
|
2016-03-31 15:22:17 +00:00
|
|
|
|
|
|
|
setw -g aggressive-resize ${boolToStr cfg.aggressiveResize}
|
|
|
|
setw -g clock-mode-style ${if cfg.clock24 then "24" else "12"}
|
|
|
|
set -s escape-time ${toString cfg.escapeTime}
|
|
|
|
|
2023-03-22 09:07:15 +00:00
|
|
|
${cfg.extraConfigBeforePlugins}
|
|
|
|
|
2021-09-18 15:04:11 +00:00
|
|
|
${lib.optionalString (cfg.plugins != []) ''
|
|
|
|
# Run plugins
|
|
|
|
${lib.concatMapStringsSep "\n" (x: "run-shell ${x.rtp}") cfg.plugins}
|
|
|
|
|
|
|
|
''}
|
|
|
|
|
2020-02-06 23:29:36 +00:00
|
|
|
${cfg.extraConfig}
|
2016-03-31 15:22:17 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
2016-03-23 07:33:28 +00:00
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
programs.tmux = {
|
|
|
|
|
2017-12-07 21:26:36 +00:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whenever to configure {command}`tmux` system-wide.";
|
|
|
|
relatedPackages = [ "tmux" ];
|
|
|
|
};
|
2016-03-23 07:33:28 +00:00
|
|
|
|
2016-03-31 15:22:17 +00:00
|
|
|
aggressiveResize = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Resize the window to the size of the smallest session for which it is the current window.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
baseIndex = mkOption {
|
|
|
|
default = 0;
|
|
|
|
example = 1;
|
|
|
|
type = types.int;
|
|
|
|
description = "Base index for windows and panes.";
|
|
|
|
};
|
|
|
|
|
|
|
|
clock24 = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = "Use 24 hour clock.";
|
|
|
|
};
|
|
|
|
|
2016-07-28 11:10:42 +00:00
|
|
|
customPaneNavigationAndResize = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = "Override the hjkl and HJKL bindings for pane navigation and resizing in VI mode.";
|
|
|
|
};
|
|
|
|
|
2016-03-31 15:22:17 +00:00
|
|
|
escapeTime = mkOption {
|
|
|
|
default = 500;
|
|
|
|
example = 0;
|
|
|
|
type = types.int;
|
|
|
|
description = "Time in milliseconds for which tmux waits after an escape is input.";
|
|
|
|
};
|
|
|
|
|
2023-03-22 09:07:15 +00:00
|
|
|
extraConfigBeforePlugins = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Additional contents of /etc/tmux.conf, to be run before sourcing plugins.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
2020-02-06 23:29:36 +00:00
|
|
|
extraConfig = mkOption {
|
2016-03-23 07:33:28 +00:00
|
|
|
default = "";
|
|
|
|
description = ''
|
2023-03-22 09:07:15 +00:00
|
|
|
Additional contents of /etc/tmux.conf, to be run after sourcing plugins.
|
2016-03-23 07:33:28 +00:00
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
2016-03-31 15:22:17 +00:00
|
|
|
|
|
|
|
historyLimit = mkOption {
|
|
|
|
default = 2000;
|
|
|
|
example = 5000;
|
|
|
|
type = types.int;
|
|
|
|
description = "Maximum number of lines held in window history.";
|
|
|
|
};
|
|
|
|
|
|
|
|
keyMode = mkOption {
|
|
|
|
default = defaultKeyMode;
|
|
|
|
example = "vi";
|
|
|
|
type = types.enum [ "emacs" "vi" ];
|
|
|
|
description = "VI or Emacs style shortcuts.";
|
|
|
|
};
|
|
|
|
|
|
|
|
newSession = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = "Automatically spawn a session if trying to attach and none are running.";
|
|
|
|
};
|
|
|
|
|
|
|
|
reverseSplit = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = "Reverse the window split shortcuts.";
|
|
|
|
};
|
|
|
|
|
|
|
|
resizeAmount = mkOption {
|
|
|
|
default = defaultResize;
|
|
|
|
example = 10;
|
|
|
|
type = types.int;
|
|
|
|
description = "Number of lines/columns when resizing.";
|
|
|
|
};
|
|
|
|
|
|
|
|
shortcut = mkOption {
|
|
|
|
default = defaultShortcut;
|
|
|
|
example = "a";
|
|
|
|
type = types.str;
|
|
|
|
description = "Ctrl following by this key is used as the main shortcut.";
|
|
|
|
};
|
|
|
|
|
|
|
|
terminal = mkOption {
|
|
|
|
default = defaultTerminal;
|
|
|
|
example = "screen-256color";
|
|
|
|
type = types.str;
|
2023-04-16 21:56:55 +00:00
|
|
|
description = ''
|
|
|
|
Set the $TERM variable. Use tmux-direct if italics or 24bit true color
|
|
|
|
support is needed.
|
|
|
|
'';
|
2016-03-31 15:22:17 +00:00
|
|
|
};
|
2017-12-29 12:02:58 +00:00
|
|
|
|
|
|
|
secureSocket = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Store tmux socket under /run, which is more secure than /tmp, but as a
|
|
|
|
downside it doesn't survive user logout.
|
|
|
|
'';
|
|
|
|
};
|
2021-09-18 15:04:11 +00:00
|
|
|
|
|
|
|
plugins = mkOption {
|
|
|
|
default = [];
|
|
|
|
type = types.listOf types.package;
|
|
|
|
description = "List of plugins to install.";
|
|
|
|
example = lib.literalExpression "[ pkgs.tmuxPlugins.nord ]";
|
|
|
|
};
|
2022-11-13 21:21:50 +00:00
|
|
|
|
|
|
|
withUtempter = mkOption {
|
|
|
|
description = ''
|
|
|
|
Whether to enable libutempter for tmux.
|
|
|
|
This is required so that tmux can write to /var/run/utmp (which can be queried with `who` to display currently connected user sessions).
|
|
|
|
Note, this will add a guid wrapper for the group utmp!
|
|
|
|
'';
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
2016-03-23 07:33:28 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment = {
|
2016-03-31 15:22:17 +00:00
|
|
|
etc."tmux.conf".text = tmuxConf;
|
2016-05-27 07:57:12 +00:00
|
|
|
|
2021-09-18 15:04:11 +00:00
|
|
|
systemPackages = [ pkgs.tmux ] ++ cfg.plugins;
|
2016-05-27 07:57:12 +00:00
|
|
|
|
|
|
|
variables = {
|
2019-05-30 11:48:22 +00:00
|
|
|
TMUX_TMPDIR = lib.optional cfg.secureSocket ''''${XDG_RUNTIME_DIR:-"/run/user/$(id -u)"}'';
|
2016-05-27 07:57:12 +00:00
|
|
|
};
|
2016-03-23 07:33:28 +00:00
|
|
|
};
|
2022-11-13 21:21:50 +00:00
|
|
|
security.wrappers = mkIf cfg.withUtempter {
|
|
|
|
utempter = {
|
|
|
|
source = "${pkgs.libutempter}/lib/utempter/utempter";
|
|
|
|
owner = "root";
|
|
|
|
group = "utmp";
|
|
|
|
setuid = false;
|
|
|
|
setgid = true;
|
|
|
|
};
|
|
|
|
};
|
2016-03-23 07:33:28 +00:00
|
|
|
};
|
2020-02-06 23:29:36 +00:00
|
|
|
|
|
|
|
imports = [
|
|
|
|
(lib.mkRenamedOptionModule [ "programs" "tmux" "extraTmuxConf" ] [ "programs" "tmux" "extraConfig" ])
|
|
|
|
];
|
2024-08-01 11:35:37 +00:00
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ hxtmdev ];
|
2016-03-23 07:33:28 +00:00
|
|
|
}
|