2023-11-19 16:27:18 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
2024-08-03 17:32:02 +00:00
|
|
|
namespace,
|
2023-11-19 16:27:18 +00:00
|
|
|
...
|
2024-08-03 17:32:02 +00:00
|
|
|
}: let
|
|
|
|
inherit (lib) mkIf mkEnableOption mkOption types;
|
|
|
|
|
|
|
|
cfg = config.${namespace}.services.homeassistant;
|
2023-11-19 16:27:18 +00:00
|
|
|
hass_cfg = config.services.home-assistant;
|
|
|
|
in {
|
2024-08-03 17:32:02 +00:00
|
|
|
options.${namespace}.services.homeassistant = {
|
2023-11-19 16:27:18 +00:00
|
|
|
enable = mkEnableOption "home assistant";
|
|
|
|
acmeCertName = mkOption {
|
2024-08-03 17:32:02 +00:00
|
|
|
type = types.str;
|
2023-11-19 16:27:18 +00:00
|
|
|
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
|
|
|
|
];
|
2024-01-13 18:00:15 +00:00
|
|
|
|
2023-11-19 16:36:31 +00:00
|
|
|
extraComponents = [
|
2024-02-09 02:41:21 +00:00
|
|
|
"cast"
|
2023-11-19 16:36:31 +00:00
|
|
|
"hue"
|
2023-11-26 17:55:05 +00:00
|
|
|
"met"
|
2023-11-27 02:41:45 +00:00
|
|
|
"mqtt"
|
|
|
|
"octoprint"
|
2023-11-24 22:02:09 +00:00
|
|
|
"vizio"
|
|
|
|
"zeroconf"
|
2023-11-19 16:36:31 +00:00
|
|
|
];
|
2024-01-13 18:00:15 +00:00
|
|
|
|
|
|
|
customComponents = with pkgs.home-assistant-custom-components; [
|
|
|
|
adaptive_lighting
|
|
|
|
];
|
|
|
|
|
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";
|
2023-11-26 17:55:05 +00:00
|
|
|
|
|
|
|
"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";
|
2024-01-13 18:00:15 +00:00
|
|
|
ensureDBOwnership = true;
|
2023-11-19 16:27:18 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|