add websocket listener to mosquitto
This commit is contained in:
@@ -247,7 +247,25 @@ in
|
||||
|
||||
mosquitto = {
|
||||
enable = true;
|
||||
subdomain = "mqtt";
|
||||
listeners = [
|
||||
{
|
||||
users = {
|
||||
homie = {
|
||||
acl = [
|
||||
"readwrite homie/#"
|
||||
];
|
||||
hashedPasswordFile = secrets."mosquitto/homie".path;
|
||||
};
|
||||
};
|
||||
port = 8084;
|
||||
settings = {
|
||||
protocol = "websockets";
|
||||
cafile = "/run/credentials/mosquitto.service/fullchain.pem";
|
||||
certfile = "/run/credentials/mosquitto.service/fullchain.pem";
|
||||
keyfile = "/run/credentials/mosquitto.service/key.pem";
|
||||
};
|
||||
}
|
||||
{
|
||||
users = {
|
||||
homie = {
|
||||
|
||||
@@ -1,14 +1,39 @@
|
||||
{ config, lib, ... }:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.services.mosquitto;
|
||||
fqdn = "${cfg.subdomain}.${config.networking.domain}";
|
||||
acme = config.security.acme;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
services.mosquitto = {
|
||||
openFirewall = lib.mkEnableOption "Open firewall port for Mosquitto";
|
||||
subdomain = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
};
|
||||
config = lib.mkIf cfg.enable {
|
||||
networking.firewall.allowedTCPPorts = map ({ port, ... }: port) cfg.listeners;
|
||||
};
|
||||
config = lib.mkIf cfg.enable (
|
||||
lib.mkMerge [
|
||||
{ networking.firewall.allowedTCPPorts = map ({ port, ... }: port) cfg.listeners; }
|
||||
(lib.mkIf (cfg.subdomain != null) {
|
||||
security.acme.certs.${fqdn}.postRun = ''
|
||||
systemctl restart mosquitto
|
||||
'';
|
||||
|
||||
systemd.services.mosquitto = {
|
||||
requires = [ "acme-${fqdn}.service" ];
|
||||
serviceConfig.LoadCredential = [
|
||||
"fullchain.pem:${acme.certs.${fqdn}.directory}/fullchain.pem"
|
||||
"key.pem:${acme.certs.${fqdn}.directory}/key.pem"
|
||||
];
|
||||
};
|
||||
})
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user