nixos/hosts/common/optional/docker/postgres.nix

30 lines
755 B
Nix

{ pkgs, ... }:
{
virtualisation.arion = {
backend = "docker";
projects = {
"db".settings.services."db".service = {
image = "postgres:16";
restart = "unless-stopped";
environment = {
POSTGRES_PASSWORD = "balls1234";
POSTGRES_USER = "admin";
POSTGRES_DATABASE = "test_db";
};
ports = [ "5432:5432" ];
volumes = [
"/mnt/postgres/data:/var/lib/postgres/data"
"${pkgs.writeScript "load_extensions" ''
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<EOF
create extension postgis;
select * FROM pg_extension;
EOF
''}:/docker-entrypoint-initdb.d/"
];
};
};
};
}