Skip to content

Commit 826897a

Browse files
authored
nix run .#start server 15 local dev full config (#1130)
* test: include supautils conf * feat: local dev config matching AMI release * fix: restore old testing conf * feat: make sure macos needed support included * chore: rm logfile --------- Co-authored-by: Sam Rose <[email protected]>
1 parent ea1ebd1 commit 826897a

File tree

2 files changed

+71
-13
lines changed

2 files changed

+71
-13
lines changed

Diff for: flake.nix

+48-5
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,61 @@
276276
# Start a version of the server.
277277
start-server =
278278
let
279-
configFile = ./nix/tests/postgresql.conf.in;
279+
pgconfigFile = builtins.path {
280+
name = "postgresql.conf";
281+
path = ./ansible/files/postgresql_config/postgresql.conf.j2;
282+
};
283+
supautilsConfigFile = builtins.path {
284+
name = "supautils.conf";
285+
path = ./ansible/files/postgresql_config/supautils.conf.j2;
286+
};
287+
loggingConfigFile = builtins.path {
288+
name = "logging.conf";
289+
path = ./ansible/files/postgresql_config/postgresql-csvlog.conf;
290+
};
291+
readReplicaConfigFile = builtins.path {
292+
name = "readreplica.conf";
293+
path = ./ansible/files/postgresql_config/custom_read_replica.conf.j2;
294+
};
295+
pgHbaConfigFile = builtins.path {
296+
name = "pg_hba.conf";
297+
path = ./ansible/files/postgresql_config/pg_hba.conf.j2;
298+
};
299+
pgIdentConfigFile = builtins.path {
300+
name = "pg_ident.conf";
301+
path = ./ansible/files/postgresql_config/pg_ident.conf.j2;
302+
};
280303
getkeyScript = ./nix/tests/util/pgsodium_getkey.sh;
304+
localeArchive = if pkgs.stdenv.isDarwin
305+
then "${pkgs.darwin.locale}/share/locale"
306+
else "${pkgs.glibcLocales}/lib/locale/locale-archive";
281307
in
282308
pkgs.runCommand "start-postgres-server" { } ''
283-
mkdir -p $out/bin
309+
mkdir -p $out/bin $out/etc/postgresql-custom $out/etc/postgresql
310+
cp ${supautilsConfigFile} $out/etc/postgresql-custom/supautils.conf || { echo "Failed to copy supautils.conf"; exit 1; }
311+
cp ${pgconfigFile} $out/etc/postgresql/postgresql.conf || { echo "Failed to copy postgresql.conf"; exit 1; }
312+
cp ${loggingConfigFile} $out/etc/postgresql-custom/logging.conf || { echo "Failed to copy logging.conf"; exit 1; }
313+
cp ${readReplicaConfigFile} $out/etc/postgresql-custom/read-replica.conf || { echo "Failed to copy read-replica.conf"; exit 1; }
314+
cp ${pgHbaConfigFile} $out/etc/postgresql/pg_hba.conf || { echo "Failed to copy pg_hba.conf"; exit 1; }
315+
cp ${pgIdentConfigFile} $out/etc/postgresql/pg_ident.conf || { echo "Failed to copy pg_ident.conf"; exit 1; }
316+
echo "Copy operation completed"
317+
chmod 644 $out/etc/postgresql-custom/supautils.conf
318+
chmod 644 $out/etc/postgresql/postgresql.conf
319+
chmod 644 $out/etc/postgresql-custom/logging.conf
320+
chmod 644 $out/etc/postgresql/pg_hba.conf
284321
substitute ${./nix/tools/run-server.sh.in} $out/bin/start-postgres-server \
285322
--subst-var-by 'PGSQL_DEFAULT_PORT' '${pgsqlDefaultPort}' \
286323
--subst-var-by 'PGSQL_SUPERUSER' '${pgsqlSuperuser}' \
287324
--subst-var-by 'PSQL15_BINDIR' '${basePackages.psql_15.bin}' \
288-
--subst-var-by 'PSQL_CONF_FILE' '${configFile}' \
289-
--subst-var-by 'PGSODIUM_GETKEY' '${getkeyScript}'
290-
325+
--subst-var-by 'PSQL_CONF_FILE' $out/etc/postgresql/postgresql.conf \
326+
--subst-var-by 'PGSODIUM_GETKEY' '${getkeyScript}' \
327+
--subst-var-by 'READREPL_CONF_FILE' "$out/etc/postgresql-custom/read-replica.conf" \
328+
--subst-var-by 'LOGGING_CONF_FILE' "$out/etc/postgresql-custom/logging.conf" \
329+
--subst-var-by 'SUPAUTILS_CONF_FILE' "$out/etc/postgresql-custom/supautils.conf" \
330+
--subst-var-by 'PG_HBA' "$out/etc/postgresql/pg_hba.conf" \
331+
--subst-var-by 'PG_IDENT' "$out/etc/postgresql/pg_ident.conf" \
332+
--subst-var-by 'LOCALES' '${localeArchive}'
333+
291334
chmod +x $out/bin/start-postgres-server
292335
'';
293336

Diff for: nix/tools/run-server.sh.in

+23-8
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,36 @@ PGSQL_SUPERUSER=@PGSQL_SUPERUSER@
2727
PSQL_CONF_FILE=@PSQL_CONF_FILE@
2828
PGSODIUM_GETKEY_SCRIPT=@PGSODIUM_GETKEY@
2929
PORTNO="${2:-@PGSQL_DEFAULT_PORT@}"
30-
PLJAVA_LIBJVM_LOCATION=@LIBJVM_LOCATION@
30+
SUPAUTILS_CONFIG_FILE=@SUPAUTILS_CONF_FILE@
31+
LOGGING_CONFIG_FILE=@LOGGING_CONF_FILE@
32+
READREPL_CONFIG_FILE=@READREPL_CONF_FILE@
33+
PG_HBA_FILE=@PG_HBA@
34+
PG_IDENT_FILE=@PG_IDENT@
3135
DATDIR=$(mktemp -d)
36+
LOCALE_ARCHIVE=@LOCALES@
37+
export LOCALE_ARCHIVE
38+
export LANG=en_US.UTF-8
39+
export LANGUAGE=en_US.UTF-8
40+
export LC_ALL=en_US.UTF-8
41+
export LANG=en_US.UTF-8
42+
export LC_CTYPE=en_US.UTF-8
3243
mkdir -p "$DATDIR"
3344

3445
echo "NOTE: using port $PORTNO for server"
3546
echo "NOTE: using temporary directory $DATDIR for data, which will not be removed"
3647
echo "NOTE: you are free to re-use this data directory at will"
37-
echo
3848

39-
initdb -U "$PGSQL_SUPERUSER" -D "$DATDIR" --locale=C
49+
initdb -U "$PGSQL_SUPERUSER" -D "$DATDIR"
4050

4151
echo "NOTE: patching postgresql.conf files"
42-
echo "pljava libjvm location: $PLJAVA_LIBJVM_LOCATION"
43-
sed -e "s#@PGSODIUM_GETKEY_SCRIPT@#$PGSODIUM_GETKEY_SCRIPT#g" \
44-
-e "s#@PLJAVA_LIBJVM_LOCATION@#$PLJAVA_LIBJVM_LOCATION#g" \
45-
$PSQL_CONF_FILE > "$DATDIR/postgresql.conf"
4652

47-
exec postgres -p "$PORTNO" -D "$DATDIR" -k /tmp
53+
sed -e "\$a\\
54+
include = '$SUPAUTILS_CONFIG_FILE' \\
55+
pgsodium.getkey_script = '$PGSODIUM_GETKEY_SCRIPT'" \
56+
-e "s|data_directory = '/var/lib/postgresql/data'|data_directory = '$DATDIR'|" \
57+
-e "s|hba_file = '/etc/postgresql/pg_hba.conf'|hba_file = '$PG_HBA_FILE'|" \
58+
-e "s|ident_file = '/etc/postgresql/pg_ident.conf'|ident_file = '$PG_IDENT_FILE'|" \
59+
-e "s|include = '/etc/postgresql/logging.conf'|#&|" \
60+
-e "s|include = '/etc/postgresql-custom/read-replica.conf'|include = '$READREPL_CONFIG_FILE'|" \
61+
"$PSQL_CONF_FILE" > "$DATDIR/postgresql.conf"
62+
postgres -p "$PORTNO" -D "$DATDIR" -k /tmp

0 commit comments

Comments
 (0)