blob: 21e6128c7226ab1e443d3a671ec7105f2971dcfa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
{ lib, pkgs, config, ... }:
let
TCPPorts = [21115 21116 21117 21118 21119];
UDPPorts = [21116];
in {
options.services.rustdesk-server = with lib; with types; {
enable = mkEnableOption "RustDesk, a remote access and remote control software, allowing maintenance of computers and other devices.";
package = mkPackageOption pkgs "rustdesk-server" {};
openFirewall = mkOption {
type = types.bool;
default = false;
description = ''
Open the connection ports.
TCP (${lib.concatStringsSep ", " (map toString TCPPorts)})
UDP (${lib.concatStringsSep ", " (map toString UDPPorts)})
'';
};
relayIP = mkOption {
type = str;
description = ''
The public facing IP of the RustDesk relay.
'';
};
extraSignalArgs = mkOption {
type = listOf str;
default = [];
example = [ "-k" "_" ];
description = ''
A list of extra command line arguments to pass to the `hbbs` process.
'';
};
extraRelayArgs = mkOption {
type = listOf str;
default = [];
example = [ "-k" "_" ];
description = ''
A list of extra command line arguments to pass to the `hbbr` process.
'';
};
};
config = let
cfg = config.services.rustdesk-server;
serviceDefaults = {
enable = true;
requiredBy = [ "rustdesk.target" ];
serviceConfig = {
Slice = "system-rustdesk.slice";
User = "rustdesk";
Group = "rustdesk";
DynamicUser = "yes";
Environment = [];
WorkingDirectory = "/var/lib/rustdesk";
StateDirectory = "rustdesk";
StateDirectoryMode = "0750";
LockPersonality = true;
PrivateDevices = true;
PrivateMounts = true;
PrivateUsers = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "invisible";
RestrictNamespaces = true;
};
};
in lib.mkIf cfg.enable {
users.users.rustdesk = {
description = "System user for RustDesk";
isSystemUser = true;
group = "rustdesk";
};
users.groups.rustdesk = {};
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall TCPPorts;
networking.firewall.allowedUDPPorts = lib.mkIf cfg.openFirewall UDPPorts;
systemd.slices.system-rustdesk = {
enable = true;
description = "Slice designed to contain RustDesk Signal & RustDesk Relay";
};
systemd.targets.rustdesk = {
enable = true;
description = "Target designed to group RustDesk Signal & RustDesk Relay";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
};
systemd.services.rustdesk-signal = lib.mkMerge [ serviceDefaults {
serviceConfig.ExecStart = "${cfg.package}/bin/hbbs -r ${cfg.relayIP} ${lib.escapeShellArgs cfg.extraSignalArgs}";
} ];
systemd.services.rustdesk-relay = lib.mkMerge [ serviceDefaults {
serviceConfig.ExecStart = "${cfg.package}/bin/hbbr ${lib.escapeShellArgs cfg.extraRelayArgs}";
} ];
};
meta.maintainers = with lib.maintainers; [ ppom ];
}
|