all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Julien Lepiller <julien@lepiller.eu>
To: guix-devel@gnu.org
Subject: Re: [PATCH] improve nginx-service
Date: Thu, 27 Oct 2016 19:59:49 +0200	[thread overview]
Message-ID: <20161027195949.354cae8e@lepiller.eu> (raw)
In-Reply-To: <87y41aklqp.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1564 bytes --]

On Thu, 27 Oct 2016 14:41:18 +0200
ludo@gnu.org (Ludovic Courtès) wrote:

> [...]
>
> What I had in mind was just to add ‘compose’ and ‘extend’ to
> ‘nginx-service-type’ (this is where we define how extensions are
> handled).  There’s a bit of extra bookeeping to do, in particular
> moving the list of vhosts to <nginx-configuration>, as in this
> untested patch:
> 

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?

[-- Attachment #2: 0001-service-Make-nginx-service-extensible.patch --]
[-- Type: text/x-patch, Size: 6588 bytes --]

From 25a296057969a35b86ea7371577504c43bf96334 Mon Sep 17 00:00:00 2001
From: Julien Lepiller <julien@lepiller.eu>
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)         ;<package>
   (log-directory nginx-configuration-log-directory) ;string
   (run-directory nginx-configuration-run-directory) ;string
+  (vhosts        nginx-configuration-vhosts)        ;list of <nginx-vhost-configuration>
   (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-configuration> nginx log-directory run-directory config-file)
+    (($ <nginx-configuration> 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-configuration> nginx log-directory run-directory config-file)
+    (($ <nginx-configuration> 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


  reply	other threads:[~2016-10-27 18:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-16 12:33 [PATCH] improve nginx-service Julien Lepiller
2016-10-19 21:04 ` Ludovic Courtès
2016-10-20 12:37   ` Julien Lepiller
2016-10-24 20:51     ` Ludovic Courtès
2016-10-26 19:45       ` Julien Lepiller
2016-10-27 12:41         ` Ludovic Courtès
2016-10-27 17:59           ` Julien Lepiller [this message]
2016-10-30 21:46             ` Ludovic Courtès
2016-11-02  8:22               ` Hartmut Goebel
2016-11-03 14:54                 ` Ludovic Courtès
2016-11-03 22:38                   ` Hartmut Goebel
2016-11-04 13:21                     ` Ludovic Courtès
2016-11-04 18:01                       ` Julien Lepiller
2016-11-04 21:28                         ` Hartmut Goebel
2016-11-04 22:12                           ` Julien Lepiller
2016-11-04 22:34                             ` Hartmut Goebel
2016-11-06 11:11                               ` Julien Lepiller
2016-11-04 22:58                             ` Hartmut Goebel
2016-11-06 12:18                               ` Tobias Geerinckx-Rice
2016-11-06 17:19                                 ` Ludovic Courtès
2016-11-20 12:49                                   ` Julien Lepiller
2016-11-22 22:20                                     ` Hartmut Goebel
2016-11-23  9:26                                       ` julien lepiller
2016-11-25 10:53                                         ` Clément Lassieur
2016-11-25 11:46                                           ` is using eval good style in guile?(was: [PATCH] improve nginx-service) Hartmut Goebel
2016-11-25 13:29                                             ` is using eval good style in guile? Andy Wingo
2016-11-26 21:55                                               ` Clément Lassieur
2016-11-27 21:01                                         ` [PATCH] improve nginx-service Ludovic Courtès
2016-11-06 17:33                               ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161027195949.354cae8e@lepiller.eu \
    --to=julien@lepiller.eu \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.