1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfgC = config.services.synergy.client;
8 cfgS = config.services.synergy.server;
9
10in
11
12{
13 ###### interface
14
15 options = {
16
17 services.synergy = {
18
19 # !!! All these option descriptions needs to be cleaned up.
20
21 client = {
22 enable = mkOption {
23 default = false;
24 description = "
25 Whether to enable the Synergy client (receive keyboard and mouse events from a Synergy server).
26 ";
27 };
28 screenName = mkOption {
29 default = "";
30 description = ''
31 Use the given name instead of the hostname to identify
32 ourselves to the server.
33 '';
34 };
35 serverAddress = mkOption {
36 description = ''
37 The server address is of the form: [hostname][:port]. The
38 hostname must be the address or hostname of the server. The
39 port overrides the default port, 24800.
40 '';
41 };
42 autoStart = mkOption {
43 default = true;
44 type = types.bool;
45 description = "Whether the Synergy client should be started automatically.";
46 };
47 };
48
49 server = {
50 enable = mkOption {
51 default = false;
52 description = ''
53 Whether to enable the Synergy server (send keyboard and mouse events).
54 '';
55 };
56 configFile = mkOption {
57 default = "/etc/synergy-server.conf";
58 description = "The Synergy server configuration file.";
59 };
60 screenName = mkOption {
61 default = "";
62 description = ''
63 Use the given name instead of the hostname to identify
64 this screen in the configuration.
65 '';
66 };
67 address = mkOption {
68 default = "";
69 description = "Address on which to listen for clients.";
70 };
71 autoStart = mkOption {
72 default = true;
73 type = types.bool;
74 description = "Whether the Synergy server should be started automatically.";
75 };
76 };
77 };
78
79 };
80
81
82 ###### implementation
83
84 config = mkMerge [
85 (mkIf cfgC.enable {
86 systemd.services."synergy-client" = {
87 after = [ "network.target" ];
88 description = "Synergy client";
89 wantedBy = optional cfgC.autoStart "multi-user.target";
90 path = [ pkgs.synergy ];
91 serviceConfig.ExecStart = ''${pkgs.synergy}/bin/synergyc -f ${optionalString (cfgC.screenName != "") "-n ${cfgC.screenName}"} ${cfgC.serverAddress}'';
92 serviceConfig.Restart = "on-failure";
93 };
94 })
95 (mkIf cfgS.enable {
96 systemd.services."synergy-server" = {
97 after = [ "network.target" ];
98 description = "Synergy server";
99 wantedBy = optional cfgS.autoStart "multi-user.target";
100 path = [ pkgs.synergy ];
101 serviceConfig.ExecStart = ''${pkgs.synergy}/bin/synergys -c ${cfgS.configFile} -f ${optionalString (cfgS.address != "") "-a ${cfgS.address}"} ${optionalString (cfgS.screenName != "") "-n ${cfgS.screenName}" }'';
102 serviceConfig.Restart = "on-failure";
103 };
104 })
105 ];
106
107}
108
109/* SYNERGY SERVER example configuration file
110section: screens
111 laptop:
112 dm:
113 win:
114end
115section: aliases
116 laptop:
117 192.168.5.5
118 dm:
119 192.168.5.78
120 win:
121 192.168.5.54
122end
123section: links
124 laptop:
125 left = dm
126 dm:
127 right = laptop
128 left = win
129 win:
130 right = dm
131end
132*/