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