2024-06-14 02:58:39 +03:00
|
|
|
{ container, lib, pkgs, ... } @args: let
|
2024-06-01 10:37:49 +03:00
|
|
|
cfg = container.config.postgres;
|
|
|
|
in {
|
|
|
|
systemd.tmpfiles.rules = container.mkContainerDir cfg [
|
|
|
|
"data"
|
|
|
|
];
|
|
|
|
|
|
|
|
containers.postgres = container.mkContainer cfg {
|
|
|
|
bindMounts = {
|
|
|
|
"/var/lib/postgresql/data" = {
|
|
|
|
hostPath = "${cfg.storage}/data";
|
|
|
|
isReadOnly = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-06-14 02:58:39 +03:00
|
|
|
config = { ... }: container.mkContainerConfig cfg {
|
2024-06-01 10:37:49 +03:00
|
|
|
services.postgresql = let
|
2024-06-09 23:35:53 +03:00
|
|
|
# Populate with services here.
|
|
|
|
configurations = with container.config; {
|
|
|
|
gitea = git;
|
|
|
|
nextcloud = cloud;
|
|
|
|
privatebin = paste;
|
|
|
|
onlyoffice = office;
|
|
|
|
paperless = paper;
|
|
|
|
invidious = yt;
|
|
|
|
};
|
|
|
|
|
|
|
|
access = configurations // {
|
|
|
|
all = { address = container.host; };
|
|
|
|
};
|
|
|
|
|
|
|
|
authentication = builtins.foldl' (acc: item: acc + "${item}\n") "" (
|
|
|
|
lib.mapAttrsToList (db: cfg: "host ${db} ${db} ${cfg.address}/32 trust") access
|
|
|
|
);
|
|
|
|
|
|
|
|
ensureDatabases = [ "root" ] ++ lib.mapAttrsToList (name: _: name) configurations;
|
|
|
|
|
|
|
|
ensureUsers = map (name: {
|
|
|
|
inherit name;
|
|
|
|
ensureClauses = if name == "root" then {
|
|
|
|
superuser = true;
|
|
|
|
createrole = true;
|
|
|
|
createdb = true;
|
|
|
|
} else {};
|
|
|
|
ensureDBOwnership = true;
|
|
|
|
}) ensureDatabases;
|
2024-06-01 10:37:49 +03:00
|
|
|
in {
|
2024-06-09 23:35:53 +03:00
|
|
|
inherit authentication ensureDatabases ensureUsers;
|
|
|
|
|
2024-06-01 10:37:49 +03:00
|
|
|
enable = true;
|
|
|
|
package = pkgs.postgresql_14;
|
|
|
|
dataDir = "/var/lib/postgresql/data/14";
|
|
|
|
enableTCPIP = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|