mirror of
https://github.com/juspay/services-flake.git
synced 2024-09-11 12:26:04 +03:00
postgres: add socketDir option (#77)
This commit is contained in:
parent
bf3a582502
commit
1a3f2d1936
@ -50,6 +50,12 @@ in
|
|||||||
description = "The DB data directory";
|
description = "The DB data directory";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
socketDir = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = config.dataDir;
|
||||||
|
description = "The DB socket directory";
|
||||||
|
};
|
||||||
|
|
||||||
hbaConf =
|
hbaConf =
|
||||||
let
|
let
|
||||||
hbaConfSubmodule = lib.types.submodule {
|
hbaConfSubmodule = lib.types.submodule {
|
||||||
@ -161,7 +167,7 @@ in
|
|||||||
default = {
|
default = {
|
||||||
listen_addresses = config.listen_addresses;
|
listen_addresses = config.listen_addresses;
|
||||||
port = config.port;
|
port = config.port;
|
||||||
unix_socket_directories = config.dataDir;
|
unix_socket_directories = config.socketDir;
|
||||||
hba_file = "${config.hbaConfFile}";
|
hba_file = "${config.hbaConfFile}";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -181,7 +187,7 @@ in
|
|||||||
default = {
|
default = {
|
||||||
listen_addresses = config.listen_addresses;
|
listen_addresses = config.listen_addresses;
|
||||||
port = config.port;
|
port = config.port;
|
||||||
unix_socket_directories = lib.mkDefault config.dataDir;
|
unix_socket_directories = lib.mkDefault config.socketDir;
|
||||||
hba_file = "${config.hbaConfFile}";
|
hba_file = "${config.hbaConfFile}";
|
||||||
};
|
};
|
||||||
example = lib.literalExpression ''
|
example = lib.literalExpression ''
|
||||||
@ -292,12 +298,13 @@ in
|
|||||||
text = ''
|
text = ''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
PGDATA=$(readlink -f "${config.dataDir}")
|
PGDATA=$(readlink -f "${config.dataDir}")
|
||||||
|
PGSOCKETDIR=$(readlink -f "${config.socketDir}")
|
||||||
export PGDATA
|
export PGDATA
|
||||||
postgres -k "$PGDATA"
|
postgres -k "$PGSOCKETDIR"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
pg_isreadyArgs = [
|
pg_isreadyArgs = [
|
||||||
"-h $(readlink -f ${config.dataDir})"
|
"-h $(readlink -f \"${config.socketDir}\")"
|
||||||
"-p ${toString config.port}"
|
"-p ${toString config.port}"
|
||||||
"-d template1"
|
"-d template1"
|
||||||
] ++ (lib.optional (config.superuser != null) "-U ${config.superuser}");
|
] ++ (lib.optional (config.superuser != null) "-U ${config.superuser}");
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
{ config, pkgs, lib }:
|
{ config, pkgs, lib }:
|
||||||
let
|
let
|
||||||
setupInitialSchema = dbName: schema: ''
|
setupInitialSchema = dbName: schema: ''
|
||||||
${lib.optionalString (schema != null) ''
|
|
||||||
echo "Applying database schema on ${dbName}"
|
echo "Applying database schema on ${dbName}"
|
||||||
if [ -f "${schema}" ]
|
if [ -f "${schema}" ]
|
||||||
then
|
then
|
||||||
@ -20,7 +19,6 @@ let
|
|||||||
echo "ERROR: Could not determine how to apply schema with ${schema}"
|
echo "ERROR: Could not determine how to apply schema with ${schema}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
''}
|
|
||||||
'';
|
'';
|
||||||
setupInitialDatabases =
|
setupInitialDatabases =
|
||||||
if config.initialDatabases != [ ] then
|
if config.initialDatabases != [ ] then
|
||||||
@ -37,7 +35,8 @@ let
|
|||||||
if [ 1 -ne "$dbAlreadyExists" ]; then
|
if [ 1 -ne "$dbAlreadyExists" ]; then
|
||||||
echo "Creating database: ${database.name}"
|
echo "Creating database: ${database.name}"
|
||||||
echo 'create database "${database.name}";' | psql -d postgres
|
echo 'create database "${database.name}";' | psql -d postgres
|
||||||
${lib.concatMapStrings (schema: setupInitialSchema (database.name) schema) database.schemas}
|
${lib.optionalString (database.schemas != null)
|
||||||
|
(lib.concatMapStrings (schema: setupInitialSchema (database.name) schema) database.schemas)}
|
||||||
fi
|
fi
|
||||||
'')
|
'')
|
||||||
config.initialDatabases)
|
config.initialDatabases)
|
||||||
@ -101,7 +100,7 @@ in
|
|||||||
echo
|
echo
|
||||||
echo "PostgreSQL is setting up the initial database."
|
echo "PostgreSQL is setting up the initial database."
|
||||||
echo
|
echo
|
||||||
PGHOST=$(mktemp -d "$(readlink -f ${config.dataDir})/pg-init-XXXXXX")
|
PGHOST=$(mktemp -d "$(readlink -f "${config.socketDir}")/pg-init-XXXXXX")
|
||||||
export PGHOST
|
export PGHOST
|
||||||
|
|
||||||
function remove_tmp_pg_init_sock_dir() {
|
function remove_tmp_pg_init_sock_dir() {
|
||||||
|
Loading…
Reference in New Issue
Block a user