2023-10-02 06:26:11 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2023-07-20 02:40:04 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.wezterm-mux-server;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.wezterm-mux-server = {
|
|
|
|
enable = lib.mkEnableOption "Wezterm mux server";
|
2023-07-28 00:35:07 +00:00
|
|
|
|
2023-07-20 02:40:04 +00:00
|
|
|
package = lib.mkOption {
|
|
|
|
type = lib.types.package;
|
2023-07-27 03:13:39 +00:00
|
|
|
description = ''
|
2023-07-20 02:40:04 +00:00
|
|
|
The package containing the {command}`wezterm-mux-server` binary.
|
|
|
|
'';
|
|
|
|
default = pkgs.wezterm;
|
|
|
|
defaultText = "pkgs.wezterm";
|
|
|
|
};
|
2023-07-28 00:35:07 +00:00
|
|
|
|
2023-07-20 02:40:04 +00:00
|
|
|
configFile = lib.mkOption {
|
|
|
|
type = with lib.types; nullOr path;
|
2023-07-27 03:13:39 +00:00
|
|
|
description = ''
|
2023-07-20 02:40:04 +00:00
|
|
|
The path to the configuration file. For more information, you can see
|
|
|
|
[its section for setting up multiplexing](https://wezfurlong.org/wezterm/multiplexing.html).
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
defaultText = "null";
|
|
|
|
example = lib.literalExpression "./wezterm-mux-server.lua";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
systemd.services.wezterm-mux-server = {
|
|
|
|
description = "Wezterm mux server";
|
2024-08-21 10:11:31 +00:00
|
|
|
after = [ "network-online.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
2023-10-14 03:05:46 +00:00
|
|
|
path = [ cfg.package ];
|
|
|
|
|
2023-07-27 05:35:38 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2023-10-14 03:05:46 +00:00
|
|
|
script = ''
|
|
|
|
wezterm-mux-server ${lib.optionalString (cfg.configFile != null) "--config-file ${cfg.configFile}"}
|
|
|
|
'';
|
2023-07-20 02:40:04 +00:00
|
|
|
|
|
|
|
# Give it some tough love.
|
|
|
|
serviceConfig = {
|
2023-10-14 03:05:17 +00:00
|
|
|
User = config.users.users.wezterm.name;
|
|
|
|
Group = config.users.groups.wezterm.name;
|
2023-10-14 03:05:46 +00:00
|
|
|
UMask = "0077";
|
|
|
|
|
|
|
|
Restart = "on-failure";
|
2023-07-20 02:40:04 +00:00
|
|
|
|
|
|
|
LockPersonality = true;
|
|
|
|
NoNewPrivileges = true;
|
2023-10-14 03:05:46 +00:00
|
|
|
PrivateTmp = true;
|
|
|
|
ProcSubset = "pid";
|
2023-07-20 02:40:04 +00:00
|
|
|
ProtectClock = true;
|
2023-10-14 03:05:46 +00:00
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHostname = true;
|
2023-07-20 02:40:04 +00:00
|
|
|
ProtectKernelLogs = true;
|
2023-07-27 14:21:30 +00:00
|
|
|
ProtectKernelModules = true;
|
2023-10-14 03:05:46 +00:00
|
|
|
ProtectKernelTunables = true;
|
2023-07-20 02:40:04 +00:00
|
|
|
ProtectProc = "invisible";
|
2023-10-14 03:05:46 +00:00
|
|
|
ProtectSystem = "strict";
|
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
|
|
|
"~@cpu-emulation"
|
|
|
|
"~@keyring"
|
|
|
|
"~@module"
|
|
|
|
"~@privileged"
|
|
|
|
];
|
|
|
|
SystemCallErrorNumber = "EPERM";
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
2023-07-27 14:21:30 +00:00
|
|
|
|
2023-10-14 03:05:46 +00:00
|
|
|
WorkingDirectory = config.users.users.wezterm.home;
|
2023-07-27 14:21:30 +00:00
|
|
|
StateDirectory = "wezterm";
|
2023-10-14 03:05:46 +00:00
|
|
|
RuntimeDirectory = "wezterm";
|
2023-07-20 02:40:04 +00:00
|
|
|
|
|
|
|
# Restricting what capabilities this service has.
|
2023-10-06 05:48:12 +00:00
|
|
|
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
|
2023-07-20 02:40:04 +00:00
|
|
|
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
|
|
|
|
|
|
|
|
# Restrict what address families this service can interact with.
|
|
|
|
# Wezterm mux server mostly expects it to interact with the internet
|
|
|
|
# families and makes use of Unix sockets.
|
|
|
|
RestrictAddressFamilies = [
|
|
|
|
# Practically required as it uses Unix sockets.
|
|
|
|
"AF_LOCAL"
|
|
|
|
|
|
|
|
# The internet class families.
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
];
|
|
|
|
|
|
|
|
# Restrict what namespaces it can create which is none.
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
};
|
|
|
|
};
|
2023-10-14 03:05:17 +00:00
|
|
|
|
|
|
|
users.users.wezterm = {
|
|
|
|
description = "Wezterm system user";
|
|
|
|
home = "/var/lib/wezterm";
|
|
|
|
createHome = true;
|
|
|
|
group = config.users.groups.wezterm.name;
|
|
|
|
isSystemUser = true;
|
2023-11-12 02:52:04 +00:00
|
|
|
shell = pkgs.runtimeShell;
|
2023-10-14 03:05:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.wezterm = { };
|
2023-07-20 02:40:04 +00:00
|
|
|
};
|
|
|
|
}
|