guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#29466] [PATCH 2/2] WIP: Split the config file out of the <nginx-con


From: Christopher Baines
Subject: [bug#29466] [PATCH 2/2] WIP: Split the config file out of the <nginx-configuration> record.
Date: Sun, 10 Dec 2017 08:44:21 +0000

---
 gnu/services/web.scm | 152 +++++++++++++++++++++++++++++++--------------------
 gnu/tests/web.scm    |   5 +-
 2 files changed, 95 insertions(+), 62 deletions(-)

diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index 477e43e8d..f11ac6817 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -33,14 +33,21 @@
   #:export (<nginx-configuration>
             nginx-configuration
             nginx-configuration?
-            nginx-configuartion-nginx
+            nginx-configuration-nginx
             nginx-configuration-log-directory
             nginx-configuration-run-directory
-            nginx-configuration-server-blocks
-            nginx-configuration-upstream-blocks
-            nginx-configuration-server-names-hash-bucket-size
-            nginx-configuration-server-names-hash-bucket-max-size
-            nginx-configuration-file
+            nginx-configuration-config-file
+
+            <nginx-config-file>
+            nginx-config-file
+            nginx-config-file?
+            nginx-config-file-nginx
+            nginx-config-file-log-directory
+            nginx-config-file-run-directory
+            nginx-config-file-server-blocks
+            nginx-config-file-upstream-blocks
+            nginx-config-file-server-names-hash-bucket-size
+            nginx-config-file-server-names-hash-bucket-max-size
 
             <nginx-server-configuration>
             nginx-server-configuration
@@ -130,6 +137,24 @@
                        (default #f))
   (body                nginx-named-location-configuration-body))
 
+(define-record-type* <nginx-config-file>
+  nginx-config-file make-nginx-config-file
+  nginx-config-file?
+  (nginx         nginx-configuration-nginx          ;<package>
+                 (default nginx))
+  (log-directory nginx-config-file-log-directory  ;string
+                 (default "/var/log/nginx"))
+  (run-directory nginx-config-file-run-directory  ;string
+                 (default "/var/run/nginx"))
+  (server-blocks nginx-config-file-server-blocks
+                 (default '()))          ;list of <nginx-server-config-file>
+  (upstream-blocks nginx-config-file-upstream-blocks
+                   (default '()))      ;list of <nginx-upstream-config-file>
+  (server-names-hash-bucket-size 
nginx-config-file-server-names-hash-bucket-size
+                                 (default #f))
+  (server-names-hash-bucket-max-size 
nginx-config-file-server-names-hash-bucket-max-size
+                                     (default #f)))
+
 (define-record-type* <nginx-configuration>
   nginx-configuration make-nginx-configuration
   nginx-configuration?
@@ -139,16 +164,9 @@
                  (default "/var/log/nginx"))
   (run-directory nginx-configuration-run-directory  ;string
                  (default "/var/run/nginx"))
-  (server-blocks nginx-configuration-server-blocks
-                 (default '()))          ;list of <nginx-server-configuration>
-  (upstream-blocks nginx-configuration-upstream-blocks
-                   (default '()))      ;list of <nginx-upstream-configuration>
-  (server-names-hash-bucket-size 
nginx-configuration-server-names-hash-bucket-size
-                                 (default #f))
-  (server-names-hash-bucket-max-size 
nginx-configuration-server-names-hash-bucket-max-size
-                                     (default #f))
-  (file          nginx-configuration-file         ;#f | string | file-like
-                 (default #f)))
+  (config-file   nginx-configuration-config-file    ;string | file-like
+                 (default (nginx-config-file))))
+
 
 (define (config-domain-strings names)
  "Return a string denoting the nginx config representation of NAMES, a list
@@ -241,43 +259,49 @@ of index files."
         (cons head out)))
   (fold-right flatten1 '() lst))
 
-(define (default-nginx-config config)
+(define-gexp-compiler (nginx-config-file-compiler
+                       (config <nginx-config-file>) system target)
   (match-record config
-                <nginx-configuration>
+                <nginx-config-file>
                 (nginx log-directory run-directory
                  server-blocks upstream-blocks
                  server-names-hash-bucket-size
                  server-names-hash-bucket-max-size)
-   (apply mixed-text-file "nginx.conf"
-          (flatten
-           "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"
-           "    include " nginx "/share/nginx/conf/mime.types;\n"
-           (if server-names-hash-bucket-size
-               (string-append
-                "    server_names_hash_bucket_size "
-                (number->string server-names-hash-bucket-size)
-                ";\n")
-               "")
-           (if server-names-hash-bucket-max-size
-               (string-append
-                "    server_names_hash_bucket_max_size "
-                (number->string server-names-hash-bucket-max-size)
-                ";\n")
-               "")
-           "\n"
-           (map emit-nginx-upstream-config upstream-blocks)
-           (map emit-nginx-server-config server-blocks)
+   (gexp->derivation
+    "nginx.conf"
+    #~(call-with-output-file (ungexp output "out")
+        (lambda (port)
+          (display
+           (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"
+            "    include " #$nginx "/share/nginx/conf/mime.types;\n"
+            #$(if server-names-hash-bucket-size
+                  (string-append
+                   "    server_names_hash_bucket_size "
+                   (number->string server-names-hash-bucket-size)
+                   ";\n")
+                  "")
+            #$(if server-names-hash-bucket-max-size
+                  (string-append
+                   "    server_names_hash_bucket_max_size "
+                   (number->string server-names-hash-bucket-max-size)
+                   ";\n")
+                  "")
+            "\n"
+           #$@(flatten (map emit-nginx-upstream-config upstream-blocks))
+           #$@(flatten (map emit-nginx-server-config server-blocks))
            "}\n"
-           "events {}\n"))))
+           "events {}\n")
+           port))))))
 
 (define %nginx-accounts
   (list (user-group (name "nginx") (system? #t))
@@ -292,7 +316,7 @@ of index files."
 (define (nginx-activation config)
   (match-record config
                 <nginx-configuration>
-                (nginx log-directory run-directory file)
+                (nginx log-directory run-directory config-file)
    #~(begin
        (use-modules (guix build utils))
 
@@ -311,22 +335,20 @@ of index files."
        (mkdir-p (string-append #$run-directory "/logs"))
        ;; Check configuration file syntax.
        (system* (string-append #$nginx "/sbin/nginx")
-                "-c" #$(or file
-                           (default-nginx-config config))
-                  "-t"))))
+                "-c" #$config-file
+                "-t"))))
 
 (define (nginx-shepherd-service config)
   (match-record config
                 <nginx-configuration>
-                (nginx file run-directory)
+                (nginx config-file run-directory)
    (let* ((nginx-binary (file-append nginx "/sbin/nginx"))
           (nginx-action
            (lambda args
              #~(lambda _
                  (zero?
-                  (system* #$nginx-binary "-c"
-                           #$(or file
-                                 (default-nginx-config config))
+                  (system* #$nginx-binary
+                           "-c" #$config-file
                            address@hidden))))))
 
      ;; TODO: Add 'reload' action.
@@ -347,12 +369,22 @@ of index files."
                        (service-extension account-service-type
                                           (const %nginx-accounts))))
                 (compose concatenate)
-                (extend (lambda (config servers)
-                          (nginx-configuration
-                            (inherit config)
+                (extend
+                 (lambda (config servers)
+                   (let ((config-file
+                          (nginx-configuration-config-file config)))
+                     (if (nginx-config-file? config-file)
+                         (nginx-configuration
+                          (inherit config)
+                          (config-file
+                           (nginx-config-file
+                            (inherit config-file)
                             (server-blocks
-                              (append (nginx-configuration-server-blocks 
config)
-                              servers)))))
+                             (append (nginx-config-file-server-blocks 
config-file)
+                                     servers)))))
+                         (unless (null? servers)
+                           (display "warning: cannot extend nginx with a 
custom config file\n")
+                           config)))))
                 (default-value
                   (nginx-configuration))))
 
diff --git a/gnu/tests/web.scm b/gnu/tests/web.scm
index 3fa272c67..06776b2dd 100644
--- a/gnu/tests/web.scm
+++ b/gnu/tests/web.scm
@@ -56,8 +56,9 @@
    (dhcp-client-service)
    (service nginx-service-type
             (nginx-configuration
-             (log-directory "/var/log/nginx")
-             (server-blocks %nginx-servers)))
+             (config-file
+              (nginx-config-file
+               (server-blocks %nginx-servers)))))
    (simple-service 'make-http-root activation-service-type
                    %make-http-root)))
 
-- 
2.15.1






reply via email to

[Prev in Thread] Current Thread [Next in Thread]