nixos-config/config/service/wallfly-presence.nix

62 lines
2.0 KiB
Nix
Raw Normal View History

2022-07-10 20:46:03 -07:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.fudo.services.wallfly-presence;
hostname = config.instance.hostname;
domain-name = config.instance.local-domain;
site-name = config.instance.local-site;
mqtt-broker = cfg.mqtt.broker-host;
is-mqtt-broker = hostname == mqtt-broker;
site-users = config.fudo.sites."${config.instance.local-site}".local-users;
domain-users = config.fudo.domains."${domain-name}".local-users;
user-cfg = genAttrs (unique (site-users ++ domain-users)) (username: {
password-file =
pkgs.lib.passwd.stablerandom-passwd-file "wallfly-${username}"
config.instance.build-seed;
});
local-user-cfg =
filterAttrs (username: opts: hasAttr username config.instance.local-users)
user-cfg;
in {
options.fudo.services.wallfly-presence = with types; {
enable = mkEnableOption "Enable WallFly presence for the local site.";
};
config = mkIf cfg.enable {
fudo = {
secrets.host-secrets."${hostname}" = (mapAttrs' (username: userOpts:
nameValuePair "wallfly-user-${username}-passwd" {
source-file = userOpts.password-file;
target-file = "/run/wallfly-${username}/passwd";
user = username;
2023-05-16 22:40:08 -07:00
}) local-user-cfg);
2022-07-10 20:46:03 -07:00
wallfly = {
enable = true;
2023-05-16 22:40:08 -07:00
mqtt = let
mqtt-hostname = config.fudo.services.mqtt.mqtt-hostname;
mqtt-port = config.fudo.services.mqtt.private.port;
in {
broker-uri = "tcp://${mqtt-hostname}:${toString mqtt-port}";
2022-07-10 20:46:03 -07:00
username = "wallfly-$USER";
password-file = "/run/wallfly-$USER/passwd";
};
};
2023-05-16 22:40:08 -07:00
services.mqtt = {
2022-07-10 20:46:03 -07:00
enable = true;
2023-05-16 22:40:08 -07:00
private = {
enable = true;
2022-07-10 20:46:03 -07:00
users = mapAttrs' (username: userOpts:
nameValuePair "wallfly-${username}" {
2023-05-16 22:40:08 -07:00
password-file = userOpts.password-file;
2022-07-10 20:46:03 -07:00
acl = [ "readwrite homeassistant/binary_sensor/#" ];
}) user-cfg;
2023-05-16 22:40:08 -07:00
};
2022-07-10 20:46:03 -07:00
};
};
};
}