2023-03-19 09:59:32 -07:00
|
|
|
packages:
|
|
|
|
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
2023-03-19 10:29:37 -07:00
|
|
|
suanni-server = packages."${pkgs.system}".suanni-server;
|
2023-03-20 15:26:40 -07:00
|
|
|
cfg = config.services.suanni.server;
|
2023-03-19 09:59:32 -07:00
|
|
|
|
|
|
|
in {
|
2023-03-20 15:26:40 -07:00
|
|
|
options.services.suanni.server = with types; {
|
2023-03-19 09:59:32 -07:00
|
|
|
enable = mkEnableOption "Enable Suan Ni guardian server.";
|
|
|
|
|
|
|
|
verbose = mkEnableOption "Generate verbose logs and output.";
|
|
|
|
|
|
|
|
event-listener = {
|
|
|
|
hostname = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Hostname of the event listener server.";
|
|
|
|
default = "127.0.0.1";
|
|
|
|
};
|
|
|
|
|
2023-03-19 10:39:46 -07:00
|
|
|
port = mkOption {
|
2023-03-19 09:59:32 -07:00
|
|
|
type = port;
|
|
|
|
description = "Port on which to listen for incoming events.";
|
|
|
|
default = 5354;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
synology-client = {
|
|
|
|
host = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Hostname of the Synology server.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = port;
|
|
|
|
description =
|
|
|
|
"Port on which to connect to the Synology server. Can be an SSL port.";
|
|
|
|
default = 5001;
|
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "User as which to connect to the Synology server.";
|
|
|
|
};
|
|
|
|
|
|
|
|
password-file = mkOption {
|
|
|
|
type = str;
|
|
|
|
description =
|
|
|
|
"File (on the local host) containing the password for the Synology server.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
objectifier-client = {
|
|
|
|
host = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Hostname of the Objectifier server.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = port;
|
|
|
|
description = "Port on which the Objectifier server is listening.";
|
|
|
|
default = 80;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-03-19 10:18:46 -07:00
|
|
|
mqtt-client = {
|
2023-03-19 09:59:32 -07:00
|
|
|
host = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Hostname of the MQTT server.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = port;
|
|
|
|
description = "Port on which the MQTT server is listening.";
|
|
|
|
default = 80;
|
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "User as which to connect to the MQTT server.";
|
|
|
|
};
|
|
|
|
|
|
|
|
password-file = mkOption {
|
|
|
|
type = str;
|
|
|
|
description =
|
|
|
|
"File (on the local host) containing the password for the MQTT server.";
|
|
|
|
};
|
2023-03-21 09:20:15 -07:00
|
|
|
|
|
|
|
topic = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "MQTT topic on which to publish events.";
|
|
|
|
};
|
2023-03-19 09:59:32 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2023-03-19 10:42:04 -07:00
|
|
|
systemd.services.suanni-server = {
|
2023-03-19 09:59:32 -07:00
|
|
|
path = [ suanni-server ];
|
2023-04-25 15:37:05 -07:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2023-03-21 08:24:58 -07:00
|
|
|
after = [ "network-online.target" ];
|
2023-03-19 09:59:32 -07:00
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
LoadCredential = [
|
2023-03-19 10:18:46 -07:00
|
|
|
"syno.passwd:${cfg.synology-client.password-file}"
|
|
|
|
"mqtt.passwd:${cfg.mqtt-client.password-file}"
|
2023-03-19 09:59:32 -07:00
|
|
|
];
|
|
|
|
ExecStart = pkgs.writeShellScript "suanni-server.sh"
|
2023-03-20 18:42:45 -07:00
|
|
|
(concatStringsSep " " ([
|
2023-03-21 08:40:54 -07:00
|
|
|
"suanni.server"
|
2023-03-19 09:59:32 -07:00
|
|
|
"--hostname=${cfg.event-listener.hostname}"
|
|
|
|
"--port=${toString cfg.event-listener.port}"
|
2023-03-19 10:18:46 -07:00
|
|
|
"--synology-host=${cfg.synology-client.host}"
|
|
|
|
"--synology-port=${toString cfg.synology-client.port}"
|
|
|
|
"--synology-user=${cfg.synology-client.username}"
|
2023-03-19 09:59:32 -07:00
|
|
|
"--synology-password-file=$CREDENTIALS_DIRECTORY/syno.passwd"
|
2023-03-19 10:18:46 -07:00
|
|
|
"--mqtt-host=${cfg.mqtt-client.host}"
|
|
|
|
"--mqtt-port=${toString cfg.mqtt-client.port}"
|
|
|
|
"--mqtt-user=${cfg.mqtt-client.username}"
|
2023-03-19 09:59:32 -07:00
|
|
|
"--mqtt-password-file=$CREDENTIALS_DIRECTORY/mqtt.passwd"
|
2023-03-21 09:20:15 -07:00
|
|
|
"--mqtt-topic=${cfg.mqtt-client.topic}"
|
2023-03-19 10:18:46 -07:00
|
|
|
"--objectifier-host=${cfg.objectifier-client.host}"
|
2023-03-20 18:36:26 -07:00
|
|
|
"--objectifier-port=${toString cfg.objectifier-client.port}"
|
2023-03-20 18:42:45 -07:00
|
|
|
] ++ (optional cfg.verbose "--verbose")));
|
2023-03-19 09:59:32 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|