services: web: Switch nginx related functions to use match-record.

As this is less prone to mistakes than match.

* gnu/services/web.scm (default-nginx-config, nginx-activation,
  nginx-shepherd-service): Switch from using match-lambda to match-record.
master
Christopher Baines 2017-12-03 19:36:40 +00:00
parent 2881f85220
commit 472368a8ac
No known key found for this signature in database
GPG Key ID: 5E28A33B0B84F577
1 changed files with 81 additions and 85 deletions

View File

@ -231,8 +231,12 @@ of index files."
(cons head out)))
(fold-right flatten1 '() lst))
(define (default-nginx-config nginx log-directory run-directory server-list
upstream-list server-names-hash-bucket-size
(define (default-nginx-config config)
(match-record config
<nginx-configuration>
(nginx log-directory run-directory
server-blocks upstream-blocks
server-names-hash-bucket-size
server-names-hash-bucket-max-size)
(apply mixed-text-file "nginx.conf"
(flatten
@ -260,10 +264,10 @@ of index files."
";\n")
"")
"\n"
(map emit-nginx-upstream-config upstream-list)
(map emit-nginx-server-config server-list)
(map emit-nginx-upstream-config upstream-blocks)
(map emit-nginx-server-config server-blocks)
"}\n"
"events {}\n")))
"events {}\n"))))
(define %nginx-accounts
(list (user-group (name "nginx") (system? #t))
@ -275,11 +279,10 @@ of index files."
(home-directory "/var/empty")
(shell (file-append shadow "/sbin/nologin")))))
(define nginx-activation
(match-lambda
(($ <nginx-configuration> nginx log-directory run-directory server-blocks
upstream-blocks server-names-hash-bucket-size
server-names-hash-bucket-max-size file)
(define (nginx-activation config)
(match-record config
<nginx-configuration>
(nginx log-directory run-directory file)
#~(begin
(use-modules (guix build utils))
@ -299,17 +302,13 @@ of index files."
;; Check configuration file syntax.
(system* (string-append #$nginx "/sbin/nginx")
"-c" #$(or file
(default-nginx-config nginx log-directory
run-directory server-blocks upstream-blocks
server-names-hash-bucket-size
server-names-hash-bucket-max-size))
"-t")))))
(default-nginx-config config))
"-t"))))
(define nginx-shepherd-service
(match-lambda
(($ <nginx-configuration> nginx log-directory run-directory server-blocks
upstream-blocks server-names-hash-bucket-size
server-names-hash-bucket-max-size file)
(define (nginx-shepherd-service config)
(match-record config
<nginx-configuration>
(nginx file run-directory)
(let* ((nginx-binary (file-append nginx "/sbin/nginx"))
(nginx-action
(lambda args
@ -317,10 +316,7 @@ of index files."
(zero?
(system* #$nginx-binary "-c"
#$(or file
(default-nginx-config nginx log-directory
run-directory server-blocks upstream-blocks
server-names-hash-bucket-size
server-names-hash-bucket-max-size))
(default-nginx-config config))
#$@args))))))
;; TODO: Add 'reload' action.
@ -329,7 +325,7 @@ of index files."
(documentation "Run the nginx daemon.")
(requirement '(user-processes loopback))
(start (nginx-action "-p" run-directory))
(stop (nginx-action "-s" "stop"))))))))
(stop (nginx-action "-s" "stop")))))))
(define nginx-service-type
(service-type (name 'nginx)