From 5b8072fff6afe5a455d06b8b8f37a6d7e0519986 Mon Sep 17 00:00:00 2001 From: Lancelot SIX Date: Fri, 19 Aug 2016 09:06:40 +0200 Subject: postgresql: Fix use with extensions Fixes #15512 and #16032 With the multi output, postgresql cannot find at runtime what is its basedir when looking for libdir and pkglibdir. This commit fixes that. --- nixos/modules/services/databases/postgresql.nix | 4 ++- nixos/tests/postgis.nix | 30 ++++++++++++++++++++++ pkgs/servers/sql/postgresql/default.nix | 1 + .../postgresql/specify_pkglibdir_at_runtime.patch | 29 +++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 nixos/tests/postgis.nix create mode 100644 pkgs/servers/sql/postgresql/specify_pkglibdir_at_runtime.patch diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix index 9988fc6e63be..24ef4637ec98 100644 --- a/nixos/modules/services/databases/postgresql.nix +++ b/nixos/modules/services/databases/postgresql.nix @@ -11,12 +11,14 @@ let if cfg.extraPlugins == [] then pg else pkgs.buildEnv { name = "postgresql-and-plugins-${(builtins.parseDrvName pg.name).version}"; - paths = [ pg ] ++ cfg.extraPlugins; + paths = [ pg pg.lib ] ++ cfg.extraPlugins; + buildInputs = [ pkgs.makeWrapper ]; postBuild = '' mkdir -p $out/bin rm $out/bin/{pg_config,postgres,pg_ctl} cp --target-directory=$out/bin ${pg}/bin/{postgres,pg_config,pg_ctl} + wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib ''; }; diff --git a/nixos/tests/postgis.nix b/nixos/tests/postgis.nix new file mode 100644 index 000000000000..1dba5c363c09 --- /dev/null +++ b/nixos/tests/postgis.nix @@ -0,0 +1,30 @@ +import ./make-test.nix ({ pkgs, ...} : { + name = "postgis"; + meta = with pkgs.stdenv.lib.maintainers; { + maintainers = [ lsix ]; + }; + + nodes = { + master = + { pkgs, config, ... }: + + { + services.postgresql = let mypg = pkgs.postgresql95; in { + enable = true; + package = mypg; + extraPlugins = [ (pkgs.postgis.override { postgresql = mypg; }).v_2_2_1 ]; + initialScript = pkgs.writeText "postgresql-init.sql" + '' + CREATE ROLE postgres WITH superuser login createdb; + ''; + }; + }; + }; + + testScript = '' + startAll; + $master->waitForUnit("postgresql"); + $master->sleep(10); # Hopefully this is long enough!! + $master->succeed("sudo -u postgres psql -c 'CREATE EXTENSION postgis;'"); + ''; +}) diff --git a/pkgs/servers/sql/postgresql/default.nix b/pkgs/servers/sql/postgresql/default.nix index b58ca5f44b9c..c0e97dab8125 100644 --- a/pkgs/servers/sql/postgresql/default.nix +++ b/pkgs/servers/sql/postgresql/default.nix @@ -33,6 +33,7 @@ let [ (if lib.versionAtLeast version "9.4" then ./disable-resolve_symlinks-94.patch else ./disable-resolve_symlinks.patch) ./less-is-more.patch ./hardcode-pgxs-path.patch + ./specify_pkglibdir_at_runtime.patch ]; installTargets = [ "install-world" ]; diff --git a/pkgs/servers/sql/postgresql/specify_pkglibdir_at_runtime.patch b/pkgs/servers/sql/postgresql/specify_pkglibdir_at_runtime.patch new file mode 100644 index 000000000000..fe95d2ee99f0 --- /dev/null +++ b/pkgs/servers/sql/postgresql/specify_pkglibdir_at_runtime.patch @@ -0,0 +1,29 @@ +diff -ur postgresql-9.5.3-orig/src/port/path.c postgresql-9.5.3/src/port/path.c +--- postgresql-9.5.3-orig/src/port/path.c 2016-05-09 22:50:23.000000000 +0200 ++++ postgresql-9.5.3/src/port/path.c 2016-08-29 22:44:10.507377613 +0200 +@@ -714,7 +714,11 @@ + void + get_lib_path(const char *my_exec_path, char *ret_path) + { +- make_relative_path(ret_path, LIBDIR, PGBINDIR, my_exec_path); ++ char const * const nix_pglibdir = getenv("NIX_PGLIBDIR"); ++ if(nix_pglibdir == NULL) ++ make_relative_path(ret_path, LIBDIR, PGBINDIR, my_exec_path); ++ else ++ make_relative_path(ret_path, nix_pglibdir, PGBINDIR, my_exec_path); + } + + /* +@@ -723,7 +727,11 @@ + void + get_pkglib_path(const char *my_exec_path, char *ret_path) + { +- make_relative_path(ret_path, PKGLIBDIR, PGBINDIR, my_exec_path); ++ char const * const nix_pglibdir = getenv("NIX_PGLIBDIR"); ++ if(nix_pglibdir == NULL) ++ make_relative_path(ret_path, PKGLIBDIR, PGBINDIR, my_exec_path); ++ else ++ make_relative_path(ret_path, nix_pglibdir, PGBINDIR, my_exec_path); + } + + /* -- cgit 1.4.1