From patchwork Sun Nov 6 11:11:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Lepiller X-Patchwork-Id: 17231 Received: (qmail 547 invoked by uid 89); 6 Nov 2016 11:12:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=cups, serves X-Spam-Status: No, score=-4.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: lists.gnu.org Received: from lists.gnu.org (HELO lists.gnu.org) (208.118.235.17) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 06 Nov 2016 11:12:13 +0000 Received: from localhost ([::1]:41713 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3LMx-0008Pt-AZ for patchwork@sourceware.org; Sun, 06 Nov 2016 06:12:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3LMp-0008Pm-T2 for guix-devel@gnu.org; Sun, 06 Nov 2016 06:12:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c3LMm-0005W3-K6 for guix-devel@gnu.org; Sun, 06 Nov 2016 06:12:03 -0500 Received: from dau94-h03-89-91-205-84.dsl.sta.abo.bbox.fr ([89.91.205.84]:55265 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 1c3LMl-0005T7-Ux for guix-devel@gnu.org; Sun, 06 Nov 2016 06:12:00 -0500 Received: from localhost (localhost [127.0.0.1]) by skaro.lepiller.eu (Postfix) with ESMTP id 3363981DF5 for ; Sun, 6 Nov 2016 12:11:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=lepiller.eu; s=default; t=1478430716; bh=FAKKNVQjIMR20IZxQ7HIdJ5YRiXuwO+YGcbmq1e/WsE=; h=Date:From:To:Subject:In-Reply-To:References:From; b=hQvnRd/aG8bJr9CN0KEAZ9pYzv9zMyR7aviCgOHNRr4v7clu4bqX3O3w4b0tenv1F nkHNHX+G5sAIb+HBsN2aJlTbU3EFAZQqMDCiki0cG5jqkkrog80V8T0SzzaWxbbisN M9q6dJLhNVRChE7dKMrp215EhuPWaJb72AwU57+XLQWNQaJMh7ByTH36kjrZa2uMqc OZIhzFG/DmxExF2EXe492Bdyv73qniqXf8H9RuPr5h9N9De9hgK/bptXitR8UnYDWQ DYR+CX+HNzeqpDmtNGFJoxh3QQbVFMSlxOF+L9att5rEhsEkqIqj5ASuw/C8eVdcx2 GCnO+mcq3uuD2LfIuJC3jgyf777P8WeX0wQUlQL1UslEn9+/zKbwBSosTXw6ErbKG2 1BjG29dwy/Xws2sIqX+QHEq+bC6j8k8RRL2p6RDr8j9ei67U98eP1uSCsPke/+pCif 9mQ1/uhDWLJjoVUuaM7AQMcu/kkWyRa3n+nrp/vr7miJjIUVp0evr23LiRy7hq9SBE fcCSijcQPETajOVZiTTvvbMkLK8hCcuypezxKWL7XCfKWx36g+ReIWyEjuLelsmm33 hqMXKjlm3PqDNwsvwfRAHhSpQNynWlrPY2L5sG1/zQveuWraYDoc/oiLw0JcNZuWrf f9OIB75QwoQlzDXVGIu5wlJs= X-Virus-Scanned: Debian amavisd-new at lepiller.eu Received: from skaro.lepiller.eu ([127.0.0.1]) by localhost (lepiller.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VyiSWT4Tg965 for ; Sun, 6 Nov 2016 12:11:48 +0100 (CET) Received: from localhost (89-93-157-164.hfc.dyn.abo.bbox.fr [89.93.157.164]) by skaro.lepiller.eu (Postfix) with ESMTPSA id B4DB57FB94 for ; Sun, 6 Nov 2016 12:11:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=lepiller.eu; s=default; t=1478430707; bh=FAKKNVQjIMR20IZxQ7HIdJ5YRiXuwO+YGcbmq1e/WsE=; h=Date:From:To:Subject:In-Reply-To:References:From; b=LCH6mqGKDi9m69NO015U8IN8I1s5qA6vJh80Sa+EtDda3QA5SG7NjxY8YnDebnquS rqkqpm/I4hnIPeSE8SYAqmFCaJsaTToUotsxxrJbT38orfPCLlTf0xeMp/GqPcz0Ki PT0INtltuj15OgIddD9OSidrJRVYvHSfpfu/i+JazwThT9ao8dDnX8kOq6lXmD1F/A /ilPA6YAWX5qreFRZ6ofD2jCj8lomPjcxtbzEUhNZS7HM+eelJe5+Znw61mIFr2iN2 zr0uOQC7Hc4coeIlKE50iZTzVh25IRQJcZ5SCeghajoP/JQcxcehzjBq8EUblF8lec Qb+fg27vrCJDioKZZWfSFbRXfDTHLSjwIVLmu9aZSMLfZ8axmUBdxA1mPUjSLvMZUH DN0hv+Ks3+/iP4rxXLlNjVlAIA3zBkabVAbwRLzDJlVuiMDkJKEO22HiFD7HUWDr40 Igdk9akiVxrLP/2a6lN38zH3MxFGoHWoZ4rK5Gj9h7US6V0ULyKO7M3m17OqiG4+2A eNgRvPfNifCjuZ1ls133VDWyxaOxEDTR0yV3+VIDnQgcn2ag6kNWA2n++OvnGMZlMc xY3vkZNBa4IOhloQQkY3VdUzHkU2j782EczE4vECQwoGc5K+rrXrZI9wP1R5zt7JAo Au5EBL278nywnUFwnvyvNYg0= Date: Sun, 6 Nov 2016 12:11:42 +0100 From: Julien Lepiller To: guix-devel@gnu.org Subject: Re: [PATCH] improve nginx-service Message-ID: <20161106121142.19cdb128@lepiller.eu> In-Reply-To: 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> <20161027195949.354cae8e@lepiller.eu> <87pomhse6w.fsf@gnu.org> <87lgx0txz0.fsf@gnu.org> <87h97n1iu0.fsf@gnu.org> <20161104190129.684844b4@lepiller.eu> <20161104231253.4b52d70f@lepiller.eu> X-Mailer: Claws Mail 3.14.0 (GTK+ 2.24.31; x86_64-unknown-linux-gnu) MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 89.91.205.84 X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list 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+patchwork=sourceware.org@gnu.org Sender: "Guix-devel" On Fri, 4 Nov 2016 23:34:31 +0100 Hartmut Goebel wrote: > Am 04.11.2016 um 23:12 schrieb Julien Lepiller: > >> > gnu/services/web.scm:118:34: In procedure > >> > default-nginx-vhost-config: gnu/services/web.scm:118:34: In > >> > procedure struct_vtable: Wrong type argument in position 1 > >> > (expecting struct): (nginx-vhost-configuration (root > >> > taler-landing-page)) > > What is your configuration exactly, and what is taler-landing-page? > > > > The configuration is like in your gtk-doc-vhost, except that I'm not > using gtk+2 and omitting the "string-append" for the path. > I attached new patches that add more documentation (I hope it helps). Using this configuration works for me: (nginx-service) (service (service-type (name 'foo) (extensions (list (service-extension nginx-service-type (const (list ;; a vhost that actually serves html files (nginx-vhost-configuration (https-port #f) (ssl-certificate #f) (ssl-certificate-key #f) (root #~(string-append #$cups "/share/doc/cups/ja"))) ;; just to show how to use a package ;; directly (nginx-vhost-configuration (server-name (list "help")) (https-port #f) (ssl-certificate #f) (ssl-certificate-key #f) (root cups)))))))) #t) It would work with simple-service too. It generates this configuration file for nginx: user nginx nginx; pid /var/run/nginx/pid; error_log /var/log/nginx/error.log info; http { client_body_temp_path /var/run/nginx/client_body_temp; proxy_temp_path /var/run/nginx/proxy_temp; fastcgi_temp_path /var/run/nginx/fastcgi_temp; uwsgi_temp_path /var/run/nginx/uwsgi_temp; scgi_temp_path /var/run/nginx/scgi_temp; access_log /var/log/nginx/access.log; server { listen 80; server_name help ; root /gnu/store/l6n860s5fmaxhwcx17mjrfw4wcqx8xy8-cups-2.1.0; index index.html ; server_tokens off; } server { listen 80; server_name _ ; root /gnu/store/l6n860s5fmaxhwcx17mjrfw4wcqx8xy8-cups-2.1.0/share/doc/cups/ja; index index.html ; server_tokens off; } } events {} From c7f6944a7483edf2719ecf47a2adf2d4b346700a Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Sun, 6 Nov 2016 11:28:01 +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 | 9 +++++ gnu/services/web.scm | 96 +++++++++++++++++++++++++++------------------------- 2 files changed, 59 insertions(+), 46 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 4b60a4a..d125546 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -10433,6 +10433,15 @@ of them. For example: (list vh)) @end example +or if you want to make a package available, you can write something like: + +@example +(define vh (nginx-vhost-configuration + (root my-package))) +(define vh2 (nginx-vhost-configuration + (root #~(string-append #$cups "/share/doc/cups/ja")))) +@end example + Is a service that adds a new @dfn{virtual host} to the list of existing ones. You can add as many such services as you want. 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