Subject: [PATCH 2/3] gnu: final-postgresql: Move to (gnu packages databases).

From: Nicolas Graves <[email-masked]>
Date: Sat, 19 Oct 2024 11:09:14 +0200

* gnu/services/databases.scm (final-postgresql): Move from here...
* gnu/packages/databases.scm (extend-postgresql): ...to here and
switch to directory-union implementation.
---
 gnu/packages/databases.scm |  9 +++++++++
 gnu/services/databases.scm | 26 ++------------------------
 2 files changed, 11 insertions(+), 24 deletions(-)

diff --git a/gnu/packages/databases.scm b/gnu/packages/databases.scm
index f05566becd..d9dc4525aa 100644
--- a/gnu/packages/databases.scm
+++ b/gnu/packages/databases.scm
@@ -63,6 +63,7 @@
 ;;; Copyright © 2023 Munyoki Kilyungi <[email-masked]>
 ;;; Copyright © 2023 Giacomo Leidi <[email-masked]>
 ;;; Copyright © 2024 Troy Figiel <[email-masked]>
+;;; Copyright © 2024 Nicolas Graves <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1409,6 +1410,14 @@ (define-public postgresql-10
 
 (define-public postgresql postgresql-14)
 
+(define-public (extend-postgresql postgresql extensions)
+  (if (null? extensions)
+      postgresql
+      (let ((packages (cons* postgresql extensions)))
+        (directory-union
+         (string-join (map package-name packages) "+")
+         packages))))
+
 (define-public timescaledb
   (package
     (name "timescaledb")
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index fa332d7978..dc6c1720ff 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -205,27 +205,6 @@ (define (create-postgresql-account config)
                (home-directory "/var/empty")
                (shell (file-append shadow "/sbin/nologin")))))))
 
-(define (final-postgresql postgresql extension-packages)
-  (if (null? extension-packages)
-    postgresql
-    (package
-      (inherit postgresql)
-      (source #f)
-      (build-system trivial-build-system)
-      (arguments
-       `(#:modules ((guix build utils) (guix build union))
-         #:builder
-         (begin
-           (use-modules (guix build utils) (guix build union) (srfi srfi-26))
-           (union-build (assoc-ref %outputs "out")
-                        (map (lambda (input) (cdr input))
-                             %build-inputs))
-           #t)))
-      (inputs
-       `(("postgresql" ,postgresql)
-         ,@(map (lambda (extension) (list "extension" extension))
-                extension-packages))))))
-
 (define postgresql-activation
   (match-lambda
     (($ <postgresql-configuration> postgresql port locale config-file
@@ -250,8 +229,7 @@ (define postgresql-activation
 
            (unless (file-exists? #$data-directory)
              (let ((initdb (string-append
-                            #$(final-postgresql postgresql
-                                                extension-packages)
+                            #$(extend-postgresql postgresql extension-packages)
                             "/bin/initdb"))
                    (initdb-args
                     (append
@@ -297,7 +275,7 @@ (define postgresql-shepherd-service
                     ((_ mode)
                      (let ((user (getpwnam "postgres"))
                            (pg_ctl #$(file-append
-                                      (final-postgresql postgresql
+                                      (extend-postgresql postgresql
                                                         extension-packages)
                                                   "/bin/pg_ctl"))
                            (options (format #f "--config-file=~a -p ~d"
-- 
2.46.0