2021-12-12 19:20:31 +01:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs;
|
|
|
|
|
|
|
|
let
|
|
|
|
port = 1883;
|
|
|
|
wsPort = 9001;
|
2022-05-06 03:16:17 +02:00
|
|
|
|
|
|
|
mkSecret = file: {
|
|
|
|
inherit file;
|
|
|
|
owner = "mosquitto";
|
|
|
|
};
|
2021-12-12 19:20:31 +01:00
|
|
|
in {
|
2022-05-06 03:16:17 +02:00
|
|
|
age.secrets = {
|
|
|
|
mqtt-felix = mkSecret ../secrets/mqtt/felix.age;
|
|
|
|
mqtt-birgit = mkSecret ../secrets/mqtt/birgit.age;
|
|
|
|
mqtt-hass = mkSecret ../secrets/mqtt/hass.age;
|
|
|
|
mqtt-tasmota = mkSecret ../secrets/mqtt/tasmota.age;
|
|
|
|
mqtt-owntracks = mkSecret ../secrets/mqtt/owntracks.age;
|
|
|
|
};
|
|
|
|
|
2021-12-12 19:20:31 +01:00
|
|
|
services.nginx = {
|
2021-12-12 19:23:38 +01:00
|
|
|
virtualHosts."mqtt.felschr.com" = {
|
2021-12-12 19:20:31 +01:00
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://localhost:${toString wsPort}";
|
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ port ];
|
|
|
|
|
|
|
|
services.mosquitto = {
|
|
|
|
enable = true;
|
|
|
|
listeners = [
|
|
|
|
{
|
|
|
|
port = port;
|
|
|
|
users = {
|
|
|
|
"hass" = {
|
|
|
|
acl = [
|
|
|
|
"readwrite homeassistant/#"
|
|
|
|
"readwrite tasmota/#"
|
|
|
|
"readwrite owntracks/#"
|
|
|
|
];
|
2022-05-04 03:02:47 +02:00
|
|
|
hashedPasswordFile = config.age.secrets.mqtt-hass.path;
|
2021-12-12 19:20:31 +01:00
|
|
|
};
|
|
|
|
"tasmota" = {
|
|
|
|
acl = [ "readwrite tasmota/#" "readwrite homeassistant/#" ];
|
2022-05-04 03:02:47 +02:00
|
|
|
hashedPasswordFile = config.age.secrets.mqtt-tasmota.path;
|
2021-12-12 19:20:31 +01:00
|
|
|
};
|
|
|
|
"owntracks" = {
|
|
|
|
acl = [ "readwrite owntracks/#" ];
|
2022-05-04 03:02:47 +02:00
|
|
|
hashedPasswordFile = config.age.secrets.mqtt-owntracks.path;
|
2021-12-12 19:20:31 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
{
|
|
|
|
port = wsPort;
|
|
|
|
settings.protocol = "websockets";
|
|
|
|
users = {
|
|
|
|
"felix" = {
|
|
|
|
acl = [ "read owntracks/#" "readwrite owntracks/felix/#" ];
|
2022-05-04 03:02:47 +02:00
|
|
|
hashedPasswordFile = config.age.secrets.mqtt-felix.path;
|
2021-12-12 19:20:31 +01:00
|
|
|
};
|
|
|
|
"birgit" = {
|
|
|
|
acl = [ "read owntracks/#" "readwrite owntracks/birgit/#" ];
|
2022-05-04 03:02:47 +02:00
|
|
|
hashedPasswordFile = config.age.secrets.mqtt-birgit.path;
|
2021-12-12 19:20:31 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|