suanni/module.nix

130 lines
3.6 KiB
Nix
Raw Permalink Normal View History

2023-03-19 09:59:32 -07:00
packages:
{ config, lib, pkgs, ... }:
with lib;
let
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";
};
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;
};
};
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 {
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" ];
after = [ "network-online.target" ];
2023-03-19 09:59:32 -07:00
serviceConfig = {
DynamicUser = true;
LoadCredential = [
"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 " " ([
"suanni.server"
2023-03-19 09:59:32 -07:00
"--hostname=${cfg.event-listener.hostname}"
"--port=${toString cfg.event-listener.port}"
"--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"
"--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}"
"--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
};
};
};
}