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