nix/container/Postgres.nix

45 lines
914 B
Nix
Raw Normal View History

2024-06-09 15:31:53 +03:00
{ storage
2024-06-01 10:37:49 +03:00
, host
, mkContainer
, mkContainerConfig
2024-06-09 15:31:53 +03:00
, mkContainerDir
2024-06-01 10:37:49 +03:00
, ... } @args: let
2024-06-09 15:31:53 +03:00
address = "10.1.0.3";
path = "${storage}/postgres";
2024-06-01 10:37:49 +03:00
in {
2024-06-09 15:31:53 +03:00
systemd.tmpfiles.rules = map (dir: mkContainerDir "${path}/${dir}") [
"data"
];
2024-06-01 10:37:49 +03:00
2024-06-09 15:31:53 +03:00
containers.postgres = mkContainer address {
2024-06-01 10:37:49 +03:00
bindMounts = {
"/var/lib/postgresql/data" = {
hostPath = "${path}/data";
isReadOnly = false;
};
};
2024-06-09 16:26:05 +03:00
config = { pkgs, ... }: mkContainerConfig {
2024-06-01 10:37:49 +03:00
services.postgresql = let
databases = [
"privatebin"
];
in {
enable = true;
package = pkgs.postgresql_14;
dataDir = "/var/lib/postgresql/data/14";
enableTCPIP = true;
authentication = ''
host all all ${host}/32 trust
host privatebin privatebin 10.1.0.14/32 trust
'';
ensureDatabases = databases;
ensureUsers = map (name: {
inherit name;
ensureDBOwnership = true;
}) databases;
};
};
};
}