>From a1305d1280642bcff46fc736717f119bd4999e74 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Fri, 4 Nov 2016 17:36:21 +0100 Subject: [PATCH 3/3] services: Accept gexps as nginx configuration value. * gnu/services/web.scm (default-nginx-config): Use computed-file instead of plain-file. --- doc/guix.texi | 8 +++++ gnu/services/web.scm | 96 +++++++++++++++++++++++++++------------------------- 2 files changed, 58 insertions(+), 46 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 5c42140..2b07bc4 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -10428,6 +10428,14 @@ This service can be extended to add more vhosts than the default one. (root "/var/www/extra-website")))) @end example +or if you want to make a package available, you can write something like: + address@hidden +(simple-service 'gtk-doc-vhost nginx-service-type + (list (nginx-vhost-configuration + (root (file-append gtk+2 "/share/gtk-doc/html/gdk2/"))))) address@hidden example + @end deffn @deftp {Data Type} nginx-vhost-configuration diff --git a/gnu/services/web.scm b/gnu/services/web.scm index e36d284..df6e680 100644 --- a/gnu/services/web.scm +++ b/gnu/services/web.scm @@ -90,54 +90,58 @@ of index files." names))) (define (default-nginx-vhost-config vhost) - (string-append - " server {\n" - (if (nginx-vhost-configuration-http-port vhost) - (string-append " listen " - (number->string (nginx-vhost-configuration-http-port vhost)) - ";\n") - "") - (if (nginx-vhost-configuration-https-port vhost) - (string-append " listen " - (number->string (nginx-vhost-configuration-https-port vhost)) - " ssl;\n") - "") - " server_name " (config-domain-strings - (nginx-vhost-configuration-server-name vhost)) - ";\n" - (if (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) - (string-append " ssl_certificate_key " - (nginx-vhost-configuration-ssl-certificate-key vhost) ";\n") - "") - " root " (nginx-vhost-configuration-root vhost) ";\n" - " index " (config-index-strings (nginx-vhost-configuration-index vhost)) ";\n" - " server_tokens " (if (nginx-vhost-configuration-server-tokens? vhost) - "on" "off") ";\n" - " }\n")) + #~(string-append + " server {\n" + #$(if (nginx-vhost-configuration-http-port vhost) + (string-append " listen " + (number->string (nginx-vhost-configuration-http-port vhost)) + ";\n") + "") + #$(if (nginx-vhost-configuration-https-port vhost) + (string-append " listen " + (number->string (nginx-vhost-configuration-https-port vhost)) + " ssl;\n") + "") + " server_name " #$(config-domain-strings + (nginx-vhost-configuration-server-name vhost)) + ";\n" + #$(if (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) + (string-append " ssl_certificate_key " + (nginx-vhost-configuration-ssl-certificate-key vhost) ";\n") + "") + " root " #$(nginx-vhost-configuration-root vhost) ";\n" + " index " #$(config-index-strings (nginx-vhost-configuration-index vhost)) ";\n" + " server_tokens " #$(if (nginx-vhost-configuration-server-tokens? vhost) + "on" "off") ";\n" + " }\n")) (define (default-nginx-config log-directory run-directory vhost-list) - (plain-file "nginx.conf" - (string-append - "user nginx nginx;\n" - "pid " run-directory "/pid;\n" - "error_log " log-directory "/error.log info;\n" - "http {\n" - " client_body_temp_path " run-directory "/client_body_temp;\n" - " proxy_temp_path " run-directory "/proxy_temp;\n" - " fastcgi_temp_path " run-directory "/fastcgi_temp;\n" - " uwsgi_temp_path " run-directory "/uwsgi_temp;\n" - " scgi_temp_path " run-directory "/scgi_temp;\n" - " access_log " log-directory "/access.log;\n" - (let ((http (map default-nginx-vhost-config vhost-list))) - (do ((http http (cdr http)) - (block "" (string-append (car http) "\n" block ))) - ((null? http) block))) - "}\n" - "events {}\n"))) + (computed-file + "nginx.conf" + #~(call-with-output-file #$output + (lambda (port) + (format port + (string-append + "user nginx nginx;\n" + "pid " #$run-directory "/pid;\n" + "error_log " #$log-directory "/error.log info;\n" + "http {\n" + " client_body_temp_path " #$run-directory "/client_body_temp;\n" + " proxy_temp_path " #$run-directory "/proxy_temp;\n" + " fastcgi_temp_path " #$run-directory "/fastcgi_temp;\n" + " uwsgi_temp_path " #$run-directory "/uwsgi_temp;\n" + " scgi_temp_path " #$run-directory "/scgi_temp;\n" + " access_log " #$log-directory "/access.log;\n" + #$(let ((http (map default-nginx-vhost-config vhost-list))) + (do ((http http (cdr http)) + (block "" #~(string-append #$(car http) "\n" #$block ))) + ((null? http) block))) + "}\n" + "events {}\n")))))) (define %nginx-accounts (list (user-group (name "nginx") (system? #t)) -- 2.10.2