at 25.11-pre 4.5 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 9 cfgC = config.services.synergy.client; 10 cfgS = config.services.synergy.server; 11 12in 13 14{ 15 ###### interface 16 17 options = { 18 19 services.synergy = { 20 21 # !!! All these option descriptions needs to be cleaned up. 22 23 client = { 24 enable = lib.mkEnableOption "the Synergy client (receive keyboard and mouse events from a Synergy server)"; 25 26 screenName = lib.mkOption { 27 default = ""; 28 type = lib.types.str; 29 description = '' 30 Use the given name instead of the hostname to identify 31 ourselves to the server. 32 ''; 33 }; 34 serverAddress = lib.mkOption { 35 type = lib.types.str; 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 = lib.mkOption { 43 default = true; 44 type = lib.types.bool; 45 description = "Whether the Synergy client should be started automatically."; 46 }; 47 }; 48 49 server = { 50 enable = lib.mkEnableOption "the Synergy server (send keyboard and mouse events)"; 51 52 configFile = lib.mkOption { 53 type = lib.types.path; 54 default = "/etc/synergy-server.conf"; 55 description = "The Synergy server configuration file."; 56 }; 57 screenName = lib.mkOption { 58 type = lib.types.str; 59 default = ""; 60 description = '' 61 Use the given name instead of the hostname to identify 62 this screen in the configuration. 63 ''; 64 }; 65 address = lib.mkOption { 66 type = lib.types.str; 67 default = ""; 68 description = "Address on which to listen for clients."; 69 }; 70 autoStart = lib.mkOption { 71 default = true; 72 type = lib.types.bool; 73 description = "Whether the Synergy server should be started automatically."; 74 }; 75 tls = { 76 enable = lib.mkOption { 77 type = lib.types.bool; 78 default = false; 79 description = '' 80 Whether TLS encryption should be used. 81 82 Using this requires a TLS certificate that can be 83 generated by starting the Synergy GUI once and entering 84 a valid product key. 85 ''; 86 }; 87 88 cert = lib.mkOption { 89 type = lib.types.nullOr lib.types.str; 90 default = null; 91 example = "~/.synergy/SSL/Synergy.pem"; 92 description = "The TLS certificate to use for encryption."; 93 }; 94 }; 95 }; 96 }; 97 98 }; 99 100 ###### implementation 101 102 config = lib.mkMerge [ 103 (lib.mkIf cfgC.enable { 104 systemd.user.services.synergy-client = { 105 after = [ 106 "network.target" 107 "graphical-session.target" 108 ]; 109 description = "Synergy client"; 110 wantedBy = lib.optional cfgC.autoStart "graphical-session.target"; 111 path = [ pkgs.synergy ]; 112 serviceConfig.ExecStart = ''${pkgs.synergy}/bin/synergyc -f ${ 113 lib.optionalString (cfgC.screenName != "") "-n ${cfgC.screenName}" 114 } ${cfgC.serverAddress}''; 115 serviceConfig.Restart = "on-failure"; 116 }; 117 }) 118 (lib.mkIf cfgS.enable { 119 systemd.user.services.synergy-server = { 120 after = [ 121 "network.target" 122 "graphical-session.target" 123 ]; 124 description = "Synergy server"; 125 wantedBy = lib.optional cfgS.autoStart "graphical-session.target"; 126 path = [ pkgs.synergy ]; 127 serviceConfig.ExecStart = ''${pkgs.synergy}/bin/synergys -c ${cfgS.configFile} -f${ 128 lib.optionalString (cfgS.address != "") " -a ${cfgS.address}" 129 }${ 130 lib.optionalString (cfgS.screenName != "") " -n ${cfgS.screenName}" 131 }${lib.optionalString cfgS.tls.enable " --enable-crypto"}${ 132 lib.optionalString (cfgS.tls.cert != null) (" --tls-cert ${cfgS.tls.cert}") 133 }''; 134 serviceConfig.Restart = "on-failure"; 135 }; 136 }) 137 ]; 138 139} 140 141/* 142 SYNERGY SERVER example configuration file 143 section: screens 144 laptop: 145 dm: 146 win: 147 end 148 section: aliases 149 laptop: 150 192.168.5.5 151 dm: 152 192.168.5.78 153 win: 154 192.168.5.54 155 end 156 section: links 157 laptop: 158 left = dm 159 dm: 160 right = laptop 161 left = win 162 win: 163 right = dm 164 end 165*/