dotfiles/modules/nixos/services/homeassistant/default.nix

82 lines
1.7 KiB
Nix
Raw Normal View History

2023-11-19 16:27:18 +00:00
{
options,
config,
lib,
pkgs,
format,
...
}:
with lib; let
cfg = config.aa.services.homeassistant;
hass_cfg = config.services.home-assistant;
in {
options.aa.services.homeassistant = with types; {
enable = mkEnableOption "home assistant";
acmeCertName = mkOption {
type = str;
default = "";
description = ''
If set to a non-empty string, forces SSL with the supplied acme
certificate.
'';
};
};
config = mkIf cfg.enable {
services.home-assistant = {
enable = true;
extraPackages = python3packages:
with python3packages; [
# postgresql support
psycopg2
];
2023-11-19 16:36:31 +00:00
extraComponents = [
"hue"
"met"
"tuya"
2023-11-24 22:02:09 +00:00
"vizio"
"zeroconf"
2023-11-19 16:36:31 +00:00
];
2023-11-19 16:27:18 +00:00
config = {
default_config = {};
http = {
use_x_forwarded_for = true;
trusted_proxies = ["127.0.0.1"];
};
recorder.db_url = "postgresql://@/hass";
"automation ui" = "!include automations.yaml";
2023-11-19 16:27:18 +00:00
};
};
services.nginx = {
enable = true;
virtualHosts."hass.kilonull.com" =
{
locations."/" = {
recommendedProxySettings = true;
proxyWebsockets = true;
proxyPass = "http://127.0.0.1:${toString hass_cfg.config.http.server_port}";
};
}
// lib.optionalAttrs (cfg.acmeCertName != "") {
forceSSL = true;
useACMEHost = cfg.acmeCertName;
};
};
services.postgresql = {
ensureDatabases = ["hass"];
ensureUsers = [
{
name = "hass";
ensurePermissions = {
"DATABASE hass" = "ALL PRIVILEGES";
};
}
];
};
};
}