Subject: [PATCH] Add cat-avatar-generator-service.

From: Julien Lepiller <[email-masked]>
Date: Fri, 9 Feb 2018 21:44:09 +0100

Hi, attached is a simple and cute package :)

It's a simple service that uses the nginx service and the php
integration.

By the way, if you don't know the author of this package, he's awesome:
https://www.peppercarrot.com/
>From 5375bd9633cb37b3f26d16742fdc451f3296f723 Mon Sep 17 00:00:00 2001
From: Julien Lepiller <[email-masked]>
Date: Fri, 12 Jan 2018 23:08:50 +0100
Subject: [PATCH 1/2] gnu: Add cat-avatar-generator.

* gnu/packages/web.scm (cat-avatar-generator): New variable.
---
 gnu/packages/web.scm | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index fb076433f..d91904d65 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -6217,3 +6217,46 @@ features include:
 @item logging with multiple log levels.
 @end enumerate\n")
     (license l:expat)))
+
+(define-public cat-avatar-generator
+  (package
+    (name "cat-avatar-generator")
+    (version "1")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                     (url "https://framagit.org/Deevad/cat-avatar-generator.git")
+                     (commit "71c0c662742cafe8afd2d2d50ec84243113e35ad")))
+              (file-name (string-append name "-" version))
+              (sha256
+               (base32
+                "0s7b5whqsmfa57prbgl66ym551kg6ly0z14h5dgrlx4lqm70y2yw"))))
+    (build-system trivial-build-system)
+    (arguments
+     `(#:modules ((guix build utils)
+                  (srfi srfi-1)
+                  (srfi srfi-26))
+       #:builder
+       (begin
+         (use-modules (guix build utils)
+                      (srfi srfi-1)
+                      (srfi srfi-26))
+         (let ((source (assoc-ref %build-inputs "source"))
+               (php-dir (string-append %output "/share/web/" ,name "/")))
+           ;; The cache directory must not be in the store, but in a writable
+           ;; location.  The webserver will give us this location.
+           (copy-recursively source php-dir)
+           (substitute* (string-append php-dir "/cat-avatar-generator.php")
+             (("\\$cachepath = .*")
+              "if(isset($_SERVER['CACHE_DIR']))
+$cachepath = $_SERVER['CACHE_DIR'];
+else
+die('You need to set the CACHE_DIR variable first.');"))))))
+    (home-page "https://framagit.org/Deevad/cat-avatar-generator")
+    (synopsis "Random avatar generator")
+    (description "Cat avatar generator is a generator of cat pictures optimised
+to generate random avatars, or defined avatar from a \"seed\".  This is a
+derivation by David Revoy from the original MonsterID by Andreas Gohr.")
+    ;; expat for the code, CC-BY 4.0 for the artwork
+    (license (list l:expat
+                   l:cc-by4.0))))
-- 
2.16.1

>From b5e362ac44bf3bd284ba14e886960311b67a4019 Mon Sep 17 00:00:00 2001
From: Julien Lepiller <[email-masked]>
Date: Fri, 12 Jan 2018 23:14:14 +0100
Subject: [PATCH 2/2] gnu: Add cat-avatar-generator-service.

* gnu/services/web.scm (cat-avatar-generator-service): New variable.
---
 gnu/services/web.scm | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index c1ffe3e05..c4f46ebfc 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -870,3 +870,22 @@ 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")
+           (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)))
+                  (list (nginx-location-configuration
+                          (inherit base)
+                          (body (cons (string-append "fastcgi_param CACHE_DIR \""
+                                                     cache-dir "\";")
+                                      (nginx-location-configuration-body base))))))
+                (nginx-server-configuration-locations configuration)))
+            (root #~(string-append #$cat-avatar-generator
+                                   "/share/web/cat-avatar-generator"))))))
-- 
2.16.1