1 { lib, pkgs, config, ... }:
3 TCPPorts = [21115 21116 21117 21118 21119];
6 options.services.rustdesk-server = with lib; with types; {
7 enable = mkEnableOption "RustDesk, a remote access and remote control software, allowing maintenance of computers and other devices";
9 package = mkPackageOption pkgs "rustdesk-server" {};
11 openFirewall = mkOption {
15 Open the connection ports.
16 TCP (${lib.concatStringsSep ", " (map toString TCPPorts)})
17 UDP (${lib.concatStringsSep ", " (map toString UDPPorts)})
24 The public facing IP of the RustDesk relay.
28 extraSignalArgs = mkOption {
31 example = [ "-k" "_" ];
33 A list of extra command line arguments to pass to the `hbbs` process.
37 extraRelayArgs = mkOption {
40 example = [ "-k" "_" ];
42 A list of extra command line arguments to pass to the `hbbr` process.
48 cfg = config.services.rustdesk-server;
51 requiredBy = [ "rustdesk.target" ];
53 Slice = "system-rustdesk.slice";
58 WorkingDirectory = "/var/lib/rustdesk";
59 StateDirectory = "rustdesk";
60 StateDirectoryMode = "0750";
61 LockPersonality = true;
62 PrivateDevices = true;
66 ProtectControlGroups = true;
68 ProtectHostname = true;
69 ProtectKernelLogs = true;
70 ProtectKernelModules = true;
71 ProtectKernelTunables = true;
72 ProtectProc = "invisible";
73 RestrictNamespaces = true;
76 in lib.mkIf cfg.enable {
77 users.users.rustdesk = {
78 description = "System user for RustDesk";
82 users.groups.rustdesk = {};
84 networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall TCPPorts;
85 networking.firewall.allowedUDPPorts = lib.mkIf cfg.openFirewall UDPPorts;
87 systemd.slices.system-rustdesk = {
89 description = "RustDesk Remote Desktop Slice";
92 systemd.targets.rustdesk = {
94 description = "Target designed to group RustDesk Signal & RustDesk Relay";
95 after = [ "network.target" ];
96 wantedBy = [ "multi-user.target" ];
99 systemd.services.rustdesk-signal = lib.mkMerge [ serviceDefaults {
100 serviceConfig.ExecStart = "${cfg.package}/bin/hbbs -r ${cfg.relayIP} ${lib.escapeShellArgs cfg.extraSignalArgs}";
103 systemd.services.rustdesk-relay = lib.mkMerge [ serviceDefaults {
104 serviceConfig.ExecStart = "${cfg.package}/bin/hbbr ${lib.escapeShellArgs cfg.extraRelayArgs}";
108 meta.maintainers = with lib.maintainers; [ ppom ];