From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julien Lepiller Subject: Re: [PATCH] improve nginx-service Date: Thu, 27 Oct 2016 19:59:49 +0200 Message-ID: <20161027195949.354cae8e@lepiller.eu> References: <20161016143347.38d8a6f2@polymos.lepiller.eu> <874m483vap.fsf@gnu.org> <20161020143744.516a1184@polymos.lepiller.eu> <87shrlzd0w.fsf@gnu.org> <20161026214507.45445d14@lepiller.eu> <87y41aklqp.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/vbOtplMSSr/fHPvOQR9KsA6" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36988) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzoyJ-0000D4-1m for guix-devel@gnu.org; Thu, 27 Oct 2016 14:00:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bzoyC-0007mE-SY for guix-devel@gnu.org; Thu, 27 Oct 2016 14:00:11 -0400 Received: from dau94-h03-89-91-205-84.dsl.sta.abo.bbox.fr ([89.91.205.84]:48443 helo=skaro.lepiller.eu) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bzoyC-0007iY-8r for guix-devel@gnu.org; Thu, 27 Oct 2016 14:00:04 -0400 Received: from localhost (localhost [127.0.0.1]) by skaro.lepiller.eu (Postfix) with ESMTP id EA9D581D35 for ; Thu, 27 Oct 2016 19:58:17 +0200 (CEST) Received: from skaro.lepiller.eu ([127.0.0.1]) by localhost (lepiller.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ci7LxIHwOVym for ; Thu, 27 Oct 2016 19:58:11 +0200 (CEST) Received: from localhost (89-93-157-164.hfc.dyn.abo.bbox.fr [89.93.157.164]) by skaro.lepiller.eu (Postfix) with ESMTPSA id EAC0981D29 for ; Thu, 27 Oct 2016 19:58:10 +0200 (CEST) In-Reply-To: <87y41aklqp.fsf@gnu.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel@gnu.org --MP_/vbOtplMSSr/fHPvOQR9KsA6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Thu, 27 Oct 2016 14:41:18 +0200 ludo@gnu.org (Ludovic Court=C3=A8s) wrote: > [...] > > What I had in mind was just to add =E2=80=98compose=E2=80=99 and =E2=80= =98extend=E2=80=99 to > =E2=80=98nginx-service-type=E2=80=99 (this is where we define how extensi= ons are > handled). There=E2=80=99s a bit of extra bookeeping to do, in particular > moving the list of vhosts to , as in this > untested patch: >=20 What do you think of this patch? I only had to add one (or) so the same config file would be used during test and running (I hope it does not create another one?). Actually your patch didn't help me except for syntax simplification. Your answer was not really helpful, but it forced me to consider what I really wanted. So my use case would be that I would like to run a webservice from the store (all configuration should be made via guix). But my problem is that I don't know how to get the path to the store that I could pass as the root parameter in nginx-vhost-config. Also, I don't know what the best solution would be to get a configured web service in the store. Configuration is usually in a file in the root directory, and sometimes a default file is already present and you are supposed to modify it by hand. The issue here is that the store is read-only. How could you create a configuration file that can be found in the package's directory (using a guix service)? Would that mean that I have to copy the whole package and change just one file? Is there anything better, or do I have no other choice than install it outside of guix? --MP_/vbOtplMSSr/fHPvOQR9KsA6 Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-service-Make-nginx-service-extensible.patch >From 25a296057969a35b86ea7371577504c43bf96334 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Thu, 27 Oct 2016 19:47:27 +0200 Subject: [PATCH] service: Make nginx-service extensible gnu/services/web.scm (nginx-service-type): Make extensible --- doc/guix.texi | 15 ++++++++++++++- gnu/services/web.scm | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 1293b8b..b6e62b3 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -10399,7 +10399,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. @@ -10415,6 +10415,19 @@ this to work, use the default value for @var{config-file}. @end deffn +@deffn [Scheme Variable] nginx-service-type +This is the type for the @code{nginx} web server. + +This service can be extended to add more vhosts than the default one. + +@example +(simple-service 'my-extra-vhost nginx-service-type + (list (nginx-vhost-configuration (https-port #f) + (root "/var/www/extra-website")))) +@end example + +@end 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..0fb1a0b 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,7 @@ (nginx nginx-configuration-nginx) ; (log-directory nginx-configuration-log-directory) ;string (run-directory nginx-configuration-run-directory) ;string + (vhosts nginx-configuration-vhosts) ;list of (file nginx-configuration-file)) ;string | file-like (define (config-domain-strings names) @@ -102,11 +104,13 @@ of index files." " server_name " (config-domain-strings (nginx-vhost-configuration-server-name vhost)) ";\n" - (if (nginx-vhost-configuration-ssl-certificate vhost) + (if (and (nginx-vhost-configuration-https-port vhost) + (nginx-vhost-configuration-ssl-certificate vhost)) (string-append " ssl_certificate " (nginx-vhost-configuration-ssl-certificate vhost) ";\n") "") - (if (nginx-vhost-configuration-ssl-certificate-key vhost) + (if (and (nginx-vhost-configuration-https-port vhost) + (nginx-vhost-configuration-ssl-certificate-key vhost)) (string-append " ssl_certificate_key " (nginx-vhost-configuration-ssl-certificate-key vhost) ";\n") "") @@ -148,7 +152,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 +168,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 #$@args)))))) + (system* #$nginx-binary "-c" #$(or config-file + (default-nginx-config + log-directory + run-directory + vhosts)) + #$@args)))))) ;; TODO: Add 'reload' action. (list (shepherd-service @@ -192,14 +204,20 @@ 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 (list (nginx-vhost-configuration + (https-port #f)))) + (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 +227,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.1 --MP_/vbOtplMSSr/fHPvOQR9KsA6--