@@ -1,8 +1,9 @@
1−{ lib, stdenv, fetchurl, zlib, readline, libossp_uuid, openssl }:
1+{ lib, stdenv, glibc, fetchurl, zlib, readline, libossp_uuid, openssl, makeWrapper }:
22
33let
44
5− common = { version, sha256, psqlSchema } @ args: stdenv.mkDerivation (rec {
5+ common = { version, sha256, psqlSchema } @ args:
6+ let atLeast = lib.versionAtLeast version; in stdenv.mkDerivation (rec {
67 name = "postgresql-${version}";
78
89 src = fetchurl {
@@ -14,7 +15,7 @@ let
1415 setOutputFlags = false; # $out retains configureFlags :-/
1516
1617 buildInputs =
17− [ zlib readline openssl ]
18+ [ zlib readline openssl makeWrapper ]
1819 ++ lib.optionals (!stdenv.isDarwin) [ libossp_uuid ];
1920
2021 enableParallelBuilding = true;
@@ -30,9 +31,9 @@ let
3031 ++ lib.optional (!stdenv.isDarwin) "--with-ossp-uuid";
3132
3233 patches =
33− [ (if lib.versionAtLeast version "9.4" then ./disable-resolve_symlinks-94.patch else ./disable-resolve_symlinks.patch)
34− ./less-is-more.patch
35− ./hardcode-pgxs-path.patch
34+ [ (if atLeast "9.4" then ./disable-resolve_symlinks-94.patch else ./disable-resolve_symlinks.patch)
35+ (if atLeast "9.6" then ./less-is-more-96.patch else ./less-is-more.patch)
36+ (if atLeast "9.6" then ./hardcode-pgxs-path-96.patch else ./hardcode-pgxs-path.patch)
3637 ./specify_pkglibdir_at_runtime.patch
3738 ];
3839
@@ -41,10 +42,11 @@ let
4142 LC_ALL = "C";
4243
4344 postConfigure =
44− ''
45− # Hardcode the path to pgxs so pg_config returns the path in $out
46− substituteInPlace "src/bin/pg_config/pg_config.c" --replace HARDCODED_PGXS_PATH $out/lib
47− '';
45+ let path = if atLeast "9.6" then "src/common/config_info.c" else "src/bin/pg_config/pg_config.c"; in
46+ ''
47+ # Hardcode the path to pgxs so pg_config returns the path in $out
48+ substituteInPlace "${path}" --replace HARDCODED_PGXS_PATH $out/lib
49+ '';
4850
4951 postInstall =
5052 ''
@@ -56,6 +58,12 @@ let
5658 substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv.cc}/bin/ld ld
5759 '';
5860
61+ postFixup =
62+ ''
63+ # initdb needs access to "locale" command from glibc.
64+ wrapProgram $out/bin/initdb --prefix PATH ":" ${glibc.bin}/bin
65+ '';
66+
5967 disallowedReferences = [ stdenv.cc ];
6068
6169 passthru = {
@@ -104,5 +112,10 @@ in {
104112 sha256 = "1l3fqxlpxgl6nrcd4h6lpi2hsiv56yg83n3xrn704rmdch8mfpng";
105113 };
106114
115+ postgresql96 = common {
116+ version = "9.6.1";
117+ psqlSchema = "9.6";
118+ sha256 = "1k8zwnabsl8f7vlp3azm4lrklkb9jkaxmihqf0mc27ql9451w475";
119+ };
107120
108121}