roptat pushed a commit to branch master
in repository guix.

commit 08da664d1041133e8282a5df0fcab6eee7e548fa
Author: Julien Lepiller <jul...@lepiller.eu>
Date:   Fri Jan 12 23:14:14 2018 +0100

    gnu: Add cat-avatar-generator-service.
    
    * gnu/services/web.scm (cat-avatar-generator-service): New variable.
    * doc/guix.text (Web Services): Document it.
---
 doc/guix.texi        | 25 +++++++++++++++++++++++++
 gnu/services/web.scm | 27 +++++++++++++++++++++++++--
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 08f531b..9dafe60 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -15641,6 +15641,31 @@ A simple services setup for nginx with php can look 
like this:
                  %base-services))
 @end example
 
+@cindex cat-avatar-generator
+The cat avatar generator is a simple service to demonstrate the use of php-fpm
+in @code{Nginx}.  It is used to generate cat avatar from a seed, for instance
+the hash of a user's email address.
+
+@deffn {Scheme Procedure} cat-avatar-generator-serice @
+       [#:cache-dir "/var/cache/cat-avatar-generator"] @
+       [#:package cat-avatar-generator] @
+       [#:configuration (nginx-server-configuration)]
+Returns an nginx-server-configuration that inherits @code{configuration}.  It
+extends the nginx configuration to add a server block that serves 
@code{package},
+a version of cat-avatar-generator.  During execution, cat-avatar-generator will
+be able to use @code{cache-dir} as its cache directory.
+@end deffn
+
+A simple setup for cat-avatar-generator can look like this:
+@example
+(services (cons* (cat-avatar-generator-service
+                  #:configuration
+                  (nginx-server-configuration
+                    (server-name '("example.com"))))
+                 ...
+                 %base-services))
+@end example
+
 @node Certificate Services
 @subsubsection Certificate Services
 
diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index c1ffe3e..beda481 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -2,7 +2,7 @@
 ;;; Copyright © 2015 David Thompson <da...@gnu.org>
 ;;; Copyright © 2015, 2016, 2017 Ludovic Courtès <l...@gnu.org>
 ;;; Copyright © 2016 ng0 <n...@we.make.ritual.n0.is>
-;;; Copyright © 2016, 2017 Julien Lepiller <jul...@lepiller.eu>
+;;; Copyright © 2016, 2017, 2018 Julien Lepiller <jul...@lepiller.eu>
 ;;; Copyright © 2017 Christopher Baines <m...@cbaines.net>
 ;;; Copyright © 2017 nee <nee-...@hidamari.blue>
 ;;; Copyright © 2017 Clément Lassieur <clem...@lassieur.org>
@@ -153,7 +153,9 @@
             
php-fpm-on-demand-process-manager-configuration-process-idle-timeout
 
             php-fpm-service-type
-            nginx-php-location))
+            nginx-php-location
+
+            cat-avatar-generator-service))
 
 ;;; Commentary:
 ;;;
@@ -870,3 +872,24 @@ a webserver.")
           (string-append "fastcgi_pass unix:" socket ";")
           "fastcgi_index index.php;"
           (list "include " nginx-package "/share/nginx/conf/fastcgi.conf;")))))
+
+(define* (cat-avatar-generator-service
+          #:key
+          (cache-dir "/var/cache/cat-avatar-generator")
+          (package cat-avatar-generator)
+          (configuration (nginx-server-configuration)))
+  (simple-service
+    'cat-http-server nginx-service-type
+    (list (nginx-server-configuration
+            (inherit configuration)
+            (locations
+              (cons
+                (let ((base (nginx-php-location)))
+                  (nginx-location-configuration
+                    (inherit base)
+                    (body (list (string-append "fastcgi_param CACHE_DIR \""
+                                               cache-dir "\";")
+                                (nginx-location-configuration-body base)))))
+                (nginx-server-configuration-locations configuration)))
+            (root #~(string-append #$package
+                                   "/share/web/cat-avatar-generator"))))))

Reply via email to