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 };
93 })
94 (mkIf cfgS.enable {
95 systemd.services."synergy-server" = {
96 after = [ "network.target" ];
97 description = "Synergy server";
98 wantedBy = optional cfgS.autoStart "multi-user.target";
99 path = [ pkgs.synergy ];
100 serviceConfig.ExecStart = ''${pkgs.synergy}/bin/synergys -c ${cfgS.configFile} -f ${optionalString (cfgS.address != "") "-a ${cfgS.address}"} ${optionalString (cfgS.screenName != "") "-n ${cfgS.screenName}" }'';
101 };
102 })
103 ];
104
105}
106
107/* SYNERGY SERVER example configuration file
108section: screens
109 laptop:
110 dm:
111 win:
112end
113section: aliases
114 laptop:
115 192.168.5.5
116 dm:
117 192.168.5.78
118 win:
119 192.168.5.54
120end
121section: links
122 laptop:
123 left = dm
124 dm:
125 right = laptop
126 left = win
127 win:
128 right = dm
129end
130*/