all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Christopher Baines <mail@cbaines.net>
To: 30701@debbugs.gnu.org
Subject: [bug#30701] [PATCH 1/4] services: Rework the PostgreSQL config file to use a record type.
Date: Sun,  4 Mar 2018 19:16:30 +0000	[thread overview]
Message-ID: <20180304191633.20262-1-mail@cbaines.net> (raw)
In-Reply-To: <87po4jpsgc.fsf@cbaines.net>

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 (<postgresql-config-file>): New record type.
  (%default-postgres-config): Remove this, it's been replaced by the
  configuration file.
  (<postgresql-configuration>): 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?
+            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>
+  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 <postgresql-config-file>) system target)
+  (match file
+    (($ <postgresql-config-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>
   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

  reply	other threads:[~2018-03-04 19:17 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-04 19:10 [bug#30701] [PATCH 0/4] PostgreSQL service changes (add record type, and system test) Christopher Baines
2018-03-04 19:16 ` Christopher Baines [this message]
2018-03-04 19:16   ` [bug#30701] [PATCH 2/4] services: Use a external pid file for PostgreSQL Christopher Baines
2018-03-05  0:32     ` Clément Lassieur
2018-03-05  8:21       ` Christopher Baines
2018-03-05  8:27         ` Christopher Baines
2018-03-05 12:15         ` Clément Lassieur
2018-03-04 19:16   ` [bug#30701] [PATCH 3/4] tests: databases: Add a system test " Christopher Baines
2018-03-05  0:32     ` Clément Lassieur
2018-03-05  8:34       ` Christopher Baines
2018-03-04 19:16   ` [bug#30701] [PATCH 4/4] services: databases: Add postgresql-configuration record exports Christopher Baines
2018-03-05 12:16     ` Clément Lassieur
2018-03-05 19:37       ` Christopher Baines
2018-03-05  0:32   ` [bug#30701] [PATCH 1/4] services: Rework the PostgreSQL config file to use a record type Clément Lassieur
2018-03-05  7:52     ` Christopher Baines
2018-03-05  8:52       ` Clément Lassieur
2018-03-05  9:35       ` Clément Lassieur
2018-03-05  8:39 ` [bug#30701] [PATCH 1/3] " Christopher Baines
2018-03-05  8:39   ` [bug#30701] [PATCH 2/3] tests: databases: Add a system test for PostgreSQL Christopher Baines
2018-03-05 11:54     ` Clément Lassieur
2018-03-05 19:25       ` Christopher Baines
2018-03-05  8:39   ` [bug#30701] [PATCH 3/3] services: databases: Add postgresql-configuration record exports Christopher Baines
2018-03-05 19:37 ` [bug#30701] [PATCH 1/3] services: Rework the PostgreSQL config file to use a record type Christopher Baines
2018-03-05 19:37   ` [bug#30701] [PATCH 2/3] tests: databases: Add a system test for PostgreSQL Christopher Baines
2018-03-05 19:37   ` [bug#30701] [PATCH 3/3] services: databases: Add postgresql-configuration record exports Christopher Baines
2018-03-05 21:33   ` [bug#30701] [PATCH 1/3] services: Rework the PostgreSQL config file to use a record type Clément Lassieur
2018-03-13 17:37     ` bug#30701: " Christopher Baines
2018-03-14 17:37       ` [bug#30701] " Clément Lassieur
2018-03-17 20:35         ` Christopher Baines
2018-03-18  0:34           ` Clément Lassieur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180304191633.20262-1-mail@cbaines.net \
    --to=mail@cbaines.net \
    --cc=30701@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.