Fix db
This commit is contained in:
@@ -10,26 +10,28 @@ let
|
||||
allApps = lib.unique (listNames ++ containerNames);
|
||||
|
||||
in {
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
ensureDatabases = map (name: "${name}_db") allApps;
|
||||
ensureUsers = map (name: { name = "${name}_user"; }) allApps;
|
||||
backup = {
|
||||
enable = true;
|
||||
location = "/var/lib/postgresql/backups";
|
||||
startAt = "-- 04:00:00"; # Runs every day at 4 AM
|
||||
backupAll = true; # Backs up all databases and roles
|
||||
config = lib.mkIf ( builtins.length allApps > 0) {
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
ensureDatabases = map (name: "${name}_db") allApps;
|
||||
ensureUsers = map (name: { name = "${name}_user"; }) allApps;
|
||||
backup = {
|
||||
enable = true;
|
||||
location = "/var/lib/postgresql/backups";
|
||||
startAt = "-- 04:00:00"; # Runs every day at 4 AM
|
||||
backupAll = true; # Backs up all databases and roles
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.postgresql.postStart = lib.mkAfter ''
|
||||
${lib.concatMapStringsSep "\n" (name: ''
|
||||
$PSQL -tAc "ALTER DATABASE ${name}_db OWNER TO ${name}_user;"
|
||||
|
||||
if [ -f "${config.sops.secrets."${name}_pass".path}" ]; then
|
||||
PASS=$(cat "${config.sops.secrets."${name}_pass".path}")
|
||||
$PSQL -tAc "ALTER USER ${name}_user WITH PASSWORD '$PASS';"
|
||||
fi
|
||||
'') allApps}
|
||||
'';
|
||||
systemd.services.postgresql.postStart = lib.mkAfter ''
|
||||
${lib.concatMapStringsSep "\n" (name: ''
|
||||
$PSQL -tAc "ALTER DATABASE ${name}_db OWNER TO ${name}_user;"
|
||||
|
||||
if [ -f "${config.sops.secrets."${name}_pass".path}" ]; then
|
||||
PASS=$(cat "${config.sops.secrets."${name}_pass".path}")
|
||||
$PSQL -tAc "ALTER USER ${name}_user WITH PASSWORD '$PASS';"
|
||||
fi
|
||||
'') allApps}
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
{ config, pkgs, lib, ... }:{
|
||||
imports = [ ./sops ./nftables ./openssh ./containers ];
|
||||
imports = [ ./containers ./database ./nftables ./openssh ./sops ];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user