infrastructure/nixos/access/home-assistant.nix
2024-04-15 11:23:20 -07:00

50 lines
1.3 KiB
Nix

{
config,
lib,
access,
...
}: let
inherit (lib.modules) mkDefault;
inherit (config.services) home-assistant nginx;
name.shortServer = mkDefault "home";
listen' = {
http = { };
https.ssl = true;
hass = {
enable = !home-assistant.enable;
port = mkDefault home-assistant.config.http.server_port;
extraParameters = [ "default_server" ];
};
};
in {
config.services.nginx.virtualHosts = {
home-assistant = {
inherit name;
locations."/" = {
proxy = {
websocket.enable = true;
headers.enableRecommended = true;
};
proxyPass = mkDefault (
if home-assistant.enable then "http://localhost:${toString home-assistant.config.http.server_port}"
else access.proxyUrlFor { serviceName = "home-assistant"; }
);
};
};
home-assistant'local = {
inherit name listen';
ssl.cert.copyFromVhost = "home-assistant";
local.enable = mkDefault true;
locations."/" = {
proxy = {
websocket.enable = true;
headers.enableRecommended = true;
};
proxyPass = (mkDefault
nginx.virtualHosts.home-assistant.locations."/".proxyPass
);
};
};
};
config.networking.firewall.allowedTCPPorts = [ home-assistant.config.http.server_port ];
}