summary refs log tree commit diff
path: root/services/home-assistant.nix
blob: cf594b0e0f3753d22009f860f042be67c75f10c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{ me, auxiliaryPkgs, ... }:

let
  inherit (auxiliaryPkgs) common;

  homeVersion = "2025.3.3";
  homeDir = "/srv/home";
  homeLocalPort = 8123;

  homeImage = common.pullImage {
    name = "homeassistant/home-assistant";
    tag = homeVersion;
    digest = "sha256:b67d76f5d0bacf55cf6c914be379a0436a1da1f8acb94ee08e3b108d46cf8c58";
    x86.sha256 = "06ijcvdzax473fsy90657jmr2vjzh5pwdssk2vzgva8d6g3d396l";
  };

in
{
  foundation.service.home-assistant = {
    default = {
      fullImage = homeImage;
      # give home-assistant control over the device network
      # stack to auto-discover devices on the network.
      customNetwork = "host";
      volumes = [
        [
          "/etc/localtime"
          "/etc/localtime:ro"
        ]
        [
          "${homeDir}/config"
          "/config"
        ]
      ];
      ports = [ 8123 ];
    };

    # additional services can be added here to enable
    # more home-manager device integrations.
  };

  services.nginx.virtualHosts = {
    "home.rnrd.fyi" = {
      useACMEHost = "rnrd.fyi";
      forceSSL = true;
      listenAddresses = [ me.tailscale.ip ];
      locations."/" = {
        proxyPass = "http://127.0.0.1:${toString homeLocalPort}";
        proxyWebsockets = true;
      };
      extraConfig = ''
        proxy_buffering off;
        access_log /var/log/nginx/home.access.log json_combined;
      '';
    };
  };
}