70 lines
1.8 KiB
Nix
70 lines
1.8 KiB
Nix
let
|
|
nixpkgs = import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/24.11-beta.tar.gz") {
|
|
overlays = [];
|
|
config = {};
|
|
};
|
|
|
|
in
|
|
with nixpkgs;
|
|
|
|
stdenv.mkDerivation {
|
|
name = "postgres-env";
|
|
buildInputs = [];
|
|
|
|
nativeBuildInputs = [
|
|
zsh
|
|
vim
|
|
geos
|
|
gdal
|
|
nixpkgs-fmt
|
|
nodejs_22
|
|
openssl
|
|
prisma
|
|
|
|
# postgres-12 with postgis support
|
|
(postgresql_12.withPackages (p: [ p.postgis ]))
|
|
];
|
|
|
|
postgresConf =
|
|
writeText "postgresql.conf"
|
|
''
|
|
# Add Custom Settings
|
|
log_min_messages = warning
|
|
log_min_error_statement = error
|
|
log_min_duration_statement = 100 # ms
|
|
log_connections = on
|
|
log_disconnections = on
|
|
log_duration = on
|
|
#log_line_prefix = '[] '
|
|
log_timezone = 'UTC'
|
|
log_statement = 'all'
|
|
log_directory = 'pg_log'
|
|
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
|
|
logging_collector = on
|
|
log_min_error_statement = error
|
|
'';
|
|
|
|
|
|
# ENV Variables
|
|
LD_LIBRARY_PATH = "${geos}/lib:${gdal}/lib";
|
|
PGDATA = "${toString ./.}/.pg";
|
|
|
|
# Post Shell Hook
|
|
shellHook = ''
|
|
echo "Using ${postgresql_12.name}."
|
|
|
|
# Setup: other env variables
|
|
export PGHOST="$PGDATA"
|
|
export PRISMA_SCHEMA_ENGINE_BINARY="${pkgs.prisma-engines}/bin/schema-engine"
|
|
export PRISMA_QUERY_ENGINE_BINARY="${pkgs.prisma-engines}/bin/query-engine"
|
|
export PRISMA_QUERY_ENGINE_LIBRARY="${pkgs.prisma-engines}/lib/libquery_engine.node"
|
|
export PRISMA_FMT_BINARY="${pkgs.prisma-engines}/bin/prisma-fmt"
|
|
export PATH="$PWD/node_modules/.bin/:$PATH"
|
|
|
|
# Setup: DB
|
|
[ ! -d $PGDATA ] && pg_ctl initdb -o "-U postgres" && cat "$postgresConf" >> $PGDATA/postgresql.conf
|
|
pg_ctl -o "-p 5555 -k $PGDATA" start
|
|
alias fin="pg_ctl stop && exit"
|
|
alias pg="psql -p 5555 -U postgres"
|
|
'';
|
|
}
|