[PATCH 0/3] Add postgresql-libversion

  • Open
  • quality assurance status badge
Details
One participant
  • Nicolas Graves
Owner
unassigned
Submitted by
Nicolas Graves
Severity
normal
N
N
Nicolas Graves wrote on 19 Oct 10:49 +0200
(address . guix-patches@gnu.org)(name . Nicolas Graves)(address . ngraves@ngraves.fr)
20241019085518.18205-1-ngraves@ngraves.fr
I was in the process of trying to get more useful information from
repology for Guix using a database dump. I've just jumped into the
postgresql-extensions rabbithole. Here's a properly constructed
extension.

I also wonder why:
- the postgresql-service is stuck with postgresql-10
- we don't patch postgresql with a native-search-path just like python so that pg_config/psql reads from this native-search-path for extensions and falls back to its current default instead. It seems like the reasonable thing to do instead of the circumvoluted directory-union for extensions.

Nicolas Graves (3):
gnu: Add libversion.
gnu: final-postgresql: Move to (gnu packages databases).
gnu: Add postgresql-libversion.

gnu/packages/databases.scm | 9 +++
gnu/packages/version-control.scm | 118 ++++++++++++++++++++++++++++++-
gnu/services/databases.scm | 26 +------
3 files changed, 128 insertions(+), 25 deletions(-)

--
2.46.0
N
N
Nicolas Graves wrote on 19 Oct 11:09 +0200
[PATCH 1/3] gnu: Add libversion.
(address . 73876@debbugs.gnu.org)(name . Nicolas Graves)(address . ngraves@ngraves.fr)
20241019090928.21158-1-ngraves@ngraves.fr
* gnu/packages/version-control.scm (libversion): New variable.
---
gnu/packages/version-control.scm | 34 +++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)

Toggle diff (54 lines)
diff --git a/gnu/packages/version-control.scm b/gnu/packages/version-control.scm
index 6bd37fee82..b14ec77ff5 100644
--- a/gnu/packages/version-control.scm
+++ b/gnu/packages/version-control.scm
@@ -47,7 +47,7 @@
;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
;;; Copyright © 2022 Dhruvin Gandhi <contact@dhruvin.dev>
;;; Copyright © 2015, 2022 David Thompson <davet@gnu.org>
-;;; Copyright © 2023 Nicolas Graves <ngraves@ngraves.fr>
+;;; Copyright © 2023, 2024 Nicolas Graves <ngraves@ngraves.fr>
;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
;;; Copyright © 2023 Kjartan Oli Agustsson <kjartanoli@disroot.org>
;;; Copyright © 2023 Steve George <steve@futurile.net>
@@ -1251,6 +1251,38 @@ (define-public libgit2-1.3
;; Tests may be disabled if cross-compiling.
(format #t "Test suite not run.~%"))))))))))
+(define-public libversion
+ (package
+ (name "libversion")
+ (version "3.0.3")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/repology/libversion")
+ (commit version)))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "186dq3x9w8k5xp4b84ms7f5cm10si3yzs52iscgv0xs58c7rfja4"))))
+ (build-system cmake-build-system)
+ (home-page "https://github.com/repology/libversion")
+ (synopsis "Version string comparison library")
+ (description "This package provides a very advanced string comparison
+library, used by the @url{https://repology.org, Repology} project, and able to
+compare versions with:
+
+@itemize
+@item insignificant components
+@item leading zero
+@item unusual separators
+@item letter suffixes
+@item alphanumeric prerelease components
+@item prerelease keywords
+@item patch, post and pl keywords
+@item customizable handling of ambiguous p keyword
+@end itemize")
+ (license license:expat)))
+
(define-public git-crypt
(package
(name "git-crypt")
--
2.46.0
N
N
Nicolas Graves wrote on 19 Oct 11:09 +0200
[PATCH 2/3] gnu: final-postgresql: Move to (gnu packages databases).
(address . 73876@debbugs.gnu.org)(name . Nicolas Graves)(address . ngraves@ngraves.fr)
20241019090928.21158-2-ngraves@ngraves.fr
* 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(-)

Toggle diff (80 lines)
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 <me@bonfacemunyoki.com>
;;; Copyright © 2023 Giacomo Leidi <goodoldpaul@autistici.org>
;;; Copyright © 2024 Troy Figiel <troy@troyfigiel.com>
+;;; Copyright © 2024 Nicolas Graves <ngraves@ngraves.fr>
;;;
;;; 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
N
N
Nicolas Graves wrote on 19 Oct 11:09 +0200
[PATCH 3/3] gnu: Add postgresql-libversion.
(address . 73876@debbugs.gnu.org)(name . Nicolas Graves)(address . ngraves@ngraves.fr)
20241019090928.21158-3-ngraves@ngraves.fr
* gnu/packages/version-control.scm (postgresql-libversion): New variable.
---
gnu/packages/version-control.scm | 85 ++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)

Toggle diff (98 lines)
diff --git a/gnu/packages/version-control.scm b/gnu/packages/version-control.scm
index b14ec77ff5..b70db7a022 100644
--- a/gnu/packages/version-control.scm
+++ b/gnu/packages/version-control.scm
@@ -1570,6 +1570,91 @@ (define-public python-git-multimail
repository")
(license license:gpl2)))
+(define postgresql-libversion-bootstrap
+ (package
+ (name "postgresql-libversion")
+ (version "2.0.1")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/repology/postgresql-libversion")
+ (commit version)))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "0g28dbj0zad62irzv051m4acby974f1ya605xfl48i8g3il9fyny"))))
+ (build-system gnu-build-system)
+ (arguments
+ (list
+ #:tests? #f
+ #:make-flags #~(list (string-append "DESTDIR=" (getcwd) "/tmp-out"))
+ #:phases
+ #~(modify-phases %standard-phases
+ (delete 'configure)
+ (delete 'install)
+ (add-after 'build 'pre-install
+ (lambda args
+ (mkdir "tmp-out")
+ (apply (assoc-ref %standard-phases 'install) args)))
+ (add-after 'pre-install 'install
+ (lambda _
+ (let ((tmp-out (string-append (dirname (getcwd)) "/tmp-out")))
+ (copy-recursively
+ (dirname
+ (dirname (car (find-files tmp-out "libversion.so"))))
+ #$output))))
+ (add-after 'build 'start-postgresql
+ (lambda* (#:key tests? #:allow-other-keys)
+ (when tests?
+ (let ((dbdir (string-append (dirname (getcwd)) "/pgdir")))
+ (invoke "initdb" "-D" dbdir)
+ (invoke "pg_ctl" "-D" dbdir
+ "-o" (string-append "-k " dbdir)
+ "-l" (string-append dbdir "/db.log")
+ "start")
+ (invoke "psql" "-h" dbdir "-d" "postgres"
+ "-c" "CREATE DATABASE nixbld;")
+ (setenv "PGHOST" dbdir)))))
+ (replace 'check
+ (lambda* (#:key tests? #:allow-other-keys)
+ (if tests?
+ (invoke "make" "installcheck")
+ (format #t "test suite not run~%")))))))
+ (inputs (list libversion postgresql))
+ (native-inputs (list pkg-config))
+ (home-page "https://github.com/repology/postgresql-libversion")
+ (synopsis "PostgreSQL extension for version string comparison")
+ (description "This package provides a PostgreSQL extension with support
+for version string comparison through @code{libversion}. It is used to
+experiment with @url{https://repology.org, Repology} database dumps.")
+ (license license:expat)))
+
+;; A postgresql extension needs extend-postgresql with itself to test.
+;; This is because CREATE EXTENSION needs the extension to be in the
+;; postgresql package.
+(define-public postgresql-libversion
+ (package
+ (inherit postgresql-libversion-bootstrap)
+ (arguments
+ (substitute-keyword-arguments
+ (package-arguments postgresql-libversion-bootstrap)
+ ((#:tests? _) #t)
+ ((#:phases phases)
+ #~(modify-phases #$phases
+ (delete 'build)
+ (delete 'pre-install)
+ (delete 'install-license-files)
+ (replace 'install
+ (lambda _
+ (copy-recursively
+ #$(this-package-native-input "postgresql-libversion")
+ #$output)))))))
+ (native-inputs (list pkg-config
+ postgresql-libversion-bootstrap
+ (extend-postgresql
+ postgresql
+ (list postgresql-libversion-bootstrap))))))
+
(define-public python-ghp-import
(package
(name "python-ghp-import")
--
2.46.0
N
N
Nicolas Graves wrote on 19 Oct 19:35 +0200
tag 73876 moreinfo
(address . control@debbugs.gnu.org)
87ttd8uhay.fsf@ngraves.fr
tags 73876 + moreinfo
quit

The approach in timescaledb seems to be better. I'll resubmit a
version. My questions are still relevant though ;)

--
Best regards,
Nicolas Graves
N
N
Nicolas Graves wrote on 20 Oct 11:05 +0200
(address . control@debbugs.gnu.org)
875xpncffc.fsf@ngraves.fr
tags 73876 - moreinfo
quit
--
Best regards,
Nicolas Graves
N
N
Nicolas Graves wrote on 20 Oct 16:21 +0200
[PATCH v2 1/3] gnu: Add libversion.
(address . 73876@debbugs.gnu.org)(name . Nicolas Graves)(address . ngraves@ngraves.fr)
20241020142144.22877-1-ngraves@ngraves.fr
* gnu/packages/version-control.scm (libversion): New variable.
---
gnu/packages/version-control.scm | 34 +++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)

Toggle diff (54 lines)
diff --git a/gnu/packages/version-control.scm b/gnu/packages/version-control.scm
index 6bd37fee82..b14ec77ff5 100644
--- a/gnu/packages/version-control.scm
+++ b/gnu/packages/version-control.scm
@@ -47,7 +47,7 @@
;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
;;; Copyright © 2022 Dhruvin Gandhi <contact@dhruvin.dev>
;;; Copyright © 2015, 2022 David Thompson <davet@gnu.org>
-;;; Copyright © 2023 Nicolas Graves <ngraves@ngraves.fr>
+;;; Copyright © 2023, 2024 Nicolas Graves <ngraves@ngraves.fr>
;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
;;; Copyright © 2023 Kjartan Oli Agustsson <kjartanoli@disroot.org>
;;; Copyright © 2023 Steve George <steve@futurile.net>
@@ -1251,6 +1251,38 @@ (define-public libgit2-1.3
;; Tests may be disabled if cross-compiling.
(format #t "Test suite not run.~%"))))))))))
+(define-public libversion
+ (package
+ (name "libversion")
+ (version "3.0.3")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/repology/libversion")
+ (commit version)))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "186dq3x9w8k5xp4b84ms7f5cm10si3yzs52iscgv0xs58c7rfja4"))))
+ (build-system cmake-build-system)
+ (home-page "https://github.com/repology/libversion")
+ (synopsis "Version string comparison library")
+ (description "This package provides a very advanced string comparison
+library, used by the @url{https://repology.org, Repology} project, and able to
+compare versions with:
+
+@itemize
+@item insignificant components
+@item leading zero
+@item unusual separators
+@item letter suffixes
+@item alphanumeric prerelease components
+@item prerelease keywords
+@item patch, post and pl keywords
+@item customizable handling of ambiguous p keyword
+@end itemize")
+ (license license:expat)))
+
(define-public git-crypt
(package
(name "git-crypt")
--
2.46.0
N
N
Nicolas Graves wrote on 20 Oct 16:21 +0200
[PATCH v2 2/3] gnu: Add postgresql-libversion.
(address . 73876@debbugs.gnu.org)(name . Nicolas Graves)(address . ngraves@ngraves.fr)
20241020142144.22877-2-ngraves@ngraves.fr
* gnu/packages/version-control.scm (postgresql-libversion): New variable.
---
gnu/packages/version-control.scm | 68 ++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)

Toggle diff (81 lines)
diff --git a/gnu/packages/version-control.scm b/gnu/packages/version-control.scm
index b14ec77ff5..00e50a9182 100644
--- a/gnu/packages/version-control.scm
+++ b/gnu/packages/version-control.scm
@@ -1570,6 +1570,74 @@ (define-public python-git-multimail
repository")
(license license:gpl2)))
+(define-public postgresql-libversion
+ (package
+ (name "postgresql-libversion")
+ (version "2.0.1")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/repology/postgresql-libversion")
+ (commit version)))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "0g28dbj0zad62irzv051m4acby974f1ya605xfl48i8g3il9fyny"))))
+ (build-system gnu-build-system)
+ (arguments
+ (list
+ #:make-flags #~(list (string-append "DESTDIR=" (getcwd) "/tmp-out"))
+ #:imported-modules `((guix build union)
+ ,@%default-gnu-imported-modules)
+ #:modules `(,@%default-gnu-imported-modules
+ (guix build union)
+ (ice-9 match))
+ #:phases
+ #~(modify-phases %standard-phases
+ (delete 'configure)
+ (delete 'install)
+ (add-after 'build 'pre-install
+ (lambda args
+ (mkdir "tmp-out")
+ (apply (assoc-ref %standard-phases 'install) args)))
+ (add-after 'pre-install 'install
+ (lambda _
+ (let ((tmp-out (string-append (dirname (getcwd)) "/tmp-out")))
+ (copy-recursively
+ (dirname
+ (dirname (car (find-files tmp-out "libversion.so"))))
+ #$output))))
+ (add-after 'install 'prepare-tests
+ (lambda* (#:key inputs tests? #:allow-other-keys)
+ (if tests?
+ (let ((pg-data (string-append (getcwd) "/../pg-data"))
+ (pg-union (string-append (getcwd) "/../pg-union")))
+ (match inputs
+ (((names . directories) ...)
+ (union-build pg-union (cons #$output directories))))
+ (setenv "PATH" (string-append pg-union "/bin:"
+ (getenv "PATH")))
+ (invoke "initdb" "-D" pg-data)
+ (invoke "pg_ctl" "-D" pg-data
+ "-o" (string-append "-k " pg-data)
+ "-l" (string-append pg-data "/db.log")
+ "start")
+ (setenv "PGHOST" pg-data))
+ (format #t "prepare-tests phase not run~%"))))
+ (replace 'check
+ (lambda* (#:key tests? #:allow-other-keys)
+ (if tests?
+ (invoke "make" "installcheck")
+ (format #t "test suite not run~%")))))))
+ (inputs (list libversion postgresql))
+ (native-inputs (list pkg-config))
+ (home-page "https://github.com/repology/postgresql-libversion")
+ (synopsis "PostgreSQL extension for version string comparison")
+ (description "This package provides a PostgreSQL extension with support
+for version string comparison through @code{libversion}. It is used to
+experiment with @url{https://repology.org, Repology} database dumps.")
+ (license license:expat)))
+
(define-public python-ghp-import
(package
(name "python-ghp-import")
--
2.46.0
N
N
Nicolas Graves wrote on 20 Oct 16:21 +0200
[PATCH v2 3/3] gnu: databases: Rewrite final-postgresql for postgresql-service.
(address . 73876@debbugs.gnu.org)(name . Nicolas Graves)(address . ngraves@ngraves.fr)
20241020142144.22877-3-ngraves@ngraves.fr
* gnu/services/databases.scm (final-postgresql): Rewrite using a
directory-union and rename to extend-postgresql.
---
gnu/services/databases.scm | 31 +++++++++----------------------
1 file changed, 9 insertions(+), 22 deletions(-)

Toggle diff (58 lines)
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index fa332d7978..aed0f414ab 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -205,26 +205,13 @@ (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-public (extend-postgresql postgresql extensions)
+ (if (null? extensions)
+ postgresql
+ (let ((packages (cons* postgresql extensions)))
+ (directory-union
+ (string-join (map package-name packages) "+")
+ packages))))
(define postgresql-activation
(match-lambda
@@ -250,7 +237,7 @@ (define postgresql-activation
(unless (file-exists? #$data-directory)
(let ((initdb (string-append
- #$(final-postgresql postgresql
+ #$(extend-postgresql postgresql
extension-packages)
"/bin/initdb"))
(initdb-args
@@ -297,7 +284,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
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 73876@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 73876
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch