diff --git a/nix/postgres/default.nix b/nix/postgres/default.nix index 8611e03f..f9d114e7 100644 --- a/nix/postgres/default.nix +++ b/nix/postgres/default.nix @@ -323,7 +323,7 @@ in ''; }; pg_isreadyArgs = [ - "-h ${config.listen_addresses}" + (if config.socketDir != "" then "-h $(readlink -f \"${config.socketDir}\")" else "-h ${config.listen_addresses}") "-p ${toString config.port}" "-d template1" ] ++ (lib.optional (config.superuser != null) "-U ${config.superuser}"); diff --git a/nix/postgres/postgres_test.nix b/nix/postgres/postgres_test.nix index d2b0580e..1adf9789 100644 --- a/nix/postgres/postgres_test.nix +++ b/nix/postgres/postgres_test.nix @@ -16,8 +16,19 @@ } ]; }; + services.postgres."pg3" = { + enable = true; + socketDir = "./test/new/socket/path2"; + listen_addresses = ""; + initialDatabases = [ + { + name = "test-db"; + } + ]; + }; # avoid both the processes trying to create `data` directory at the same time settings.processes."pg2-init".depends_on."pg1-init".condition = "process_completed_successfully"; + settings.processes."pg3-init".depends_on."pg2-init".condition = "process_completed_successfully"; settings.processes.test = let cfg = config.services.postgres."pg1"; @@ -37,12 +48,16 @@ # schemas test echo "SELECT * from users where user_name = 'test_user';" | psql -h 127.0.0.1 -p 5433 -d sample-db | grep -q test_user + + # listen_addresses test + echo "SELECT 1 FROM pg_database where datname = 'test-db';" | psql -h "$(readlink -f ${config.services.postgres.pg3.socketDir})" -d postgres | grep -q 1 ''; name = "postgres-test"; }; depends_on = { "pg1".condition = "process_healthy"; "pg2".condition = "process_healthy"; + "pg3".condition = "process_healthy"; }; }; }