1{ lib, stdenv, glibc, fetchurl, zlib, readline, libossp_uuid, openssl, libxml2, 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" "man" ];
15 setOutputFlags = false; # $out retains configureFlags :-/
16
17 buildInputs =
18 [ zlib readline openssl libxml2 makeWrapper ]
19 ++ lib.optionals (!stdenv.isDarwin) [ libossp_uuid ];
20
21 enableParallelBuilding = true;
22
23 makeFlags = [ "world" ];
24
25 configureFlags = [
26 "--with-openssl"
27 "--with-libxml"
28 "--sysconfdir=/etc"
29 "--libdir=$(lib)/lib"
30 ]
31 ++ lib.optional (stdenv.isDarwin) "--with-uuid=e2fs"
32 ++ lib.optional (!stdenv.isDarwin) "--with-ossp-uuid";
33
34 patches =
35 [ (if atLeast "9.4" then ./disable-resolve_symlinks-94.patch else ./disable-resolve_symlinks.patch)
36 (if atLeast "9.6" then ./less-is-more-96.patch else ./less-is-more.patch)
37 (if atLeast "9.6" then ./hardcode-pgxs-path-96.patch else ./hardcode-pgxs-path.patch)
38 ./specify_pkglibdir_at_runtime.patch
39 ];
40
41 installTargets = [ "install-world" ];
42
43 LC_ALL = "C";
44
45 postConfigure =
46 let path = if atLeast "9.6" then "src/common/config_info.c" else "src/bin/pg_config/pg_config.c"; in
47 ''
48 # Hardcode the path to pgxs so pg_config returns the path in $out
49 substituteInPlace "${path}" --replace HARDCODED_PGXS_PATH $out/lib
50 '';
51
52 postInstall =
53 ''
54 moveToOutput "lib/pgxs" "$out" # looks strange, but not deleting it
55 moveToOutput "lib/*.a" "$out"
56 moveToOutput "lib/libecpg*" "$out"
57
58 # Prevent a retained dependency on gcc-wrapper.
59 substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv.cc}/bin/ld ld
60
61 # Remove static libraries in case dynamic are available.
62 for i in $out/lib/*.a; do
63 name="$(basename "$i")"
64 if [ -e "$lib/lib/''${name%.a}.so" ] || [ -e "''${i%.a}.so" ]; then
65 rm "$i"
66 fi
67 done
68 '';
69
70 postFixup = lib.optionalString (!stdenv.isDarwin)
71 ''
72 # initdb needs access to "locale" command from glibc.
73 wrapProgram $out/bin/initdb --prefix PATH ":" ${glibc.bin}/bin
74 '';
75
76 disallowedReferences = [ stdenv.cc ];
77
78 passthru = {
79 inherit readline psqlSchema;
80 };
81
82 meta = with lib; {
83 homepage = https://www.postgresql.org;
84 description = "A powerful, open source object-relational database system";
85 license = licenses.postgresql;
86 maintainers = [ maintainers.ocharles ];
87 platforms = platforms.unix;
88 hydraPlatforms = platforms.linux;
89 };
90 });
91
92in {
93
94 postgresql91 = common {
95 version = "9.1.24";
96 psqlSchema = "9.1";
97 sha256 = "1lz5ibvgz6cxprxlnd7a8iwv387idr7k53bdsvy4bw9ayglq83fy";
98 };
99
100 postgresql92 = common {
101 version = "9.2.21";
102 psqlSchema = "9.2";
103 sha256 = "0697e843523ee60c563f987f9c65bc4201294b18525d6e5e4b2c50c6d4058ef9";
104 };
105
106 postgresql93 = common {
107 version = "9.3.17";
108 psqlSchema = "9.3";
109 sha256 = "9c03e5f280cfe9bd202fa01af773eb146abd8ab3065f7279d574c568f6948dbe";
110 };
111
112 postgresql94 = common {
113 version = "9.4.12";
114 psqlSchema = "9.4";
115 sha256 = "fca055481875d1c49e31c28443f56472a1474b3fbe25b7ae64440c6118f82e64";
116 };
117
118 postgresql95 = common {
119 version = "9.5.7";
120 psqlSchema = "9.5";
121 sha256 = "8b1e936f82109325decc0f5575e846b93fb4fd384e8c4bde83ff5e7f87fc6cad";
122 };
123
124 postgresql96 = common {
125 version = "9.6.3";
126 psqlSchema = "9.6";
127 sha256 = "1645b3736901f6d854e695a937389e68ff2066ce0cde9d73919d6ab7c995b9c6";
128 };
129
130}