Merge branch 'master' into staging
[jackhill/guix/guix.git] / gnu / tests / web.scm
index 1c984dd..7f4518a 100644 (file)
@@ -521,42 +521,43 @@ HTTP-PORT."
 ;;; Patchwork
 ;;;
 
-(define patchwork-initial-database-setup-service
-  (match-lambda
-    (($ <patchwork-database-configuration>
-        engine name user password host port)
-
-     (define start-gexp
-       #~(lambda ()
-           (let ((pid (primitive-fork))
-                 (postgres (getpwnam "postgres")))
-             (if (eq? pid 0)
-                 (dynamic-wind
-                   (const #t)
-                   (lambda ()
-                     (setgid (passwd:gid postgres))
-                     (setuid (passwd:uid postgres))
-                     (primitive-exit
-                      (if (and
-                           (zero?
-                            (system* #$(file-append postgresql "/bin/createuser")
-                                     #$user))
-                           (zero?
-                            (system* #$(file-append postgresql "/bin/createdb")
-                                     "-O" #$user #$name)))
-                          0
-                          1)))
-                   (lambda ()
-                     (primitive-exit 1)))
-                 (zero? (cdr (waitpid pid)))))))
-
-     (shepherd-service
-      (requirement '(postgres))
-      (provision '(patchwork-postgresql-user-and-database))
-      (start start-gexp)
-      (stop #~(const #f))
-      (respawn? #f)
-      (documentation "Setup patchwork database.")))))
+(define (patchwork-initial-database-setup-service configuration)
+  (define start-gexp
+    #~(lambda ()
+        (let ((pid (primitive-fork))
+              (postgres (getpwnam "postgres")))
+          (if (eq? pid 0)
+              (dynamic-wind
+                (const #t)
+                (lambda ()
+                  (setgid (passwd:gid postgres))
+                  (setuid (passwd:uid postgres))
+                  (primitive-exit
+                   (if (and
+                        (zero?
+                         (system* #$(file-append postgresql "/bin/createuser")
+                                  #$(patchwork-database-configuration-user
+                                      configuration)))
+                        (zero?
+                         (system* #$(file-append postgresql "/bin/createdb")
+                                  "-O"
+                                  #$(patchwork-database-configuration-user
+                                      configuration)
+                                  #$(patchwork-database-configuration-name
+                                      configuration))))
+                       0
+                       1)))
+                (lambda ()
+                  (primitive-exit 1)))
+              (zero? (cdr (waitpid pid)))))))
+
+  (shepherd-service
+   (requirement '(postgres))
+   (provision '(patchwork-postgresql-user-and-database))
+   (start start-gexp)
+   (stop #~(const #f))
+   (respawn? #f)
+   (documentation "Setup patchwork database.")))
 
 (define (patchwork-os patchwork)
   (simple-operating-system
@@ -566,7 +567,9 @@ HTTP-PORT."
              (config
               (httpd-config-file
                (listen '("8080"))))))
-   (service postgresql-service-type)
+   (service postgresql-service-type
+            (postgresql-configuration
+             (postgresql postgresql-10)))
    (service patchwork-service-type
             (patchwork-configuration
              (patchwork patchwork)