home: tmux: add tmux service
All checks were successful
continuous-integration/drone/push Build is passing

The service definition is pretty awful, but it deals with the secure
socket correctly...

This avoids having a small lapse when starting the very first shell of a
session, which must first launch the server.
This commit is contained in:
Bruno BELANYI 2021-09-30 16:48:26 +02:00
parent 84cdc30037
commit cc21d84808

View file

@ -5,6 +5,10 @@ in
{
options.my.home.tmux = with lib.my; {
enable = mkDisableOption "tmux terminal multiplexer";
service = {
enable = mkDisableOption "tmux server service";
};
};
config.programs.tmux = lib.mkIf cfg.enable {
@ -44,4 +48,30 @@ in
bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel
'';
};
config.systemd.user.services.tmux = lib.mkIf cfg.service.enable {
Unit = {
Description = "tmux server";
};
Install = {
WantedBy = [ "default.target" ];
};
Service =
let
# Wrap `tmux` in a login shell and set the socket path
tmuxCmd = "${config.programs.tmux.package}/bin/tmux";
socketExport = lib.optionalString
config.programs.tmux.secureSocket
''export TMUX_TMPDIR=''${XDG_RUNTIME_DIR:-"/run/user/\$(id -u)"};'';
mkTmuxCommand =
c: "${pkgs.runtimeShell} -l -c '${socketExport} ${tmuxCmd} ${c}'";
in
{
Type = "forking";
ExecStart = mkTmuxCommand "new -d -s ambroisie";
ExecStop = mkTmuxCommand "kill-server";
};
};
}