nixos/services.synergy: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-30 00:46:50 +02:00
parent 165ad257f7
commit 334d6eb492

View File

@ -1,7 +1,4 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfgC = config.services.synergy.client;
@ -19,60 +16,60 @@ in
# !!! All these option descriptions needs to be cleaned up.
client = {
enable = mkEnableOption "the Synergy client (receive keyboard and mouse events from a Synergy server)";
enable = lib.mkEnableOption "the Synergy client (receive keyboard and mouse events from a Synergy server)";
screenName = mkOption {
screenName = lib.mkOption {
default = "";
type = types.str;
type = lib.types.str;
description = ''
Use the given name instead of the hostname to identify
ourselves to the server.
'';
};
serverAddress = mkOption {
type = types.str;
serverAddress = lib.mkOption {
type = lib.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 {
autoStart = lib.mkOption {
default = true;
type = types.bool;
type = lib.types.bool;
description = "Whether the Synergy client should be started automatically.";
};
};
server = {
enable = mkEnableOption "the Synergy server (send keyboard and mouse events)";
enable = lib.mkEnableOption "the Synergy server (send keyboard and mouse events)";
configFile = mkOption {
type = types.path;
configFile = lib.mkOption {
type = lib.types.path;
default = "/etc/synergy-server.conf";
description = "The Synergy server configuration file.";
};
screenName = mkOption {
type = types.str;
screenName = lib.mkOption {
type = lib.types.str;
default = "";
description = ''
Use the given name instead of the hostname to identify
this screen in the configuration.
'';
};
address = mkOption {
type = types.str;
address = lib.mkOption {
type = lib.types.str;
default = "";
description = "Address on which to listen for clients.";
};
autoStart = mkOption {
autoStart = lib.mkOption {
default = true;
type = types.bool;
type = lib.types.bool;
description = "Whether the Synergy server should be started automatically.";
};
tls = {
enable = mkOption {
type = types.bool;
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether TLS encryption should be used.
@ -83,8 +80,8 @@ in
'';
};
cert = mkOption {
type = types.nullOr types.str;
cert = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "~/.synergy/SSL/Synergy.pem";
description = "The TLS certificate to use for encryption.";
@ -98,24 +95,24 @@ in
###### implementation
config = mkMerge [
(mkIf cfgC.enable {
config = lib.mkMerge [
(lib.mkIf cfgC.enable {
systemd.user.services.synergy-client = {
after = [ "network.target" "graphical-session.target" ];
description = "Synergy client";
wantedBy = optional cfgC.autoStart "graphical-session.target";
wantedBy = lib.optional cfgC.autoStart "graphical-session.target";
path = [ pkgs.synergy ];
serviceConfig.ExecStart = ''${pkgs.synergy}/bin/synergyc -f ${optionalString (cfgC.screenName != "") "-n ${cfgC.screenName}"} ${cfgC.serverAddress}'';
serviceConfig.ExecStart = ''${pkgs.synergy}/bin/synergyc -f ${lib.optionalString (cfgC.screenName != "") "-n ${cfgC.screenName}"} ${cfgC.serverAddress}'';
serviceConfig.Restart = "on-failure";
};
})
(mkIf cfgS.enable {
(lib.mkIf cfgS.enable {
systemd.user.services.synergy-server = {
after = [ "network.target" "graphical-session.target" ];
description = "Synergy server";
wantedBy = optional cfgS.autoStart "graphical-session.target";
wantedBy = lib.optional cfgS.autoStart "graphical-session.target";
path = [ pkgs.synergy ];
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}")}'';
serviceConfig.ExecStart = ''${pkgs.synergy}/bin/synergys -c ${cfgS.configFile} -f${lib.optionalString (cfgS.address != "") " -a ${cfgS.address}"}${lib.optionalString (cfgS.screenName != "") " -n ${cfgS.screenName}"}${lib.optionalString cfgS.tls.enable " --enable-crypto"}${lib.optionalString (cfgS.tls.cert != null) (" --tls-cert ${cfgS.tls.cert}")}'';
serviceConfig.Restart = "on-failure";
};
})