aboutsummaryrefslogtreecommitdiff
path: root/modules/programs/tmux.nix
diff options
context:
space:
mode:
authorSam Stites <sam@stites.io>2018-09-14 12:14:39 -0400
committerRobert Helgesson <robert@rycee.net>2018-11-14 00:08:39 +0100
commitf4ebbcbf707e10b17bf450272dba3bad2c885e6f (patch)
tree39175a54653bb811a194a8d37cf1a6eacf3b10aa /modules/programs/tmux.nix
parent36ecad6cbefe2690ec0599f88f1c98e1aa662d6f (diff)
tmux: add module
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.
Diffstat (limited to 'modules/programs/tmux.nix')
-rw-r--r--modules/programs/tmux.nix148
1 files changed, 148 insertions, 0 deletions
diff --git a/modules/programs/tmux.nix b/modules/programs/tmux.nix
new file mode 100644
index 00000000000..050168bedc8
--- /dev/null
+++ b/modules/programs/tmux.nix
@@ -0,0 +1,148 @@
+{ 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)}
+ # ============================================= #
+ '';
+ })
+ ]
+ );
+}