1{ lib, stdenv, glibc, fetchurl, zlib, readline, libossp_uuid, openssl, libxml2, makeWrapper, tzdata }:
2
3let
4
5 common = { version, sha256, psqlSchema }:
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 NIX_CFLAGS_COMPILE = [ "-I${libxml2.dev}/include/libxml2" ];
26
27 # Otherwise it retains a reference to compiler and fails; see #44767. TODO: better.
28 preConfigure = "CC=${stdenv.cc.targetPrefix}cc";
29
30 configureFlags = [
31 "--with-openssl"
32 "--with-libxml"
33 "--sysconfdir=/etc"
34 "--libdir=$(lib)/lib"
35 "--with-system-tzdata=${tzdata}/share/zoneinfo"
36 (if stdenv.isDarwin then "--with-uuid=e2fs" else "--with-ossp-uuid")
37 ];
38
39 patches =
40 [ (if atLeast "9.4" then ./disable-resolve_symlinks-94.patch else ./disable-resolve_symlinks.patch)
41 (if atLeast "9.6" then ./less-is-more-96.patch else ./less-is-more.patch)
42 (if atLeast "9.6" then ./hardcode-pgxs-path-96.patch else ./hardcode-pgxs-path.patch)
43 ./specify_pkglibdir_at_runtime.patch
44 ];
45
46 installTargets = [ "install-world" ];
47
48 LC_ALL = "C";
49
50 postConfigure =
51 let path = if atLeast "9.6" then "src/common/config_info.c" else "src/bin/pg_config/pg_config.c"; in
52 ''
53 # Hardcode the path to pgxs so pg_config returns the path in $out
54 substituteInPlace "${path}" --replace HARDCODED_PGXS_PATH $out/lib
55 '';
56
57 postInstall =
58 ''
59 moveToOutput "lib/pgxs" "$out" # looks strange, but not deleting it
60 moveToOutput "lib/*.a" "$out"
61 moveToOutput "lib/libecpg*" "$out"
62
63 # Prevent a retained dependency on gcc-wrapper.
64 substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv.cc}/bin/ld ld
65
66 if [ -z "''${dontDisableStatic:-}" ]; then
67 # Remove static libraries in case dynamic are available.
68 for i in $out/lib/*.a; do
69 name="$(basename "$i")"
70 if [ -e "$lib/lib/''${name%.a}.so" ] || [ -e "''${i%.a}.so" ]; then
71 rm "$i"
72 fi
73 done
74 fi
75 '';
76
77 postFixup = lib.optionalString (!stdenv.isDarwin && stdenv.hostPlatform.libc == "glibc")
78 ''
79 # initdb needs access to "locale" command from glibc.
80 wrapProgram $out/bin/initdb --prefix PATH ":" ${glibc.bin}/bin
81 '';
82
83 doInstallCheck = false; # needs a running daemon?
84
85 disallowedReferences = [ stdenv.cc ];
86
87 passthru = {
88 inherit readline psqlSchema;
89 };
90
91 meta = with lib; {
92 homepage = https://www.postgresql.org;
93 description = "A powerful, open source object-relational database system";
94 license = licenses.postgresql;
95 maintainers = [ maintainers.ocharles ];
96 platforms = platforms.unix;
97 };
98 });
99
100in {
101
102 postgresql93 = common {
103 version = "9.3.24";
104 psqlSchema = "9.3";
105 sha256 = "1a8dnv16n2rxnbwhqw7c0kjpj3xqvkpwk50kvimj4d917cxaf542";
106 };
107
108 postgresql94 = common {
109 version = "9.4.19";
110 psqlSchema = "9.4";
111 sha256 = "12qn9h47rkn4k41gdbxkkvg0pff43k1113jmhc83f19adc1nnxq3";
112 };
113
114 postgresql95 = common {
115 version = "9.5.14";
116 psqlSchema = "9.5";
117 sha256 = "0k8s62h6qd9p3xlx315j5irniskqsnx1nz4ir5r1yhqp07mdab1y";
118 };
119
120 postgresql96 = common {
121 version = "9.6.10";
122 psqlSchema = "9.6";
123 sha256 = "09l4zqs74fqnazdsyln9x657mq3wsbgng9wpvq71yh26cv2sq5c6";
124 };
125
126 postgresql100 = common {
127 version = "10.5";
128 psqlSchema = "10.0";
129 sha256 = "04a07jkvc5s6zgh6jr78149kcjmsxclizsqabjw44ld4j5n633kc";
130 };
131
132}