mirror of
https://github.com/nix-community/home-manager
synced 2024-12-30 13:49:47 +01:00
f4ebbcbf70
This commit adds the tmux program to Home Manager. In addition to configuring tmux, a user may specify tmux plugins from Nixpkgs. These can be included in the list of `plugins` and can either be a package (all tmux plugins live under `nixpkgs.tmuxPlugins.*`), or an object which includes the plugin and an `extraConfig`, which will be run immediately after sourcing the tmux plugin. Finally, this commit introduces two nested programs which may be enabled which depend on tmux: tmuxp and tmuxinator. These do not have the ability to be configured, although this may be a future contribution.
148 lines
4.1 KiB
Nix
148 lines
4.1 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.programs.tmux;
|
|
|
|
pluginName = p: if types.package.check p then p.name else p.plugin.name;
|
|
|
|
pluginModule = types.submodule {
|
|
options = {
|
|
plugin = mkOption {
|
|
type = types.package;
|
|
description = "Path of the configuration file to include.";
|
|
};
|
|
|
|
extraConfig = mkOption {
|
|
type = types.lines;
|
|
description = "Additional configuration for the associated plugin.";
|
|
default = "";
|
|
};
|
|
};
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
options = {
|
|
programs.tmux = {
|
|
enable = mkEnableOption "tmux";
|
|
|
|
package = mkOption {
|
|
type = types.package;
|
|
default = pkgs.tmux;
|
|
defaultText = "pkgs.tmux";
|
|
example = literalExample "pkgs.tmux";
|
|
description = "The tmux package to install";
|
|
};
|
|
|
|
sensibleOnTop = mkOption {
|
|
type = types.bool;
|
|
default = true;
|
|
description = ''
|
|
Run the sensible plugin at the top of the configuration. It
|
|
is possible to override the sensible settings using the
|
|
<option>programs.tmux.extraConfig</option> option.
|
|
'';
|
|
};
|
|
|
|
tmuxp.enable = mkEnableOption "tmuxp";
|
|
|
|
tmuxinator.enable = mkEnableOption "tmuxinator";
|
|
|
|
plugins = mkOption {
|
|
type = with types;
|
|
listOf (either package pluginModule)
|
|
// { description = "list of plugin packages or submodules"; };
|
|
description = ''
|
|
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 = [ ];
|
|
example = literalExample ''
|
|
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
|
|
''';
|
|
}
|
|
]
|
|
'';
|
|
};
|
|
|
|
extraConfig = mkOption {
|
|
type = types.lines;
|
|
default = "";
|
|
description = ''
|
|
Additional configuration to add to
|
|
<filename>tmux.conf</filename>.
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable (
|
|
mkMerge [
|
|
{
|
|
home.packages = [ cfg.package ]
|
|
++ optional cfg.tmuxinator.enable pkgs.tmuxinator
|
|
++ optional cfg.tmuxp.enable pkgs.tmuxp;
|
|
|
|
home.file.".tmux.conf".text = cfg.extraConfig;
|
|
}
|
|
|
|
(mkIf cfg.sensibleOnTop {
|
|
home.file.".tmux.conf".text = mkBefore ''
|
|
# ============================================= #
|
|
# Start with defaults from the Sensible plugin #
|
|
# --------------------------------------------- #
|
|
run-shell ${pkgs.tmuxPlugins.sensible.rtp}
|
|
# ============================================= #
|
|
'';
|
|
})
|
|
|
|
(mkIf (cfg.plugins != []) {
|
|
assertions = [(
|
|
let
|
|
hasBadPluginName = p: !(hasPrefix "tmuxplugin" (pluginName p));
|
|
badPlugins = filter hasBadPluginName cfg.plugins;
|
|
in
|
|
{
|
|
assertion = badPlugins == [];
|
|
message =
|
|
"Invalid tmux plugin (not prefixed with \"tmuxplugins\"): "
|
|
+ concatMapStringsSep ", " pluginName badPlugins;
|
|
}
|
|
)];
|
|
|
|
home.file.".tmux.conf".text = mkAfter ''
|
|
# ============================================= #
|
|
# Load plugins with Home Manager #
|
|
# --------------------------------------------- #
|
|
|
|
${(concatMapStringsSep "\n\n" (p: ''
|
|
# ${pluginName p}
|
|
# ---------------------
|
|
${p.extraConfig or ""}
|
|
run-shell ${
|
|
if types.package.check p
|
|
then p.rtp
|
|
else p.plugin.rtp
|
|
}
|
|
'') cfg.plugins)}
|
|
# ============================================= #
|
|
'';
|
|
})
|
|
]
|
|
);
|
|
}
|