From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esZ87-00066N-2v for guix-patches@gnu.org; Sun, 04 Mar 2018 14:17:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esZ83-0000ri-MA for guix-patches@gnu.org; Sun, 04 Mar 2018 14:17:07 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:36804) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1esZ83-0000rc-Hu for guix-patches@gnu.org; Sun, 04 Mar 2018 14:17:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1esZ83-0004QS-CL for guix-patches@gnu.org; Sun, 04 Mar 2018 14:17:03 -0500 Subject: [bug#30701] [PATCH 1/4] services: Rework the PostgreSQL config file to use a record type. References: <87po4jpsgc.fsf@cbaines.net> In-Reply-To: <87po4jpsgc.fsf@cbaines.net> Resent-Message-ID: From: Christopher Baines Date: Sun, 4 Mar 2018 19:16:30 +0000 Message-Id: <20180304191633.20262-1-mail@cbaines.net> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 30701@debbugs.gnu.org For the default config file representation. This makes it possible to more easily change the configuration file, and have dynamic content. In particular, I'm looking at adding a pid file location to the config file. * gnu/services/databases.scm (): New record type. (%default-postgres-config): Remove this, it's been replaced by the configuration file. (): Alter the default for the config file field. (postgresql-service): Alter the default value for the config-file parameter. --- gnu/services/databases.scm | 86 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 20 deletions(-) diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm index 3ca8f471f..9ffb6a5e9 100644 --- a/gnu/services/databases.scm +++ b/gnu/services/databases.scm @@ -26,11 +26,20 @@ #:use-module (gnu system shadow) #:use-module (gnu packages admin) #:use-module (gnu packages databases) + #:use-module (guix store) #:use-module (guix modules) #:use-module (guix records) #:use-module (guix gexp) + #:use-module (srfi srfi-1) #:use-module (ice-9 match) - #:export (postgresql-configuration + #:export ( + postgresql-config-file + postgresql-config-file? + postgresql-config-file-log-destination + postgresql-config-file-hba-file + postgresql-config-file-ident-file + postgresql-config-file-extra-config + postgresql-configuration? postgresql-service postgresql-service-type @@ -68,6 +77,60 @@ ;;; ;;; Code: +(define %default-postgres-hba + (plain-file "pg_hba.conf" + " +local all all trust +host all all 127.0.0.1/32 trust +host all all ::1/128 trust")) + +(define %default-postgres-ident + (plain-file "pg_ident.conf" + "# MAPNAME SYSTEM-USERNAME PG-USERNAME")) + +(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 '()))) + +(define-gexp-compiler (postgresql-config-file-compiler + (file ) system target) + (match file + (($ log-destination hba-file + ident-file extra-config) + (define (quote string) + (if string + (list "'" string "'") + (list))) + + (define contents + (append-map + (match-lambda + ((key) (list)) + ((key . #f) (list)) + ((key values ...) `(,key " = " ,@values "\n"))) + + `(("log_destination" ,@(quote log-destination)) + ("hba_file" ,@(quote hba-file)) + ("ident_file" ,@(quote ident-file)) + ,@extra-config))) + + (gexp->derivation + "postgresql.conf" + #~(call-with-output-file (ungexp output "out") + (lambda (port) + (display + (string-append #$@contents) + port))) + #:local-build? #t)))) + (define-record-type* postgresql-configuration make-postgresql-configuration postgresql-configuration? @@ -78,27 +141,10 @@ (locale postgresql-configuration-locale (default "en_US.utf8")) (config-file postgresql-configuration-file - (default %default-postgres-config)) + (default (postgresql-config-file))) (data-directory postgresql-configuration-data-directory (default "/var/lib/postgresql/data"))) -(define %default-postgres-hba - (plain-file "pg_hba.conf" - " -local all all trust -host all all 127.0.0.1/32 trust -host all all ::1/128 trust")) - -(define %default-postgres-ident - (plain-file "pg_ident.conf" - "# MAPNAME SYSTEM-USERNAME PG-USERNAME")) - -(define %default-postgres-config - (mixed-text-file "postgresql.conf" - "log_destination = 'syslog'\n" - "hba_file = '" %default-postgres-hba "'\n" - "ident_file = '" %default-postgres-ident "'\n")) - (define %postgresql-accounts (list (user-group (name "postgres") (system? #t)) (user-account @@ -192,7 +238,7 @@ host all all ::1/128 trust")) (define* (postgresql-service #:key (postgresql postgresql) (port 5432) (locale "en_US.utf8") - (config-file %default-postgres-config) + (config-file (postgresql-config-file)) (data-directory "/var/lib/postgresql/data")) "Return a service that runs @var{postgresql}, the PostgreSQL database server. -- 2.16.0