2015-07-28 20:37:27 +01:00
let
2019-01-26 17:46:57 +00:00
generic =
# dependencies
{ stdenv , lib , fetchurl , makeWrapper
2017-02-02 03:28:17 +00:00
, glibc , zlib , readline , openssl , openssl_1_0_2 , icu , systemd , libossp_uuid
2019-01-26 17:46:57 +00:00
, 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 " 1 0 " ;
2019-01-26 17:46:57 +00:00
in stdenv . mkDerivation rec {
2019-08-15 13:41:18 +01:00
pname = " p o s t g r e s q l " ;
2018-11-27 19:16:21 +00:00
inherit version ;
2015-07-28 20:37:27 +01:00
src = fetchurl {
2019-08-15 13:41:18 +01:00
url = " m i r r o r : / / p o s t g r e s q l / s o u r c e / v ${ version } / ${ pname } - ${ version } . t a r . b z 2 " ;
2015-07-28 20:37:27 +01:00
inherit sha256 ;
} ;
2017-09-27 20:48:39 +01:00
outputs = [ " o u t " " l i b " " d o c " " m a n " ] ;
2015-10-14 04:47:54 +01:00
setOutputFlags = false ; # $out retains configureFlags :-/
2015-07-28 20:37:27 +01:00
buildInputs =
2017-02-02 03:28:17 +00:00
[ zlib readline 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 ]
2017-02-02 03:28:17 +00:00
++ [ ( if atLeast " 9 . 5 " then openssl else openssl_1_0_2 ) ]
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 = [ " w o r l d " ] ;
2015-07-28 20:37:27 +01:00
2019-10-30 00:40:49 +00:00
NIX_CFLAGS_COMPILE = " - I ${ libxml2 . dev } / i n c l u d e / l i b x m l 2 " ;
2018-07-31 04:23:17 +01:00
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 = " C C = ${ stdenv . cc . targetPrefix } c c " ;
2018-08-19 08:07:00 +01:00
2015-10-14 04:47:54 +01:00
configureFlags = [
" - - w i t h - o p e n s s l "
2017-07-15 14:58:17 +01:00
" - - w i t h - l i b x m l "
2015-10-14 04:47:54 +01:00
" - - s y s c o n f d i r = / e t c "
" - - l i b d i r = $ ( l i b ) / l i b "
2018-08-11 19:06:13 +01:00
" - - w i t h - s y s t e m - t z d a t a = ${ tzdata } / s h a r e / z o n e i n f o "
2019-07-21 20:13:06 +01:00
( lib . optionalString enableSystemd " - - w i t h - s y s t e m d " )
2018-08-02 21:22:42 +01:00
( if stdenv . isDarwin then " - - w i t h - u u i d = e 2 f s " else " - - w i t h - o s s p - u u i d " )
2018-12-08 05:32:26 +00:00
] ++ lib . optionals icuEnabled [ " - - w i t h - i c u " ] ;
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 = [ " i n s t a l l - w o r l d " ] ;
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 " s r c / c o m m o n / c o n f i g _ i n f o . c " else " s r c / b i n / p g _ c o n f i g / p g _ c o n f i g . 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 " l i b / p g x s " " $ o u t " # looks strange, but not deleting it
2019-10-04 00:00:00 +01:00
moveToOutput " l i b / l i b p g c o m m o n * . a " " $ o u t "
moveToOutput " l i b / l i b p g p o r t * . a " " $ o u t "
2015-12-02 09:03:23 +00:00
moveToOutput " l i b / l i b e c p g * " " $ o u t "
2015-10-14 04:47:54 +01:00
2017-09-27 20:48:39 +01:00
# Prevent a retained dependency on gcc-wrapper.
substituteInPlace " $ o u t / l i b / p g x s / s r c / M a k e f i l e . g l o b a l " - - 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 $ l i b / l i b / * . a ; d o
2018-01-11 14:19:46 +00:00
name = " $ ( b a s e n a m e " $ i " ) "
2018-11-28 01:33:57 +00:00
ext = " ${ stdenv . hostPlatform . extensions . sharedLibrary } "
if [ - e " $ l i b / l i b / ' ' ${ name % . a } $ e x t " ] || [ - e " ' ' ${ i % . a } $ e x t " ] ; 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 == " g l i b c " )
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 = " c h e c k " ;
2019-10-25 23:31:49 +01:00
preCheck =
# On musl, comment skip the following tests, because they break due to
# ! ERROR: could not load library "/build/postgresql-11.5/tmp_install/nix/store/...-postgresql-11.5-lib/lib/libpqwalreceiver.so": Error loading shared library libpq.so.5: No such file or directory (needed by /build/postgresql-11.5/tmp_install/nix/store/...-postgresql-11.5-lib/lib/libpqwalreceiver.so)
# See also here:
# https://git.alpinelinux.org/aports/tree/main/postgresql/disable-broken-tests.patch?id=6d7d32c12e073a57a9e5946e55f4c1fbb68bd442
if stdenv . hostPlatform . isMusl then ''
substituteInPlace src/test/regress/parallel_schedule \
- - replace " s u b s c r i p t i o n " " " \
- - replace " o b j e c t _ a d d r e s s " " "
'' e l s e n u l l ;
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 p o w e r f u l , o p e n s o u r c e o b j e c t - r e l a t i o n a l d a t a b a s e s y s t e m " ;
2018-11-02 18:31:20 +00:00
license = licenses . postgresql ;
2019-08-20 18:36:05 +01:00
maintainers = with maintainers ; [ ocharles thoughtpolice danbst globin ] ;
2018-11-02 18:31:20 +00:00
platforms = platforms . unix ;
2018-12-17 15:33:18 +00:00
knownVulnerabilities = optional ( ! atLeast " 9 . 4 " )
" P o s t g r e S Q L v e r s i o n s o l d e r t h a n 9 . 4 a r e n o t m a i n t a i n e d a n y m o r e ! " ;
2015-07-28 20:37:27 +01:00
} ;
2019-01-26 17:46:57 +00:00
} ;
postgresqlWithPackages = { postgresql , makeWrapper , buildEnv }: pkgs : f : buildEnv {
name = " p o s t g r e s q l - a n d - p l u g i n s - ${ 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 = [ " / " " / b i n " ] ;
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
'' ;
2019-07-22 00:57:16 +01:00
passthru . version = postgresql . version ;
passthru . psqlSchema = postgresql . psqlSchema ;
2019-01-26 17:46:57 +00:00
} ;
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_5 = self . callPackage generic {
2020-02-14 05:00:00 +00:00
version = " 9 . 5 . 2 1 " ;
2016-01-08 15:47:03 +00:00
psqlSchema = " 9 . 5 " ;
2020-02-14 05:00:00 +00:00
sha256 = " 0 b 3 k z c 0 4 3 1 b v p 5 5 j n s 4 2 q 9 h 1 1 1 9 g y 0 7 5 m p 4 a y w n k q 9 3 p m 1 7 n x d b y " ;
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 {
2020-02-14 05:01:00 +00:00
version = " 9 . 6 . 1 7 " ;
2016-11-22 21:48:18 +00:00
psqlSchema = " 9 . 6 " ;
2020-02-14 05:01:00 +00:00
sha256 = " 1 h m 0 w 6 n 9 8 8 n 9 q n 2 w y l h j q 0 2 i 5 a y z b 1 6 r z h g k c v 0 9 f p s l 6 8 n y 7 q g n " ;
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-11-15 01:02:00 +00:00
version = " 1 0 . 1 1 " ;
2019-02-21 17:21:08 +00:00
psqlSchema = " 1 0 . 0 " ; # should be 10, but changing it is invasive
2019-11-15 01:02:00 +00:00
sha256 = " 0 2 f c m v b h 0 m h p l j 3 s 2 j d 2 4 s 6 4 2 y s x 7 b g g n f 0 h 8 b s 5 a m h 7 d g z i 8 p 8 d " ;
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-11-15 01:03:00 +00:00
version = " 1 1 . 6 " ;
2019-02-21 17:21:08 +00:00
psqlSchema = " 1 1 . 1 " ; # should be 11, but changing it is invasive
2019-11-15 01:03:00 +00:00
sha256 = " 0 w 1 i q 4 8 8 k p z f g f n l w 4 k 3 2 l z 5 b y 6 9 5 m p n k q 4 6 1 j r g s r 9 9 z 5 z l z 4 j 9 " ;
2019-01-26 17:46:57 +00:00
this = self . postgresql_11 ;
inherit self ;
2018-10-18 14:52:29 +01:00
} ;
2019-10-04 00:00:00 +01:00
postgresql_12 = self . callPackage generic {
2019-11-15 01:04:00 +00:00
version = " 1 2 . 1 " ;
2019-10-04 00:00:00 +01:00
psqlSchema = " 1 2 " ;
2019-11-15 01:04:00 +00:00
sha256 = " 1 v c 3 h j c b g k d f c z c 1 i p k k 0 2 r a h a b n 7 f a b p b 7 q s 2 0 3 j x p n p a m z 7 6 x 0 " ;
2019-10-04 00:00:00 +01:00
this = self . postgresql_12 ;
inherit self ;
} ;
2019-02-02 20:56:52 +00:00
}