113 lines
2.8 KiB
Nix
113 lines
2.8 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
with lib;
|
|
let
|
|
cfg = config.services.room-assistant;
|
|
in
|
|
{
|
|
options = {
|
|
services.room-assistant = {
|
|
enable = mkEnableOption (lib.mdDoc "room-assistant");
|
|
|
|
name = mkOption {
|
|
type = with types; uniq string;
|
|
description = "
|
|
...
|
|
";
|
|
default = "room";
|
|
};
|
|
|
|
mqttHost = mkOption {
|
|
type = with types; uniq string;
|
|
description = "
|
|
...
|
|
";
|
|
default = "";
|
|
};
|
|
|
|
mqttUser = mkOption {
|
|
type = with types; uniq string;
|
|
description = "
|
|
...
|
|
";
|
|
default = "espresense";
|
|
};
|
|
|
|
mqttPassword = mkOption {
|
|
type = with types; uniq string;
|
|
description = "
|
|
...
|
|
";
|
|
default = "insecure-password";
|
|
};
|
|
};
|
|
};
|
|
config = mkIf cfg.enable {
|
|
hardware = {
|
|
bluetooth.enable = true;
|
|
deviceTree.filter = "bcm2711-rpi-*.dtb";
|
|
};
|
|
|
|
systemd.services = {
|
|
btattach = {
|
|
before = [ "bluetooth.service" ];
|
|
after = [ "dev-ttyAMA0.device" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig = {
|
|
ExecStart = "${pkgs.bluez}/bin/btattach -B /dev/ttyAMA0 -P bcm -S 3000000";
|
|
};
|
|
};
|
|
};
|
|
|
|
virtualisation.docker.enable = true;
|
|
|
|
environment.etc."room-assistant.yml" = {
|
|
text = ''
|
|
global:
|
|
instanceName: ${cfg.name}
|
|
integrations:
|
|
- homeAssistant
|
|
- bluetoothClassic
|
|
homeAssistant:
|
|
mqttUrl: 'mqtt://${cfg.mqttHost}'
|
|
mqttOptions:
|
|
username: ${cfg.mqttUser}
|
|
password: ${cfg.mqttPassword}
|
|
bluetoothClassic:
|
|
addresses:
|
|
- A8:5B:B7:98:84:F0
|
|
- 00:24:E4:E6:FE:AD
|
|
|
|
'';
|
|
|
|
# The UNIX file mode bits
|
|
mode = "0440";
|
|
};
|
|
|
|
systemd.services."room-assistant" = {
|
|
description = "room-assistant";
|
|
wantedBy = [ "multi-user.target" ];
|
|
after = [ "docker.service" "docker.socket" ];
|
|
requires = [ "docker.service" "docker.socket" ];
|
|
script = ''
|
|
exec ${pkgs.docker}/bin/docker run \
|
|
--rm \
|
|
--name=room-assistant \
|
|
--network=host \
|
|
-v /var/run/dbus:/var/run/dbus \
|
|
-v /etc/room-assistant.yml:/room-assistant/config/local.yml \
|
|
--cap-add=NET_ADMIN \
|
|
mkerix/room-assistant:2.20.0
|
|
'';
|
|
preStop = "${pkgs.docker}/bin/docker stop room-assistant";
|
|
reload = "${pkgs.docker}/bin/docker restart room-assistant";
|
|
serviceConfig = {
|
|
ExecStartPre = "-${pkgs.docker}/bin/docker rm -f room-assistant";
|
|
ExecStopPost = "-${pkgs.docker}/bin/docker rm -f room-assistant";
|
|
TimeoutStartSec = 0;
|
|
TimeoutStopSec = 120;
|
|
Restart = "always";
|
|
};
|
|
};
|
|
};
|
|
}
|