services: Rework the PostgreSQL config file to use a record type.

For the default config file representation. This makes it possible to more
easily change the configuration file, and have dynamic content.

* 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.
This commit is contained in:
Christopher Baines 2018-03-04 15:05:02 +00:00
parent 0fa4702c04
commit 936e7a5245
No known key found for this signature in database
GPG Key ID: 5E28A33B0B84F577
1 changed files with 65 additions and 20 deletions

View File

@ -29,8 +29,16 @@
#: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,20 +76,6 @@
;;;
;;; Code:
(define-record-type* <postgresql-configuration>
postgresql-configuration make-postgresql-configuration
postgresql-configuration?
(postgresql postgresql-configuration-postgresql ;<package>
(default postgresql))
(port postgresql-configuration-port
(default 5432))
(locale postgresql-configuration-locale
(default "en_US.utf8"))
(config-file postgresql-configuration-file
(default %default-postgres-config))
(data-directory postgresql-configuration-data-directory
(default "/var/lib/postgresql/data")))
(define %default-postgres-hba
(plain-file "pg_hba.conf"
"
@ -93,11 +87,62 @@ host all all ::1/128 trust"))
(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-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 "'")
'()))
(define contents
(append-map
(match-lambda
((key) '())
((key . #f) '())
((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?
(postgresql postgresql-configuration-postgresql ;<package>
(default postgresql))
(port postgresql-configuration-port
(default 5432))
(locale postgresql-configuration-locale
(default "en_US.utf8"))
(config-file postgresql-configuration-file
(default (postgresql-config-file)))
(data-directory postgresql-configuration-data-directory
(default "/var/lib/postgresql/data")))
(define %postgresql-accounts
(list (user-group (name "postgres") (system? #t))
@ -192,7 +237,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.