>From 55ccf3041bff562345816b500ee5a2aeda9e3226 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Thu, 3 Nov 2016 18:11:01 +0100 Subject: [PATCH 1/3] Make nginx-service extensible * gnu/services/web.scm (nginx-service-type): Make extensible. --- doc/guix.texi | 15 ++++++++++++++- gnu/services/web.scm | 33 +++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 1075a7e..5c42140 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -10401,7 +10401,7 @@ The @code{(gnu services web)} module provides the following service: [#:log-directory ``/var/log/nginx''] @ [#:run-directory ``/var/run/nginx''] @ [#:vhost-list (list (nginx-vhost-configuration))] @ - [#:config-file] + [#:config-file @code{#f}] Return a service that runs @var{nginx}, the nginx web server. @@ -10417,6 +10417,19 @@ this to work, use the default value for @var{config-file}. @end deffn address@hidden {Scheme Variable} nginx-service-type +This is the type for the nginx web server. + +This service can be extended to add more vhosts than the default one. + address@hidden +(simple-service 'my-extra-vhost nginx-service-type + (list (nginx-vhost-configuration (https-port #f) + (root "/var/www/extra-website")))) address@hidden example + address@hidden deffn + @deftp {Data Type} nginx-vhost-configuration Data type representing the configuration of an nginx virtual host. This type has the following parameters: diff --git a/gnu/services/web.scm b/gnu/services/web.scm index 59e1e54..50f83f3 100644 --- a/gnu/services/web.scm +++ b/gnu/services/web.scm @@ -28,6 +28,7 @@ #:use-module (guix records) #:use-module (guix gexp) #:use-module (ice-9 match) + #:use-module (srfi srfi-1) #:export (nginx-configuration nginx-configuration? nginx-vhost-configuration @@ -67,6 +68,8 @@ (nginx nginx-configuration-nginx) ; (log-directory nginx-configuration-log-directory) ;string (run-directory nginx-configuration-run-directory) ;string + (vhosts nginx-configuration-vhosts + (default '())) ;list of (file nginx-configuration-file)) ;string | file-like (define (config-domain-strings names) @@ -148,7 +151,7 @@ of index files." (define nginx-activation (match-lambda - (($ nginx log-directory run-directory config-file) + (($ nginx log-directory run-directory vhosts config-file) #~(begin (use-modules (guix build utils)) @@ -164,17 +167,25 @@ of index files." (mkdir-p (string-append #$run-directory "/scgi_temp")) ;; Check configuration file syntax. (system* (string-append #$nginx "/sbin/nginx") - "-c" #$config-file "-t"))))) + "-c" #$(or config-file + (default-nginx-config log-directory + run-directory vhosts)) + "-t"))))) (define nginx-shepherd-service (match-lambda - (($ nginx log-directory run-directory config-file) + (($ nginx log-directory run-directory vhosts config-file) (let* ((nginx-binary (file-append nginx "/sbin/nginx")) (nginx-action (lambda args #~(lambda _ (zero? - (system* #$nginx-binary "-c" #$config-file address@hidden)))))) + (system* #$nginx-binary "-c" #$(or config-file + (default-nginx-config + log-directory + run-directory + vhosts)) + address@hidden)))))) ;; TODO: Add 'reload' action. (list (shepherd-service @@ -192,14 +203,19 @@ of index files." (service-extension activation-service-type nginx-activation) (service-extension account-service-type - (const %nginx-accounts)))))) + (const %nginx-accounts)))) + (compose concatenate) + (extend (lambda (config vhosts) + (nginx-configuration + (inherit config) + (vhosts (append (nginx-configuration-vhosts config) + vhosts))))))) (define* (nginx-service #:key (nginx nginx) (log-directory "/var/log/nginx") (run-directory "/var/run/nginx") - (vhost-list (list (nginx-vhost-configuration))) - (config-file - (default-nginx-config log-directory run-directory vhost-list))) + (vhost-list '()) + (config-file #f)) "Return a service that runs NGINX, the nginx web server. The nginx daemon loads its runtime configuration from CONFIG-FILE, stores log @@ -209,4 +225,5 @@ files in LOG-DIRECTORY, and stores temporary runtime files in RUN-DIRECTORY." (nginx nginx) (log-directory log-directory) (run-directory run-directory) + (vhosts vhost-list) (file config-file)))) -- 2.10.2