Skip to content

Commit cb0c5e3

Browse files
home-assistant: add configurePostgres option
1 parent 2f54a6e commit cb0c5e3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

modules/home-assistant.nix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ in
77
{
88
options = {
99
services.home-assistant = {
10+
configurePostgres = lib.mkOption {
11+
type = lib.types.bool;
12+
default = false;
13+
example = true;
14+
description = "Whether to configure and create a local PostgreSQL database.";
15+
};
16+
1017
ldap = {
1118
enable = lib.mkEnableOption ''login only via LDAP
1219
@@ -137,6 +144,10 @@ in
137144
meta = true;
138145
}];
139146
})
147+
148+
(lib.mkIf cfg.configurePostgres {
149+
config.recorder.db_url = "postgresql://@/hass";
150+
})
140151
];
141152

142153
config.services.portunus.seedSettings.groups = lib.optional (cfg.ldap.userGroup != null) {
@@ -149,6 +160,14 @@ in
149160
permissions = { };
150161
};
151162

163+
config.services.postgresql = lib.mkIf cfg.configurePostgres {
164+
ensureDatabases = [ "hass" ];
165+
ensureUsers = [ {
166+
name = "hass";
167+
ensureDBOwnership = true;
168+
} ];
169+
};
170+
152171
config.systemd.tmpfiles.rules = lib.mkIf (cfg.enable && cfg.recommendedDefaults) [
153172
"f ${cfg.configDir}/automations.yaml 0444 hass hass"
154173
"f ${cfg.configDir}/scenes.yaml 0444 hass hass"

0 commit comments

Comments
 (0)