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

38 lines
1.1 KiB
Nix

{ pkgs, ... }:
{
virtualisation.arion = {
backend = "docker";
projects = {
"db".settings.services."db".service = {
restart = "unless-stopped";
build.context = "/nix/store";
build.dockerfile = builtins.baseNameOf "${pkgs.writeScript "pgDockerfile" ''
FROM postgres:16
# install packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
postgresql-16-postgis \
&& rm -rf /var/lib/apt/lists/*
''}";
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/"
];
};
};
};
}