From bafa1a9b9e1d5fdfcb10d5afeb56241b9eacf489 Mon Sep 17 00:00:00 2001 From: James Walker Date: Wed, 14 Jul 2021 22:49:45 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=A0=20initial=20home-assistant=20setup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hosts/plato/configuration.nix | 1 + hosts/socrates/configuration.nix | 1 + modules/home-assistant/default.nix | 15 +++++++++++++++ modules/home-assistant/nginx.nix | 17 +++++++++++++++++ modules/home-assistant/postgresql.nix | 13 +++++++++++++ 5 files changed, 47 insertions(+) create mode 100644 modules/home-assistant/default.nix create mode 100644 modules/home-assistant/nginx.nix create mode 100644 modules/home-assistant/postgresql.nix diff --git a/hosts/plato/configuration.nix b/hosts/plato/configuration.nix index 768ddc4..9c73d42 100644 --- a/hosts/plato/configuration.nix +++ b/hosts/plato/configuration.nix @@ -9,6 +9,7 @@ in { ../../modules/coredns + ../../modules/home-assistant ../../modules/matrix ]; diff --git a/hosts/socrates/configuration.nix b/hosts/socrates/configuration.nix index 89bd6f9..a55441a 100644 --- a/hosts/socrates/configuration.nix +++ b/hosts/socrates/configuration.nix @@ -10,6 +10,7 @@ in { ../../modules/coredns + ../../modules/home-assistant/nginx.nix ../../modules/matrix/nginx.nix ]; diff --git a/modules/home-assistant/default.nix b/modules/home-assistant/default.nix new file mode 100644 index 0000000..0b183ce --- /dev/null +++ b/modules/home-assistant/default.nix @@ -0,0 +1,15 @@ +{ config, lib, pkgs, ... }: + +{ + # Use the docker container because it's officially supported. + virtualisation.oci-containers = { + containers = { + home-assistant = { + image = "ghcr.io/home-assistant/home-assistant:2021.7.2"; + volumes = + [ "/var/lib/hass:/config" "/etc/localtime:/etc/localtime:ro" ]; + extraOptions = [ "--privileged" "--network=host" ]; + }; + }; + }; +} diff --git a/modules/home-assistant/nginx.nix b/modules/home-assistant/nginx.nix new file mode 100644 index 0000000..52896db --- /dev/null +++ b/modules/home-assistant/nginx.nix @@ -0,0 +1,17 @@ +{ config, lib, pkgs, ... }: + +{ + services.nginx = { + enable = true; + virtualHosts = { + "hass.nerdhaus.ca" = { + forceSSL = true; + enableACME = true; + locations."/" = { + proxyPass = "http://plato:8123"; + proxyWebsockets = true; + }; + }; + }; + }; +} diff --git a/modules/home-assistant/postgresql.nix b/modules/home-assistant/postgresql.nix new file mode 100644 index 0000000..0ca40ff --- /dev/null +++ b/modules/home-assistant/postgresql.nix @@ -0,0 +1,13 @@ +{ config, lib, pkgs, ... }: + +{ + services = { + postgresql = { + ensureDatabases = [ "hass" ]; + ensureUsers = [{ + name = "hass"; + ensurePermissions = { "DATABASE hass" = "ALL PRIVILEGES"; }; + }]; + }; + }; +}