2015-07-28 20:37:27 +01:00
|
|
|
let
|
|
|
|
|
2019-01-26 17:46:57 +00:00
|
|
|
generic =
|
|
|
|
# dependencies
|
|
|
|
{ stdenv, lib, fetchurl, makeWrapper
|
|
|
|
, glibc, zlib, readline, openssl, icu, systemd, libossp_uuid
|
|
|
|
, pkgconfig, libxml2, tzdata
|
|
|
|
|
2019-07-21 20:13:06 +01:00
|
|
|
# This is important to obtain a version of `libpq` that does not depend on systemd.
|
2019-07-23 04:08:28 +01:00
|
|
|
, enableSystemd ? (lib.versionAtLeast version "9.6" && !stdenv.isDarwin)
|
2019-07-21 20:13:06 +01:00
|
|
|
|
2019-01-26 17:46:57 +00:00
|
|
|
# for postgreql.pkgs
|
|
|
|
, this, self, newScope, buildEnv
|
|
|
|
|
|
|
|
# source specification
|
|
|
|
, version, sha256, psqlSchema
|
|
|
|
}:
|
2018-12-08 05:32:26 +00:00
|
|
|
let
|
|
|
|
atLeast = lib.versionAtLeast version;
|
|
|
|
icuEnabled = atLeast "10";
|
2019-01-26 17:46:57 +00:00
|
|
|
|
|
|
|
in stdenv.mkDerivation rec {
|
2015-07-28 20:37:27 +01:00
|
|
|
name = "postgresql-${version}";
|
2018-11-27 19:16:21 +00:00
|
|
|
inherit version;
|
2015-07-28 20:37:27 +01:00
|
|
|
|
|
|
|
src = fetchurl {
|
|
|
|
url = "mirror://postgresql/source/v${version}/${name}.tar.bz2";
|
|
|
|
inherit sha256;
|
|
|
|
};
|
|
|
|
|
2017-09-27 20:48:39 +01:00
|
|
|
outputs = [ "out" "lib" "doc" "man" ];
|
2015-10-14 04:47:54 +01:00
|
|
|
setOutputFlags = false; # $out retains configureFlags :-/
|
2015-07-28 20:37:27 +01:00
|
|
|
|
|
|
|
buildInputs =
|
2018-07-27 07:19:05 +01:00
|
|
|
[ zlib readline openssl libxml2 makeWrapper ]
|
2018-12-08 05:32:26 +00:00
|
|
|
++ lib.optionals icuEnabled [ icu ]
|
2019-07-21 20:13:06 +01:00
|
|
|
++ lib.optionals enableSystemd [ systemd ]
|
2015-07-28 20:37:27 +01:00
|
|
|
++ lib.optionals (!stdenv.isDarwin) [ libossp_uuid ];
|
|
|
|
|
2018-12-08 05:32:26 +00:00
|
|
|
nativeBuildInputs = lib.optionals icuEnabled [ pkgconfig ];
|
|
|
|
|
2018-11-27 20:13:23 +00:00
|
|
|
enableParallelBuilding = !stdenv.isDarwin;
|
2015-07-28 20:37:27 +01:00
|
|
|
|
2019-05-31 03:30:15 +01:00
|
|
|
buildFlags = [ "world" ];
|
2015-07-28 20:37:27 +01:00
|
|
|
|
2018-07-31 04:23:17 +01:00
|
|
|
NIX_CFLAGS_COMPILE = [ "-I${libxml2.dev}/include/libxml2" ];
|
|
|
|
|
2018-08-19 08:07:00 +01:00
|
|
|
# Otherwise it retains a reference to compiler and fails; see #44767. TODO: better.
|
2018-08-20 09:07:27 +01:00
|
|
|
preConfigure = "CC=${stdenv.cc.targetPrefix}cc";
|
2018-08-19 08:07:00 +01:00
|
|
|
|
2015-10-14 04:47:54 +01:00
|
|
|
configureFlags = [
|
|
|
|
"--with-openssl"
|
2017-07-15 14:58:17 +01:00
|
|
|
"--with-libxml"
|
2015-10-14 04:47:54 +01:00
|
|
|
"--sysconfdir=/etc"
|
|
|
|
"--libdir=$(lib)/lib"
|
2018-08-11 19:06:13 +01:00
|
|
|
"--with-system-tzdata=${tzdata}/share/zoneinfo"
|
2019-07-21 20:13:06 +01:00
|
|
|
(lib.optionalString enableSystemd "--with-systemd")
|
2018-08-02 21:22:42 +01:00
|
|
|
(if stdenv.isDarwin then "--with-uuid=e2fs" else "--with-ossp-uuid")
|
2018-12-08 05:32:26 +00:00
|
|
|
] ++ lib.optionals icuEnabled [ "--with-icu" ];
|
2015-07-28 20:37:27 +01:00
|
|
|
|
|
|
|
patches =
|
2018-08-06 16:17:49 +01:00
|
|
|
[ (if atLeast "9.4" then ./patches/disable-resolve_symlinks-94.patch else ./patches/disable-resolve_symlinks.patch)
|
|
|
|
(if atLeast "9.6" then ./patches/less-is-more-96.patch else ./patches/less-is-more.patch)
|
|
|
|
(if atLeast "9.6" then ./patches/hardcode-pgxs-path-96.patch else ./patches/hardcode-pgxs-path.patch)
|
|
|
|
./patches/specify_pkglibdir_at_runtime.patch
|
2019-05-31 03:30:15 +01:00
|
|
|
./patches/findstring.patch
|
2019-03-16 11:28:20 +00:00
|
|
|
] ++ lib.optional stdenv.isLinux ./patches/socketdir-in-run.patch;
|
2015-07-28 20:37:27 +01:00
|
|
|
|
|
|
|
installTargets = [ "install-world" ];
|
|
|
|
|
|
|
|
LC_ALL = "C";
|
|
|
|
|
2016-05-15 01:37:10 +01:00
|
|
|
postConfigure =
|
2016-11-22 21:48:18 +00:00
|
|
|
let path = if atLeast "9.6" then "src/common/config_info.c" else "src/bin/pg_config/pg_config.c"; in
|
|
|
|
''
|
|
|
|
# Hardcode the path to pgxs so pg_config returns the path in $out
|
2017-09-27 20:48:39 +01:00
|
|
|
substituteInPlace "${path}" --replace HARDCODED_PGXS_PATH $out/lib
|
2016-11-22 21:48:18 +00:00
|
|
|
'';
|
2016-05-15 01:37:10 +01:00
|
|
|
|
2015-07-28 20:37:27 +01:00
|
|
|
postInstall =
|
|
|
|
''
|
2017-09-27 20:48:39 +01:00
|
|
|
moveToOutput "lib/pgxs" "$out" # looks strange, but not deleting it
|
2019-02-19 01:31:09 +00:00
|
|
|
moveToOutput "lib/libpgcommon.a" "$out"
|
|
|
|
moveToOutput "lib/libpgport.a" "$out"
|
2015-12-02 09:03:23 +00:00
|
|
|
moveToOutput "lib/libecpg*" "$out"
|
2015-10-14 04:47:54 +01:00
|
|
|
|
2017-09-27 20:48:39 +01:00
|
|
|
# Prevent a retained dependency on gcc-wrapper.
|
|
|
|
substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv.cc}/bin/ld ld
|
|
|
|
|
2018-01-11 14:19:46 +00:00
|
|
|
if [ -z "''${dontDisableStatic:-}" ]; then
|
|
|
|
# Remove static libraries in case dynamic are available.
|
2019-02-19 01:31:09 +00:00
|
|
|
for i in $out/lib/*.a $lib/lib/*.a; do
|
2018-01-11 14:19:46 +00:00
|
|
|
name="$(basename "$i")"
|
2018-11-28 01:33:57 +00:00
|
|
|
ext="${stdenv.hostPlatform.extensions.sharedLibrary}"
|
|
|
|
if [ -e "$lib/lib/''${name%.a}$ext" ] || [ -e "''${i%.a}$ext" ]; then
|
2018-01-11 14:19:46 +00:00
|
|
|
rm "$i"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2015-07-28 20:37:27 +01:00
|
|
|
'';
|
|
|
|
|
2018-01-12 04:27:55 +00:00
|
|
|
postFixup = lib.optionalString (!stdenv.isDarwin && stdenv.hostPlatform.libc == "glibc")
|
2016-11-22 21:48:18 +00:00
|
|
|
''
|
|
|
|
# initdb needs access to "locale" command from glibc.
|
|
|
|
wrapProgram $out/bin/initdb --prefix PATH ":" ${glibc.bin}/bin
|
|
|
|
'';
|
|
|
|
|
2019-06-06 05:18:38 +01:00
|
|
|
doCheck = !stdenv.isDarwin;
|
2019-05-12 20:40:22 +01:00
|
|
|
# autodetection doesn't seem to able to find this, but it's there.
|
|
|
|
checkTarget = "check";
|
|
|
|
|
2018-04-25 04:20:18 +01:00
|
|
|
doInstallCheck = false; # needs a running daemon?
|
|
|
|
|
2015-07-28 20:37:27 +01:00
|
|
|
disallowedReferences = [ stdenv.cc ];
|
|
|
|
|
|
|
|
passthru = {
|
2019-01-26 17:46:57 +00:00
|
|
|
inherit readline psqlSchema version;
|
|
|
|
|
|
|
|
pkgs = let
|
|
|
|
scope = { postgresql = this; };
|
|
|
|
newSelf = self // scope;
|
|
|
|
newSuper = { callPackage = newScope (scope // this.pkgs); };
|
|
|
|
in import ./packages.nix newSelf newSuper;
|
|
|
|
|
|
|
|
withPackages = postgresqlWithPackages {
|
|
|
|
inherit makeWrapper buildEnv;
|
|
|
|
postgresql = this;
|
|
|
|
}
|
|
|
|
this.pkgs;
|
2015-07-28 20:37:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
meta = with lib; {
|
2018-11-02 18:31:20 +00:00
|
|
|
homepage = https://www.postgresql.org;
|
2015-07-28 20:37:27 +01:00
|
|
|
description = "A powerful, open source object-relational database system";
|
2018-11-02 18:31:20 +00:00
|
|
|
license = licenses.postgresql;
|
2019-01-26 17:46:57 +00:00
|
|
|
maintainers = with maintainers; [ ocharles thoughtpolice danbst ];
|
2018-11-02 18:31:20 +00:00
|
|
|
platforms = platforms.unix;
|
2018-12-17 15:33:18 +00:00
|
|
|
knownVulnerabilities = optional (!atLeast "9.4")
|
|
|
|
"PostgreSQL versions older than 9.4 are not maintained anymore!";
|
2015-07-28 20:37:27 +01:00
|
|
|
};
|
2019-01-26 17:46:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
postgresqlWithPackages = { postgresql, makeWrapper, buildEnv }: pkgs: f: buildEnv {
|
|
|
|
name = "postgresql-and-plugins-${postgresql.version}";
|
|
|
|
paths = f pkgs ++ [
|
|
|
|
postgresql
|
|
|
|
postgresql.lib
|
|
|
|
postgresql.man # in case user installs this into environment
|
|
|
|
];
|
|
|
|
buildInputs = [ makeWrapper ];
|
|
|
|
|
|
|
|
# We include /bin to ensure the $out/bin directory is created, which is
|
|
|
|
# needed because we'll be removing the files from that directory in postBuild
|
|
|
|
# below. See #22653
|
|
|
|
pathsToLink = ["/" "/bin"];
|
|
|
|
|
2019-07-21 20:05:41 +01:00
|
|
|
# Note: the duplication of executables is about 4MB size.
|
|
|
|
# So a nicer solution was patching postgresql to allow setting the
|
|
|
|
# libdir explicitely.
|
2019-01-26 17:46:57 +00:00
|
|
|
postBuild = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
rm $out/bin/{pg_config,postgres,pg_ctl}
|
|
|
|
cp --target-directory=$out/bin ${postgresql}/bin/{postgres,pg_config,pg_ctl}
|
|
|
|
wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib
|
|
|
|
'';
|
|
|
|
};
|
2015-07-28 20:37:27 +01:00
|
|
|
|
2019-02-02 20:56:52 +00:00
|
|
|
in self: {
|
2015-07-28 20:37:27 +01:00
|
|
|
|
2019-02-02 20:56:52 +00:00
|
|
|
postgresql_9_4 = self.callPackage generic {
|
2019-06-21 05:46:13 +01:00
|
|
|
version = "9.4.23";
|
2015-07-28 20:37:27 +01:00
|
|
|
psqlSchema = "9.4";
|
2019-06-21 05:46:13 +01:00
|
|
|
sha256 = "16qx4gfq7i2nnxm0i3zxpb3z1mmzx05a3fsh95414ay8n049q00d";
|
2019-01-26 17:46:57 +00:00
|
|
|
this = self.postgresql_9_4;
|
|
|
|
inherit self;
|
2015-07-28 20:37:27 +01:00
|
|
|
};
|
|
|
|
|
2019-02-02 20:56:52 +00:00
|
|
|
postgresql_9_5 = self.callPackage generic {
|
2019-06-21 05:46:39 +01:00
|
|
|
version = "9.5.18";
|
2016-01-08 15:47:03 +00:00
|
|
|
psqlSchema = "9.5";
|
2019-06-21 05:46:39 +01:00
|
|
|
sha256 = "1pgkz794wmp4f40843sbin49k5lgl59jvl6nazvdbb6mgr441jfz";
|
2019-01-26 17:46:57 +00:00
|
|
|
this = self.postgresql_9_5;
|
|
|
|
inherit self;
|
2016-01-08 15:47:03 +00:00
|
|
|
};
|
|
|
|
|
2019-02-02 20:56:52 +00:00
|
|
|
postgresql_9_6 = self.callPackage generic {
|
2019-06-21 05:47:08 +01:00
|
|
|
version = "9.6.14";
|
2016-11-22 21:48:18 +00:00
|
|
|
psqlSchema = "9.6";
|
2019-06-21 05:47:08 +01:00
|
|
|
sha256 = "08hsqczy1ixkjyf2vr3s9x69agfz9yr8lh31fir4z0dfr5jw421z";
|
2019-01-26 17:46:57 +00:00
|
|
|
this = self.postgresql_9_6;
|
|
|
|
inherit self;
|
2016-11-22 21:48:18 +00:00
|
|
|
};
|
2016-01-08 15:47:03 +00:00
|
|
|
|
2019-02-02 20:56:52 +00:00
|
|
|
postgresql_10 = self.callPackage generic {
|
2019-06-21 05:47:33 +01:00
|
|
|
version = "10.9";
|
2019-02-21 17:21:08 +00:00
|
|
|
psqlSchema = "10.0"; # should be 10, but changing it is invasive
|
2019-06-21 05:47:33 +01:00
|
|
|
sha256 = "0m0gbf7nwgag6a1z5f9xszwzgf2xhx0ncakyxwxlzs87n1zk32wm";
|
2019-01-26 17:46:57 +00:00
|
|
|
this = self.postgresql_10;
|
|
|
|
inherit self;
|
2017-10-06 23:50:44 +01:00
|
|
|
};
|
|
|
|
|
2019-02-02 20:56:52 +00:00
|
|
|
postgresql_11 = self.callPackage generic {
|
2019-06-21 05:47:59 +01:00
|
|
|
version = "11.4";
|
2019-02-21 17:21:08 +00:00
|
|
|
psqlSchema = "11.1"; # should be 11, but changing it is invasive
|
2019-06-21 05:47:59 +01:00
|
|
|
sha256 = "12ycjlqncijgmd5z078ybwda8ilas96lc7nxxmdq140mzpgjv002";
|
2019-01-26 17:46:57 +00:00
|
|
|
this = self.postgresql_11;
|
|
|
|
inherit self;
|
2018-10-18 14:52:29 +01:00
|
|
|
};
|
|
|
|
|
2019-02-02 20:56:52 +00:00
|
|
|
}
|