From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id KA2KNnNgBWDJPQAA0tVLHw (envelope-from ) for ; Mon, 18 Jan 2021 10:18:27 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id mM9HMnNgBWDdVwAAbx9fmQ (envelope-from ) for ; Mon, 18 Jan 2021 10:18:27 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6A0459403A4 for ; Mon, 18 Jan 2021 10:18:27 +0000 (UTC) Received: from localhost ([::1]:39518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1RcA-0005xx-7W for larch@yhetil.org; Mon, 18 Jan 2021 05:18:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33190) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1Rbn-0005wi-8p for guix-patches@gnu.org; Mon, 18 Jan 2021 05:18:06 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:34875) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1Rbm-0006kX-K6 for guix-patches@gnu.org; Mon, 18 Jan 2021 05:18:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l1Rbm-0005KC-GW for guix-patches@gnu.org; Mon, 18 Jan 2021 05:18:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45860] [PATCH v2 2/5] services: postgresql: Add socket directory support. Resent-From: Mathieu Othacehe Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 18 Jan 2021 10:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45860 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 45860@debbugs.gnu.org Received: via spool by 45860-submit@debbugs.gnu.org id=B45860.161096502820370 (code B ref 45860); Mon, 18 Jan 2021 10:18:02 +0000 Received: (at 45860) by debbugs.gnu.org; 18 Jan 2021 10:17:08 +0000 Received: from localhost ([127.0.0.1]:46412 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1Rat-0005IO-SG for submit@debbugs.gnu.org; Mon, 18 Jan 2021 05:17:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39570) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1Ral-0005H7-Q4 for 45860@debbugs.gnu.org; Mon, 18 Jan 2021 05:17:03 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:52245) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1Rag-0006Cc-L5; Mon, 18 Jan 2021 05:16:54 -0500 Received: from [2a01:e0a:19b:d9a0:1538:87ab:3a95:7600] (port=55432 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1l1Raf-0001QJ-OJ; Mon, 18 Jan 2021 05:16:54 -0500 From: Mathieu Othacehe Date: Mon, 18 Jan 2021 11:16:25 +0100 Message-Id: <20210118101628.202607-3-othacehe@gnu.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210118101628.202607-1-othacehe@gnu.org> References: <20210118101628.202607-1-othacehe@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mathieu Othacehe Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 3.64 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 6A0459403A4 X-Spam-Score: 3.64 X-Migadu-Scanner: scn0.migadu.com X-TUID: Tsb3UWNuIog2 * gnu/services/databases.scm (postgresql-config-file-socket-directory): New procedure. ()[socket-directory]: New field. (postgresql-config-file-compiler): Honor it. (postgresql-activation): Create the socket directory if needed. * doc/guix.texi (Database Services): Document it. --- doc/guix.texi | 6 ++++++ gnu/services/databases.scm | 32 +++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 3ec5e3be15..46039d26d0 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -19402,6 +19402,12 @@ configuration. @item @code{ident-file} (default: @code{%default-postgres-ident}) Filename or G-expression for the user name mapping configuration. +@item @code{socket-directory} (default: @code{"/var/lib/postgresql"}) +Specifies the directory of the Unix-domain socket(s) on which PostgreSQL +is to listen for connections from client applications. If set to +@code{#false} PostgreSQL does not listen on any Unix-domain sockets, in +which case only TCP/IP sockets can be used to connect to the server. + @item @code{extra-config} (default: @code{'()}) List of additional keys and values to include in the PostgreSQL config file. Each entry in the list should be a list where the first element diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm index bb0e40632e..83dee52cf3 100644 --- a/gnu/services/databases.scm +++ b/gnu/services/databases.scm @@ -43,6 +43,7 @@ postgresql-config-file-log-destination postgresql-config-file-hba-file postgresql-config-file-ident-file + postgresql-config-file-socket-directory postgresql-config-file-extra-config postgresql-configuration @@ -101,20 +102,23 @@ host all all ::1/128 md5")) (define-record-type* postgresql-config-file make-postgresql-config-file postgresql-config-file? - (log-destination postgresql-config-file-log-destination - (default "syslog")) - (hba-file postgresql-config-file-hba-file - (default %default-postgres-hba)) - (ident-file postgresql-config-file-ident-file - (default %default-postgres-ident)) - (extra-config postgresql-config-file-extra-config - (default '()))) + (log-destination postgresql-config-file-log-destination + (default "syslog")) + (hba-file postgresql-config-file-hba-file + (default %default-postgres-hba)) + (ident-file postgresql-config-file-ident-file + (default %default-postgres-ident)) + (socket-directory postgresql-config-file-socket-directory + (default "/var/run/postgresql")) + (extra-config postgresql-config-file-extra-config + (default '()))) (define-gexp-compiler (postgresql-config-file-compiler (file ) system target) (match file (($ log-destination hba-file - ident-file extra-config) + ident-file socket-directory + extra-config) ;; See: https://www.postgresql.org/docs/current/config-setting.html. (define (format-value value) (cond @@ -136,6 +140,9 @@ host all all ::1/128 md5")) `(("log_destination" ,log-destination) ("hba_file" ,hba-file) ("ident_file" ,ident-file) + ,@(if socket-directory + `(("unix_socket_directories" ,socket-directory)) + '()) ,@extra-config))) (gexp->derivation @@ -211,6 +218,13 @@ host all all ::1/128 md5")) (mkdir-p #$data-directory) (chown #$data-directory (passwd:uid user) (passwd:gid user)) + ;; Create the socket directory. + (let ((socket-directory + #$(postgresql-config-file-socket-directory config-file))) + (when (string? socket-directory) + (mkdir-p socket-directory) + (chown socket-directory (passwd:uid user) (passwd:gid user)))) + ;; Drop privileges and init state directory in a new ;; process. Wait for it to finish before proceeding. (match (primitive-fork) -- 2.29.2