1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-04-09 02:30:29 +00:00

Merge pull request #99 from Enzime/add/synergy-service

synergy: Add module for client and server
This commit is contained in:
Daiderd Jordan 2018-09-14 22:57:51 +02:00 committed by GitHub
commit c49311408b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 153 additions and 0 deletions

View file

@ -59,6 +59,7 @@ let
./modules/services/privoxy
./modules/services/redis
./modules/services/skhd
./modules/services/synergy
./modules/programs/bash
./modules/programs/fish.nix
./modules/programs/gnupg.nix

View file

@ -0,0 +1,116 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.synergy;
in
{
options = {
services.synergy = {
package = mkOption {
default = pkgs.synergy;
defaultText = "pkgs.synergy";
type = types.package;
description = "The package used for the synergy client and server.";
};
client = {
enable = mkOption {
default = false;
type = types.bool;
description = "
Whether to enable the Synergy client (receive keyboard and mouse events from a Synergy server).
";
};
screenName = mkOption {
default = "";
type = types.str;
description = ''
Use the given name instead of the hostname to identify
ourselves to the server.
'';
};
serverAddress = mkOption {
type = types.str;
description = ''
The server address is of the form: [hostname][:port]. The
hostname must be the address or hostname of the server. The
port overrides the default port, 24800.
'';
};
autoStart = mkOption {
default = true;
type = types.bool;
description = "Whether the Synergy client should be started automatically.";
};
};
server = {
enable = mkOption {
default = false;
type = types.bool;
description = ''
Whether to enable the Synergy server (send keyboard and mouse events).
'';
};
configFile = mkOption {
default = "/etc/synergy-server.conf";
type = types.str;
description = "The Synergy server configuration file.";
};
screenName = mkOption {
default = "";
type = types.str;
description = ''
Use the given name instead of the hostname to identify
this screen in the configuration.
'';
};
address = mkOption {
default = "";
type = types.str;
description = "Address on which to listen for clients.";
};
autoStart = mkOption {
default = true;
type = types.bool;
description = "Whether the Synergy server should be started automatically.";
};
};
};
};
config = mkMerge [
(mkIf cfg.client.enable {
launchd.user.agents."synergy-client" = {
path = [ config.environment.systemPath ];
serviceConfig.ProgramArguments = [
"${cfg.package}/bin/synergyc" "-f" "${cfg.client.serverAddress}"
] ++ optionals (cfg.client.screenName != "") [ "-n" cfg.client.screenName ];
serviceConfig.KeepAlive = true;
serviceConfig.RunAtLoad = cfg.client.autoStart;
serviceConfig.ProcessType = "Interactive";
};
})
(mkIf cfg.server.enable {
launchd.user.agents."synergy-server" = {
path = [ config.environment.systemPath ];
serviceConfig.ProgramArguments = [
"${cfg.package}/bin/synergys" "-c" "${cfg.server.configFile}" "-f"
] ++ optionals (cfg.server.screenName != "") [ "-n" cfg.server.screenName ]
++ optionals (cfg.server.address != "") [ "-a" cfg.server.address ];
serviceConfig.KeepAlive = true;
serviceConfig.RunAtLoad = cfg.server.autoStart;
serviceConfig.ProcessType = "Interactive";
};
})
];
}

View file

@ -104,6 +104,7 @@ let
tests.services-ofborg = makeTest ./tests/services-ofborg.nix;
tests.services-offlineimap = makeTest ./tests/services-offlineimap.nix;
tests.services-skhd = makeTest ./tests/services-skhd.nix;
tests.services-synergy = makeTest ./tests/services-synergy.nix;
tests.services-privoxy = makeTest ./tests/services-privoxy.nix;
tests.system-defaults-write = makeTest ./tests/system-defaults-write.nix;
tests.system-keyboard-mapping = makeTest ./tests/system-keyboard-mapping.nix;

View file

@ -0,0 +1,35 @@
{ config, lib, pkgs, ... }:
with lib;
let
synergy = pkgs.runCommand "synergy-0.0.0" {} "mkdir $out";
in
{
services.synergy.package = synergy;
services.synergy.client.enable = true;
services.synergy.client.screenName = "client_screenName";
services.synergy.client.serverAddress = "123.123.123.123:123";
services.synergy.server.enable = true;
services.synergy.server.configFile = "/tmp/synergy.conf";
services.synergy.server.screenName = "server_screenName";
services.synergy.server.address = "0.0.0.0:123";
test = ''
echo >&2 "checking synergy-client service in ~/Library/LaunchAgents"
grep "org.nixos.synergy-client" ${config.out}/user/Library/LaunchAgents/org.nixos.synergy-client.plist
grep "${synergy}/bin/synergyc" ${config.out}/user/Library/LaunchAgents/org.nixos.synergy-client.plist
grep "${config.services.synergy.client.screenName}" ${config.out}/user/Library/LaunchAgents/org.nixos.synergy-client.plist
grep "${config.services.synergy.client.serverAddress}" ${config.out}/user/Library/LaunchAgents/org.nixos.synergy-client.plist
echo >&2 "checking synergy-server service in ~/Library/LaunchAgents"
grep "org.nixos.synergy-server" ${config.out}/user/Library/LaunchAgents/org.nixos.synergy-server.plist
grep "${synergy}/bin/synergys" ${config.out}/user/Library/LaunchAgents/org.nixos.synergy-server.plist
grep "${config.services.synergy.server.configFile}" ${config.out}/user/Library/LaunchAgents/org.nixos.synergy-server.plist
grep "${config.services.synergy.server.screenName}" ${config.out}/user/Library/LaunchAgents/org.nixos.synergy-server.plist
grep "${config.services.synergy.server.address}" ${config.out}/user/Library/LaunchAgents/org.nixos.synergy-server.plist
'';
}