1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.syncplay;
7
8 cmdArgs =
9 [ "--port" cfg.port ]
10 ++ optionals (cfg.salt != null) [ "--salt" cfg.salt ]
11 ++ optionals (cfg.certDir != null) [ "--tls" cfg.certDir ];
12
13in
14{
15 options = {
16 services.syncplay = {
17 enable = mkOption {
18 type = types.bool;
19 default = false;
20 description = "If enabled, start the Syncplay server.";
21 };
22
23 port = mkOption {
24 type = types.int;
25 default = 8999;
26 description = ''
27 TCP port to bind to.
28 '';
29 };
30
31 salt = mkOption {
32 type = types.nullOr types.str;
33 default = null;
34 description = ''
35 Salt to allow room operator passwords generated by this server
36 instance to still work when the server is restarted.
37 '';
38 };
39
40 certDir = mkOption {
41 type = types.nullOr types.path;
42 default = null;
43 description = ''
44 TLS certificates directory to use for encryption. See
45 <link xlink:href="https://github.com/Syncplay/syncplay/wiki/TLS-support"/>.
46 '';
47 };
48
49 user = mkOption {
50 type = types.str;
51 default = "nobody";
52 description = ''
53 User to use when running Syncplay.
54 '';
55 };
56
57 group = mkOption {
58 type = types.str;
59 default = "nogroup";
60 description = ''
61 Group to use when running Syncplay.
62 '';
63 };
64 };
65 };
66
67 config = mkIf cfg.enable {
68 systemd.services.syncplay = {
69 description = "Syncplay Service";
70 wantedBy = [ "multi-user.target" ];
71 after = [ "network-online.target "];
72
73 serviceConfig = {
74 ExecStart = "${pkgs.syncplay}/bin/syncplay-server ${escapeShellArgs cmdArgs}";
75 User = cfg.user;
76 Group = cfg.group;
77 };
78 };
79 };
80}