From b420e6deb96e0760f12e3d941b76e690c4235e47 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Sun, 15 Mar 2020 12:03:57 +0100 Subject: services/web: nginx-configuration: Add support for global directives. * gnu/services/web.scm ()[global-directives]: Add field. (emit-global-directive): New procedure. (default-nginx-config): Use it. * doc/guix.texi (Web Services): Document it. --- doc/guix.texi | 11 +++++++++++ gnu/services/web.scm | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/doc/guix.texi b/doc/guix.texi index 4658c6f5eb..28808b0cd5 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -20272,6 +20272,17 @@ names of loadable modules, as in this example: /etc/nginx/modules/ngx_http_accept_language_module.so"))) @end lisp +@item @code{global-directives} (default: @code{'()}) +Association list of global directives for the top level of the nginx +configuration. Values may themselves be association lists. + +@lisp +(global-directives + `((worker_processes . 16) + (pcre_jit . on) + (events . ((worker_connections . 1024))))) +@end lisp + @item @code{extra-content} (default: @code{""}) Extra content for the @code{http} block. Should be string or a string valued G-expression. diff --git a/gnu/services/web.scm b/gnu/services/web.scm index e2178faeb8..3edc751ea2 100644 --- a/gnu/services/web.scm +++ b/gnu/services/web.scm @@ -529,6 +529,7 @@ (server-names-hash-bucket-max-size nginx-configuration-server-names-hash-bucket-max-size (default #f)) (modules nginx-configuration-modules (default '())) + (global-directives nginx-configuration-global-directives (default '())) (extra-content nginx-configuration-extra-content (default "")) (file nginx-configuration-file ;#f | string | file-like @@ -552,6 +553,13 @@ of index files." (define (emit-load-module module) (list "load_module " module ";\n")) +(define emit-global-directive + (match-lambda + ((key . (? list? alist)) + (format #f "~a { ~{~a~}}~%" key (map emit-global-directive alist))) + ((key . value) + (format #f "~a ~a;~%" key value)))) + (define emit-nginx-location-config (match-lambda (($ uri body) @@ -626,12 +634,14 @@ of index files." server-names-hash-bucket-size server-names-hash-bucket-max-size modules + global-directives extra-content) (apply mixed-text-file "nginx.conf" (flatten "user nginx nginx;\n" "pid " run-directory "/pid;\n" "error_log " log-directory "/error.log info;\n" + (map emit-global-directive global-directives) (map emit-load-module modules) "http {\n" " client_body_temp_path " run-directory "/client_body_temp;\n" -- cgit v1.2.3