2018-09-14 16:14:39 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.tmux;
|
|
|
|
|
2020-04-25 12:40:32 +00:00
|
|
|
pluginName = p: if types.package.check p then p.pname else p.plugin.pname;
|
2018-09-14 16:14:39 +00:00
|
|
|
|
|
|
|
pluginModule = types.submodule {
|
|
|
|
options = {
|
|
|
|
plugin = mkOption {
|
|
|
|
type = types.package;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Path of the configuration file to include.";
|
2018-09-14 16:14:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Additional configuration for the associated plugin.";
|
2018-09-14 16:14:39 +00:00
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-10-31 09:24:01 +00:00
|
|
|
defaultKeyMode = "emacs";
|
|
|
|
defaultResize = 5;
|
2019-02-10 01:19:56 +00:00
|
|
|
defaultShortcut = "b";
|
|
|
|
defaultTerminal = "screen";
|
2021-10-31 09:24:01 +00:00
|
|
|
defaultShell = null;
|
2019-02-10 01:19:56 +00:00
|
|
|
|
|
|
|
boolToStr = value: if value then "on" else "off";
|
|
|
|
|
|
|
|
tmuxConf = ''
|
2020-04-25 15:02:49 +00:00
|
|
|
${optionalString cfg.sensibleOnTop ''
|
|
|
|
# ============================================= #
|
|
|
|
# Start with defaults from the Sensible plugin #
|
|
|
|
# --------------------------------------------- #
|
|
|
|
run-shell ${pkgs.tmuxPlugins.sensible.rtp}
|
|
|
|
# ============================================= #
|
|
|
|
''}
|
2019-02-10 01:19:56 +00:00
|
|
|
set -g default-terminal "${cfg.terminal}"
|
|
|
|
set -g base-index ${toString cfg.baseIndex}
|
|
|
|
setw -g pane-base-index ${toString cfg.baseIndex}
|
2019-10-15 02:23:32 +00:00
|
|
|
${optionalString (cfg.shell != null) ''
|
|
|
|
# We need to set default-shell before calling new-session
|
|
|
|
set -g default-shell "${cfg.shell}"
|
|
|
|
''}
|
2019-02-10 01:19:56 +00:00
|
|
|
${optionalString cfg.newSession "new-session"}
|
|
|
|
|
|
|
|
${optionalString cfg.reverseSplit ''
|
2022-03-19 23:12:21 +00:00
|
|
|
bind -N "Split the pane into two, left and right" v split-window -h
|
|
|
|
bind -N "Split the pane into two, top and bottom" s split-window -v
|
2019-02-10 01:19:56 +00:00
|
|
|
''}
|
|
|
|
|
|
|
|
set -g status-keys ${cfg.keyMode}
|
|
|
|
set -g mode-keys ${cfg.keyMode}
|
|
|
|
|
2021-10-31 09:24:01 +00:00
|
|
|
${optionalString
|
|
|
|
(cfg.keyMode == "vi" && cfg.customPaneNavigationAndResize) ''
|
2022-03-21 22:25:36 +00:00
|
|
|
bind -N "Select pane to the left of the active pane" h select-pane -L
|
|
|
|
bind -N "Select pane below the active pane" j select-pane -D
|
|
|
|
bind -N "Select pane above the active pane" k select-pane -U
|
|
|
|
bind -N "Select pane to the right of the active pane" l select-pane -R
|
2022-03-19 23:12:21 +00:00
|
|
|
|
|
|
|
bind -r -N "Resize the pane left by ${toString cfg.resizeAmount}" \
|
|
|
|
H resize-pane -L ${toString cfg.resizeAmount}
|
|
|
|
bind -r -N "Resize the pane down by ${toString cfg.resizeAmount}" \
|
|
|
|
J resize-pane -D ${toString cfg.resizeAmount}
|
|
|
|
bind -r -N "Resize the pane up by ${toString cfg.resizeAmount}" \
|
|
|
|
K resize-pane -U ${toString cfg.resizeAmount}
|
|
|
|
bind -r -N "Resize the pane right by ${toString cfg.resizeAmount}" \
|
|
|
|
L resize-pane -R ${toString cfg.resizeAmount}
|
2019-02-10 01:19:56 +00:00
|
|
|
''}
|
|
|
|
|
2021-10-31 09:24:01 +00:00
|
|
|
${if cfg.prefix != null then ''
|
|
|
|
# rebind main key: ${cfg.prefix}
|
|
|
|
unbind C-${defaultShortcut}
|
|
|
|
set -g prefix ${cfg.prefix}
|
2022-03-19 23:12:21 +00:00
|
|
|
bind -N "Send the prefix key through to the application" \
|
|
|
|
${cfg.prefix} send-prefix
|
2021-10-31 09:24:01 +00:00
|
|
|
'' else
|
|
|
|
optionalString (cfg.shortcut != defaultShortcut) ''
|
|
|
|
# rebind main key: C-${cfg.shortcut}
|
|
|
|
unbind C-${defaultShortcut}
|
|
|
|
set -g prefix C-${cfg.shortcut}
|
2022-03-19 23:12:21 +00:00
|
|
|
bind -N "Send the prefix key through to the application" \
|
|
|
|
${cfg.shortcut} send-prefix
|
2021-10-31 09:24:01 +00:00
|
|
|
bind C-${cfg.shortcut} last-window
|
|
|
|
''}
|
2019-02-10 01:19:56 +00:00
|
|
|
|
2019-06-04 11:21:20 +00:00
|
|
|
${optionalString cfg.disableConfirmationPrompt ''
|
2022-03-19 23:12:21 +00:00
|
|
|
bind-key -N "Kill the current window" & kill-window
|
|
|
|
bind-key -N "Kill the current pane" x kill-pane
|
2019-06-04 11:21:20 +00:00
|
|
|
''}
|
|
|
|
|
2023-02-05 10:02:14 +00:00
|
|
|
set -g mouse ${boolToStr cfg.mouse}
|
2019-02-10 01:19:56 +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}
|
|
|
|
set -g history-limit ${toString cfg.historyLimit}
|
|
|
|
'';
|
|
|
|
|
2020-04-25 15:02:49 +00:00
|
|
|
configPlugins = {
|
2021-10-31 09:24:01 +00:00
|
|
|
assertions = [
|
|
|
|
(let
|
2020-04-25 15:02:49 +00:00
|
|
|
hasBadPluginName = p: !(hasPrefix "tmuxplugin" (pluginName p));
|
|
|
|
badPlugins = filter hasBadPluginName cfg.plugins;
|
2021-10-31 09:24:01 +00:00
|
|
|
in {
|
|
|
|
assertion = badPlugins == [ ];
|
|
|
|
message = ''Invalid tmux plugin (not prefixed with "tmuxplugins"): ''
|
|
|
|
+ concatMapStringsSep ", " pluginName badPlugins;
|
|
|
|
})
|
|
|
|
];
|
2020-04-25 15:02:49 +00:00
|
|
|
|
2021-04-23 07:25:13 +00:00
|
|
|
xdg.configFile."tmux/tmux.conf".text = ''
|
2020-04-25 15:02:49 +00:00
|
|
|
# ============================================= #
|
|
|
|
# Load plugins with Home Manager #
|
|
|
|
# --------------------------------------------- #
|
|
|
|
|
|
|
|
${(concatMapStringsSep "\n\n" (p: ''
|
2021-10-31 09:24:01 +00:00
|
|
|
# ${pluginName p}
|
|
|
|
# ---------------------
|
|
|
|
${p.extraConfig or ""}
|
|
|
|
run-shell ${if types.package.check p then p.rtp else p.plugin.rtp}
|
2020-04-25 15:02:49 +00:00
|
|
|
'') cfg.plugins)}
|
|
|
|
# ============================================= #
|
|
|
|
'';
|
|
|
|
};
|
2018-09-14 16:14:39 +00:00
|
|
|
|
2021-10-31 09:24:01 +00:00
|
|
|
in {
|
2018-09-14 16:14:39 +00:00
|
|
|
options = {
|
|
|
|
programs.tmux = {
|
2019-02-10 01:19:56 +00:00
|
|
|
aggressiveResize = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2019-02-10 01:19:56 +00:00
|
|
|
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.ints.unsigned;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Base index for windows and panes.";
|
2019-02-10 01:19:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
clock24 = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Use 24 hour clock.";
|
2019-02-10 01:19:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
customPaneNavigationAndResize = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2019-02-10 01:19:56 +00:00
|
|
|
Override the hjkl and HJKL bindings for pane navigation and
|
|
|
|
resizing in VI mode.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-06-04 11:21:20 +00:00
|
|
|
disableConfirmationPrompt = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2019-06-04 11:21:20 +00:00
|
|
|
Disable confirmation prompt before killing a pane or window
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-07-01 23:45:18 +00:00
|
|
|
enable = mkEnableOption "tmux";
|
2018-09-14 16:14:39 +00:00
|
|
|
|
2019-02-10 01:19:56 +00:00
|
|
|
escapeTime = mkOption {
|
|
|
|
default = 500;
|
|
|
|
example = 0;
|
|
|
|
type = types.ints.unsigned;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2019-02-10 01:19:56 +00:00
|
|
|
Time in milliseconds for which tmux waits after an escape is
|
|
|
|
input.
|
2021-10-31 09:24:01 +00:00
|
|
|
'';
|
2019-02-10 01:19:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2019-02-10 01:19:56 +00:00
|
|
|
Additional configuration to add to
|
2023-06-30 23:30:13 +00:00
|
|
|
{file}`tmux.conf`.
|
2019-02-10 01:19:56 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
historyLimit = mkOption {
|
|
|
|
default = 2000;
|
|
|
|
example = 5000;
|
|
|
|
type = types.ints.positive;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Maximum number of lines held in window history.";
|
2019-02-10 01:19:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
keyMode = mkOption {
|
|
|
|
default = defaultKeyMode;
|
|
|
|
example = "vi";
|
|
|
|
type = types.enum [ "emacs" "vi" ];
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "VI or Emacs style shortcuts.";
|
2019-02-10 01:19:56 +00:00
|
|
|
};
|
|
|
|
|
2023-07-01 23:45:18 +00:00
|
|
|
mouse = mkEnableOption "mouse support";
|
2023-02-05 10:02:14 +00:00
|
|
|
|
2019-02-10 01:19:56 +00:00
|
|
|
newSession = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2019-02-10 01:19:56 +00:00
|
|
|
Automatically spawn a session if trying to attach and none
|
|
|
|
are running.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-09-14 16:14:39 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.tmux;
|
2021-10-09 09:14:08 +00:00
|
|
|
defaultText = literalExpression "pkgs.tmux";
|
|
|
|
example = literalExpression "pkgs.tmux";
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "The tmux package to install";
|
2018-09-14 16:14:39 +00:00
|
|
|
};
|
|
|
|
|
2019-02-10 01:19:56 +00:00
|
|
|
reverseSplit = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Reverse the window split shortcuts.";
|
2019-02-10 01:19:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
resizeAmount = mkOption {
|
|
|
|
default = defaultResize;
|
|
|
|
example = 10;
|
|
|
|
type = types.ints.positive;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Number of lines/columns when resizing.";
|
2019-02-10 01:19:56 +00:00
|
|
|
};
|
|
|
|
|
2018-09-14 16:14:39 +00:00
|
|
|
sensibleOnTop = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2018-09-14 16:14:39 +00:00
|
|
|
Run the sensible plugin at the top of the configuration. It
|
|
|
|
is possible to override the sensible settings using the
|
2023-06-30 23:30:13 +00:00
|
|
|
{option}`programs.tmux.extraConfig` option.
|
2018-09-14 16:14:39 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-05-20 13:23:00 +00:00
|
|
|
prefix = mkOption {
|
|
|
|
default = null;
|
|
|
|
example = "C-a";
|
|
|
|
type = types.nullOr types.str;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2020-05-20 13:23:00 +00:00
|
|
|
Set the prefix key. Overrules the "shortcut" option when set.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-02-10 01:19:56 +00:00
|
|
|
shortcut = mkOption {
|
|
|
|
default = defaultShortcut;
|
|
|
|
example = "a";
|
|
|
|
type = types.str;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2019-02-10 01:19:56 +00:00
|
|
|
CTRL following by this key is used as the main shortcut.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
terminal = mkOption {
|
|
|
|
default = defaultTerminal;
|
|
|
|
example = "screen-256color";
|
|
|
|
type = types.str;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Set the $TERM variable.";
|
2019-02-10 01:19:56 +00:00
|
|
|
};
|
|
|
|
|
2019-10-15 02:23:32 +00:00
|
|
|
shell = mkOption {
|
|
|
|
default = defaultShell;
|
|
|
|
example = "\${pkgs.zsh}/bin/zsh";
|
|
|
|
type = with types; nullOr str;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Set the default-shell tmux variable.";
|
2019-10-15 02:23:32 +00:00
|
|
|
};
|
|
|
|
|
2019-02-10 01:19:56 +00:00
|
|
|
secureSocket = mkOption {
|
2020-06-21 09:20:00 +00:00
|
|
|
default = pkgs.stdenv.isLinux;
|
2019-02-10 01:19:56 +00:00
|
|
|
type = types.bool;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2023-06-30 23:30:13 +00:00
|
|
|
Store tmux socket under {file}`/run`, which is more
|
|
|
|
secure than {file}`/tmp`, but as a downside it doesn't
|
2019-02-10 01:19:56 +00:00
|
|
|
survive user logout.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-07-01 23:45:18 +00:00
|
|
|
tmuxp.enable = mkEnableOption "tmuxp";
|
2018-09-14 16:14:39 +00:00
|
|
|
|
2023-07-01 23:45:18 +00:00
|
|
|
tmuxinator.enable = mkEnableOption "tmuxinator";
|
2018-09-14 16:14:39 +00:00
|
|
|
|
|
|
|
plugins = mkOption {
|
|
|
|
type = with types;
|
2021-10-31 09:24:01 +00:00
|
|
|
listOf (either package pluginModule) // {
|
|
|
|
description = "list of plugin packages or submodules";
|
|
|
|
};
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2018-09-14 16:14:39 +00:00
|
|
|
List of tmux plugins to be included at the end of your tmux
|
|
|
|
configuration. The sensible plugin, however, is defaulted to
|
|
|
|
run at the top of your configuration.
|
|
|
|
'';
|
|
|
|
default = [ ];
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2018-09-14 16:14:39 +00:00
|
|
|
with pkgs; [
|
|
|
|
tmuxPlugins.cpu
|
|
|
|
{
|
|
|
|
plugin = tmuxPlugins.resurrect;
|
|
|
|
extraConfig = "set -g @resurrect-strategy-nvim 'session'";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
plugin = tmuxPlugins.continuum;
|
|
|
|
extraConfig = '''
|
|
|
|
set -g @continuum-restore 'on'
|
|
|
|
set -g @continuum-save-interval '60' # minutes
|
|
|
|
''';
|
|
|
|
}
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-10-31 09:24:01 +00:00
|
|
|
config = mkIf cfg.enable (mkMerge ([
|
|
|
|
{
|
|
|
|
home.packages = [ cfg.package ]
|
|
|
|
++ optional cfg.tmuxinator.enable pkgs.tmuxinator
|
|
|
|
++ optional cfg.tmuxp.enable pkgs.tmuxp;
|
|
|
|
}
|
|
|
|
|
|
|
|
{ xdg.configFile."tmux/tmux.conf".text = mkBefore tmuxConf; }
|
|
|
|
{ xdg.configFile."tmux/tmux.conf".text = mkAfter cfg.extraConfig; }
|
|
|
|
|
|
|
|
(mkIf cfg.secureSocket {
|
|
|
|
home.sessionVariables = {
|
2023-02-05 10:22:41 +00:00
|
|
|
TMUX_TMPDIR = ''''${XDG_RUNTIME_DIR:-"/run/user/$(id -u)"}'';
|
2021-10-31 09:24:01 +00:00
|
|
|
};
|
|
|
|
})
|
2019-04-04 22:04:24 +00:00
|
|
|
|
2021-10-31 09:24:01 +00:00
|
|
|
(mkIf (cfg.plugins != [ ]) configPlugins)
|
|
|
|
]));
|
2018-09-14 16:14:39 +00:00
|
|
|
}
|