Subject: [bug#32297] [PATCH] make postgresql find its plugins

From: Julien Lepiller <[email-masked]>
Date: Sat, 28 Jul 2018 17:58:15 +0200

Hi,

attached is a patch to make postgresql find its plugins. Actually, it
only makes it unable to follow symlinks, so we can provide a union of
postgresql and plugins to the postgresql service. I also attached an
example system configuration that shows how this works. Do you think
this is the right solution? The patch was taken from nixos and updated
for the current version of postgresql.

Note that the VM will have troubles loading the extensions with only
its 256MB memory by default. You should add more ram to it.

Inside the VM, you can test with:

psql -U postgres
> create database postgistest;
> \connect postgistest;
> create extension postgis;
> create extension postgis_topology;

no error, you now have an empty spatial database :)

An extension would be to have a procedure to build the union of
packages (postgresql and extensions) called by the postgresql service.
we would have an "extension" field that would contain a list of
packages that contain extensions for postgresql and the service would
build and use the union of postgresql and these extensions. WDYT?
From 74b24f0e0323174156d3407a83833a5a72b0174a Mon Sep 17 00:00:00 2001
From: Julien Lepiller <[email-masked]>
Date: Sat, 28 Jul 2018 17:38:38 +0200
Subject: [PATCH] gnu: postgresql: Fix finding extensions.

* gnu/packages/patches/postgresql-disable-resolve_symlinks.patch: New
file.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/databases.scm (postgresql)[source]: Use it.
---
 gnu/local.mk                                  |  1 +
 gnu/packages/databases.scm                    |  5 ++--
 .../postgresql-disable-resolve_symlinks.patch | 25 +++++++++++++++++++
 3 files changed, 29 insertions(+), 2 deletions(-)
 create mode 100644 gnu/packages/patches/postgresql-disable-resolve_symlinks.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 612304bad..f98cf86e6 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1037,6 +1037,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/polkit-drop-test.patch			\
   %D%/packages/patches/portaudio-audacity-compat.patch		\
   %D%/packages/patches/portmidi-modular-build.patch		\
+  %D%/packages/patches/postgresql-disable-resolve_symlinks.patch\
   %D%/packages/patches/potrace-tests.patch			\
   %D%/packages/patches/procmail-ambiguous-getline-debian.patch  \
   %D%/packages/patches/procmail-CVE-2014-3618.patch		\
diff --git a/gnu/packages/databases.scm b/gnu/packages/databases.scm
index 382c74cfd..562b66fde 100644
--- a/gnu/packages/databases.scm
+++ b/gnu/packages/databases.scm
@@ -18,7 +18,7 @@
 ;;; Copyright © 2016 Andy Patterson <[email-masked]>
 ;;; Copyright © 2016 Danny Milosavljevic <[email-masked]>
 ;;; Copyright © 2016, 2017, 2018 Marius Bakke <[email-masked]>
-;;; Copyright © 2017 Julien Lepiller <[email-masked]>
+;;; Copyright © 2017, 2018 Julien Lepiller <[email-masked]>
 ;;; Copyright © 2017 Thomas Danckaert <[email-masked]>
 ;;; Copyright © 2017 Jelle Licht <[email-masked]>
 ;;; Copyright © 2017 Adriano Peluso <[email-masked]>
@@ -713,7 +713,8 @@ as a drop-in replacement of MySQL.")
                                   version "/postgresql-" version ".tar.bz2"))
               (sha256
                (base32
-                "0j000bcs9w8wrllg8m7j1lxsd3n2x0yzkack5p35cmxx20iq2q0v"))))
+                "0j000bcs9w8wrllg8m7j1lxsd3n2x0yzkack5p35cmxx20iq2q0v"))
+	      (patches (search-patches "postgresql-disable-resolve_symlinks.patch"))))
     (build-system gnu-build-system)
     (arguments
      `(#:configure-flags '("--with-uuid=e2fs")
diff --git a/gnu/packages/patches/postgresql-disable-resolve_symlinks.patch b/gnu/packages/patches/postgresql-disable-resolve_symlinks.patch
new file mode 100644
index 000000000..7874c37b9
--- /dev/null
+++ b/gnu/packages/patches/postgresql-disable-resolve_symlinks.patch
@@ -0,0 +1,25 @@
+From 223c82d1d6ed1f29f26307249827ff679e09c780 Mon Sep 17 00:00:00 2001
+From: Julien Lepiller <[email-masked]>
+Date: Sat, 28 Jul 2018 12:22:12 +0200
+Subject: [PATCH] disable resolve_symlink
+
+---
+ src/common/exec.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/src/common/exec.c b/src/common/exec.c
+index 878fc29..6b3e283 100644
+--- a/src/common/exec.c
++++ b/src/common/exec.c
+@@ -218,6 +218,8 @@ find_my_exec(const char *argv0, char *retpath)
+ static int
+ resolve_symlinks(char *path)
+ {
++	// On GuixSD we *want* stuff relative to symlinks.
++	return 0;
+ #ifdef HAVE_READLINK
+ 	struct stat buf;
+ 	char		orig_wd[MAXPGPATH],
+-- 
+2.18.0
+
-- 
2.18.0