1{ lib, stdenv, glibc, fetchurl, zlib, readline, libossp_uuid, openssl, makeWrapper }:
2
3let
4
5 common = { version, sha256, psqlSchema } @ args:
6 let atLeast = lib.versionAtLeast version; in stdenv.mkDerivation (rec {
7 name = "postgresql-${version}";
8
9 src = fetchurl {
10 url = "mirror://postgresql/source/v${version}/${name}.tar.bz2";
11 inherit sha256;
12 };
13
14 outputs = [ "out" "lib" "doc" ];
15 setOutputFlags = false; # $out retains configureFlags :-/
16
17 buildInputs =
18 [ zlib readline openssl makeWrapper ]
19 ++ lib.optionals (!stdenv.isDarwin) [ libossp_uuid ];
20
21 enableParallelBuilding = true;
22
23 makeFlags = [ "world" ];
24
25 configureFlags = [
26 "--with-openssl"
27 "--sysconfdir=/etc"
28 "--libdir=$(lib)/lib"
29 ]
30 ++ lib.optional (stdenv.isDarwin) "--with-uuid=e2fs"
31 ++ lib.optional (!stdenv.isDarwin) "--with-ossp-uuid";
32
33 patches =
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)
37 ./specify_pkglibdir_at_runtime.patch
38 ];
39
40 installTargets = [ "install-world" ];
41
42 LC_ALL = "C";
43
44 postConfigure =
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 '';
50
51 postInstall =
52 ''
53 moveToOutput "lib/pgxs" "$out" # looks strange, but not deleting it
54 moveToOutput "lib/*.a" "$out"
55 moveToOutput "lib/libecpg*" "$out"
56
57 # Prevent a retained dependency on gcc-wrapper.
58 substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv.cc}/bin/ld ld
59 '';
60
61 postFixup = lib.optionalString (!stdenv.isDarwin)
62 ''
63 # initdb needs access to "locale" command from glibc.
64 wrapProgram $out/bin/initdb --prefix PATH ":" ${glibc.bin}/bin
65 '';
66
67 disallowedReferences = [ stdenv.cc ];
68
69 passthru = {
70 inherit readline psqlSchema;
71 };
72
73 meta = with lib; {
74 homepage = http://www.postgresql.org/;
75 description = "A powerful, open source object-relational database system";
76 license = licenses.postgresql;
77 maintainers = [ maintainers.ocharles ];
78 platforms = platforms.unix;
79 hydraPlatforms = platforms.linux;
80 };
81 });
82
83in {
84
85 postgresql91 = common {
86 version = "9.1.24";
87 psqlSchema = "9.1";
88 sha256 = "1lz5ibvgz6cxprxlnd7a8iwv387idr7k53bdsvy4bw9ayglq83fy";
89 };
90
91 postgresql92 = common {
92 version = "9.2.20";
93 psqlSchema = "9.2";
94 sha256 = "09lgvl996py3mciybnlv0hycfwfxr41n0wksb2jvxjh0hjpbv2hb";
95 };
96
97 postgresql93 = common {
98 version = "9.3.16";
99 psqlSchema = "9.3";
100 sha256 = "0wv8qsi0amdhcl1qvkvas3lm37w6zsi818f5fxm6n0ngr155wpw4";
101 };
102
103 postgresql94 = common {
104 version = "9.4.11";
105 psqlSchema = "9.4";
106 sha256 = "08wxrk8wdhnz0756dsa8jkj0pqanjfpw7w715lyv10618p853sz3";
107 };
108
109 postgresql95 = common {
110 version = "9.5.6";
111 psqlSchema = "9.5";
112 sha256 = "0bz1b9r249ffjfvldaiah2g78ccwq30ddh8hdvlq61z26inmz7mv";
113 };
114
115 postgresql96 = common {
116 version = "9.6.2";
117 psqlSchema = "9.6";
118 sha256 = "1jahzqqw5inyvmacic2ihhj5f8z50lapci2fwws91h719ccbb1q1";
119 };
120
121}