mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
refactor: postgresql
This commit is contained in:
parent
a50966a8ea
commit
3d188ab76e
8 changed files with 80 additions and 13 deletions
|
|
@ -1,12 +1,10 @@
|
|||
{
|
||||
pkgs,
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
cfg = config.services.home-assistant;
|
||||
inherit (lib.modules) mkDefault;
|
||||
inherit (lib.lists) optional;
|
||||
inherit (lib.modules) mkIf mkDefault;
|
||||
in {
|
||||
sops.secrets = {
|
||||
ha-integration = {
|
||||
|
|
@ -49,6 +47,7 @@ in {
|
|||
use_webhook = true;
|
||||
};
|
||||
recorder = {
|
||||
db_url = mkIf (!config.services.postgresql.enable) "!secret db_url";
|
||||
auto_purge = true;
|
||||
purge_keep_days = 14;
|
||||
commit_interval = 1;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,31 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: {
|
||||
}: let
|
||||
inherit (lib.modules) mkIf mkDefault mkAfter;
|
||||
cfg = config.services.postgresql;
|
||||
in {
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
package = pkgs.postgresql_14;
|
||||
enable = mkDefault true;
|
||||
ensureDatabases = ["hass"];
|
||||
ensureUsers = [
|
||||
{
|
||||
name = "hass";
|
||||
ensureDBOwnership = true;
|
||||
tailscale.allow = !config.services.home-assistant.enable;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services.postgresql = mkIf cfg.enable {
|
||||
postStart = mkAfter ''
|
||||
$PSQL -tAf ${config.sops.secrets.postgresql-init.path}
|
||||
'';
|
||||
};
|
||||
|
||||
sops.secrets.postgresql-init = {
|
||||
owner = "postgres";
|
||||
group = "postgres";
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue