added postgres config to home assistant
This commit is contained in:
parent
9715517af6
commit
0e5d8e3335
|
@ -1,9 +1,11 @@
|
|||
{
|
||||
lib,
|
||||
pkgs,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
configDir = "/var/lib/hass";
|
||||
db_user = "hass";
|
||||
in {
|
||||
options.host.home-assistant = {
|
||||
enable = lib.mkEnableOption "should home-assistant be enabled on this computer";
|
||||
|
@ -16,8 +18,18 @@ in {
|
|||
|
||||
config = lib.mkIf config.host.home-assistant.enable (lib.mkMerge [
|
||||
{
|
||||
systemd.tmpfiles.rules = [
|
||||
"f ${config.services.home-assistant.configDir}/automations.yaml 0755 hass hass"
|
||||
];
|
||||
services.home-assistant = {
|
||||
enable = true;
|
||||
package =
|
||||
(pkgs.home-assistant.override {
|
||||
extraPackages = py: with py; [psycopg2];
|
||||
})
|
||||
.overrideAttrs (oldAttrs: {
|
||||
doInstallCheck = false;
|
||||
});
|
||||
configDir = configDir;
|
||||
extraComponents = [
|
||||
"met"
|
||||
|
@ -35,14 +47,6 @@ in {
|
|||
"openweathermap"
|
||||
];
|
||||
config = {
|
||||
homeassistant = {
|
||||
name = "Home";
|
||||
latitude = "!secret latitude";
|
||||
longitude = "!secret longitude";
|
||||
elevation = "!secret elevation";
|
||||
unit_system = "metric";
|
||||
time_zone = "CDT";
|
||||
};
|
||||
http = {
|
||||
server_port = 8082;
|
||||
use_x_forwarded_for = true;
|
||||
|
@ -50,6 +54,9 @@ in {
|
|||
ip_ban_enabled = true;
|
||||
login_attempts_threshold = 10;
|
||||
};
|
||||
recorder.db_url = "postgresql://@/${db_user}";
|
||||
"automation manual" = [];
|
||||
"automation ui" = "!include automations.yaml";
|
||||
};
|
||||
extraPackages = python3Packages:
|
||||
with python3Packages; [
|
||||
|
@ -57,6 +64,11 @@ in {
|
|||
gtts
|
||||
];
|
||||
};
|
||||
systemd.services.home-assistant = {
|
||||
requires = [
|
||||
"postgresql.service"
|
||||
];
|
||||
};
|
||||
host = {
|
||||
reverse_proxy.subdomains.${config.host.home-assistant.subdomain} = {
|
||||
target = "http://localhost:${toString config.services.home-assistant.config.http.server_port}";
|
||||
|
@ -77,6 +89,20 @@ in {
|
|||
proxy_read_timeout 90;
|
||||
'';
|
||||
};
|
||||
postgres = {
|
||||
enable = true;
|
||||
extraUsers = {
|
||||
${db_user} = {
|
||||
isClient = true;
|
||||
createUser = true;
|
||||
};
|
||||
};
|
||||
extraDatabases = {
|
||||
${db_user} = {
|
||||
name = db_user;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
(lib.mkIf config.host.impermanence.enable {
|
||||
|
|
|
@ -65,6 +65,7 @@ in {
|
|||
++ (
|
||||
builtins.map (user: {
|
||||
name = user.name;
|
||||
ensureDBOwnership = true;
|
||||
})
|
||||
createUsers
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue