diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix index a7016bbee3a86..1c16a5007291c 100644 --- a/nixos/modules/services/databases/postgresql.nix +++ b/nixos/modules/services/databases/postgresql.nix @@ -69,6 +69,15 @@ in ''; }; + socketDir = mkOption { + type = with types; nullOr path; + default = /run/postgresql; + description = lib.mdDoc '' + Directory where PostgreSQL opens a UNIX domain socket to which clients can connect. + A null value opens no socket, leaving PostgreSQL accessible only via TCP/IP. + ''; + }; + checkConfig = mkOption { type = types.bool; default = true; @@ -446,6 +455,7 @@ in log_line_prefix = cfg.logLinePrefix; listen_addresses = if cfg.enableTCPIP then "*" else "localhost"; port = cfg.port; + unix_socket_directories = toString cfg.socketDir; jit = mkDefault (if cfg.enableJIT then "on" else "off"); }; @@ -522,9 +532,10 @@ in ''; # Wait for PostgreSQL to be ready to accept connections. - postStart = - '' - PSQL="psql --port=${toString cfg.port}" + postStart = let + host = if (cfg.socketDir == null) then "" else "--host=${toString cfg.socketDir}"; + in '' + PSQL="psql --port=${toString cfg.port} ${host}" while ! $PSQL -d postgres -c "" 2> /dev/null; do if ! kill -0 "$MAINPID"; then exit 1; fi