home: tmux: add tmux service
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:
parent
3ec99d4c0e
commit
ac76d8ae68
|
@ -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";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue