nix/container/Iot.nix

107 lines
2.3 KiB
Nix
Raw Normal View History

2024-06-25 04:04:39 +03:00
{ container, lib, config, ... }: with lib; let
cfg = config.container.module.iot;
2024-06-09 23:35:53 +03:00
in {
2024-06-25 04:04:39 +03:00
options = {
container.module.iot = {
enable = mkEnableOption "IoT service.";
address = mkOption {
default = "10.1.0.27";
type = types.str;
};
port = mkOption {
default = 8123;
type = types.int;
2024-06-09 23:35:53 +03:00
};
2024-06-25 04:04:39 +03:00
domain = mkOption {
default = "iot.${config.container.domain}";
type = types.str;
2024-06-13 17:00:05 +03:00
};
2024-06-25 04:04:39 +03:00
storage = mkOption {
default = "${config.container.storage}/iot";
type = types.str;
2024-06-13 17:00:05 +03:00
};
2024-06-25 04:04:39 +03:00
};
};
2024-06-13 17:00:05 +03:00
2024-06-25 04:04:39 +03:00
config = mkIf cfg.enable {
systemd.tmpfiles.rules = container.mkContainerDir cfg [
"data"
2024-06-13 17:00:05 +03:00
];
2024-06-25 04:04:39 +03:00
containers.iot = container.mkContainer cfg {
bindMounts = {
"/var/lib/hass" = {
hostPath = "${cfg.storage}/data";
isReadOnly = false;
};
"/dev/ttyACM0" = {
hostPath = "/dev/ttyACM0";
isReadOnly = false;
};
"/dev/serial/by-id" = {
hostPath = "/dev/serial/by-id";
isReadOnly = false;
};
} // container.attachMedia "photo" true;
allowedDevices = [
{
modifier = "rwm";
node = "/dev/ttyACM0";
}
];
config = { ... }: container.mkContainerConfig cfg {
# Allow Hass to talk to Zigbee dongle.
users.users.hass.extraGroups = [ "dialout" "tty" ];
2024-06-09 23:35:53 +03:00
2024-06-25 04:04:39 +03:00
services.home-assistant = {
# NOTE: Missing: hacs. Inside hacs: `card-mod`, `Clock Weather Card`, `WallPanel` and `Yandex.Station`.
enable = true;
extraComponents = [
"caldav"
"met"
"sun"
"systemmonitor"
"zha"
];
extraPackages = python3Packages: with python3Packages; [
aiodhcpwatcher
aiodiscover
aiogithubapi
async-upnp-client
ha-av
ha-ffmpeg
hassil
home-assistant-intents
mutagen
numpy
pynacl
pyturbojpeg
python-telegram-bot
zeroconf
];
configDir = "/var/lib/hass";
# lovelaceConfig = {
# title = "Home IoT control center.";
# };
# NOTE: Using imperative config because of secrets.
config = null;
};
# HACK: Delay so that nextcloud calendar can reply on reboot.
systemd = {
services."home-assistant".wantedBy = mkForce [];
timers.fixsystemd = {
timerConfig = {
2024-06-30 00:47:21 +03:00
OnBootSec = 15;
Unit = "home-assistant.service";
};
wantedBy = [ "timers.target" ];
};
};
2024-06-09 23:35:53 +03:00
};
};
};
}