Split incoming & outgoing MQTT servers

This commit is contained in:
2023-05-08 22:46:42 -07:00
parent 6b5c41b23f
commit d886bd9586
3 changed files with 90 additions and 42 deletions
+58 -23
View File
@@ -9,7 +9,7 @@ let
in {
options.services.snooper = with types; {
enable = mkEnableOption "Enable Snooper notifiaction server.";
enable = mkEnableOption "Enable Snooper notification server.";
verbose = mkEnableOption "Generate verbose logs and output.";
@@ -24,26 +24,51 @@ in {
};
mqtt = {
host = mkOption {
type = str;
description = "Hostname of the MQTT server.";
};
incoming = {
host = mkOption {
type = str;
description = "Hostname of the MQTT server.";
};
port = mkOption {
type = port;
description = "Port on which the MQTT server is listening.";
default = 1883;
};
port = mkOption {
type = port;
description = "Port on which the MQTT server is listening.";
default = 1883;
};
username = mkOption {
type = str;
description = "User as which to connect to the MQTT server.";
};
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.";
password-file = mkOption {
type = str;
description =
"File (on the local host) containing the password for the MQTT server.";
};
};
outgoing = {
host = mkOption {
type = str;
description = "Hostname of the MQTT server.";
};
port = mkOption {
type = port;
description = "Port on which the MQTT server is listening.";
default = 1883;
};
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.";
};
};
};
};
@@ -54,14 +79,24 @@ in {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
DynamicUser = true;
LoadCredential = [ "mqtt.passwd:${cfg.mqtt.password-file}" ];
LoadCredential = [
"mqtt-incoming.passwd:${cfg.mqtt.incoming.password-file}"
"mqtt-outgoing.passwd:${cfg.mqtt.outgoing.password-file}"
];
ExecStart = pkgs.writeShellScript "snooper-server.sh"
(concatStringsSep " " ([
"snooper-server"
"--mqtt-host=${cfg.mqtt.host}"
"--mqtt-port=${toString cfg.mqtt.port}"
"--mqtt-user=${cfg.mqtt.username}"
"--mqtt-password-file=$CREDENTIALS_DIRECTORY/mqtt.passwd"
"--incoming-mqtt-host=${cfg.mqtt.incoming.host}"
"--incoming-mqtt-port=${toString cfg.mqtt.incoming.port}"
"--incoming-mqtt-user=${cfg.mqtt.incoming.username}"
"--incoming-mqtt-password-file=$CREDENTIALS_DIRECTORY/mqtt-incoming.passwd"
"--outgoing-mqtt-host=${cfg.mqtt.outgoing.host}"
"--outgoing-mqtt-port=${toString cfg.mqtt.outgoing.port}"
"--outgoing-mqtt-user=${cfg.mqtt.outgoing.username}"
"--outgoing-mqtt-password-file=$CREDENTIALS_DIRECTORY/mqtt-outgoing.passwd"
"--notification-topic=${cfg.notification-topic}"
] ++ (map (topic: "--event-topic=${topic}") cfg.event-topics)
++ (optional cfg.verbose "--verbose")));