2020-04-24 23:36:52 +00:00
let
generic =
# dependencies
{ stdenv , lib , fetchurl , makeWrapper
, glibc , zlib , readline , openssl , icu , systemd , libossp_uuid
2021-02-05 17:12:51 +00:00
, pkg-config , libxml2 , tzdata
2020-04-24 23:36:52 +00:00
# This is important to obtain a version of `libpq` that does not depend on systemd.
, enableSystemd ? ( lib . versionAtLeast version " 9 . 6 " && ! stdenv . isDarwin )
2021-05-20 23:08:51 +00:00
, gssSupport ? with stdenv . hostPlatform ; ! isWindows && ! isStatic , libkrb5
2020-04-24 23:36:52 +00:00
# for postgreql.pkgs
, this , self , newScope , buildEnv
# source specification
2021-01-15 22:18:51 +00:00
, version , sha256 , psqlSchema ,
# for tests
nixosTests , thisAttr
2020-04-24 23:36:52 +00:00
} :
let
atLeast = lib . versionAtLeast version ;
icuEnabled = atLeast " 1 0 " ;
in stdenv . mkDerivation rec {
pname = " p o s t g r e s q l " ;
inherit version ;
src = fetchurl {
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 " ;
inherit sha256 ;
} ;
2021-07-21 07:28:18 +00:00
hardeningEnable = lib . optionals ( ! stdenv . isDarwin ) [ " p i e " ] ;
2020-04-24 23:36:52 +00:00
outputs = [ " o u t " " l i b " " d o c " " m a n " ] ;
setOutputFlags = false ; # $out retains configureFlags :-/
buildInputs =
2021-03-09 03:18:52 +00:00
[ zlib readline openssl libxml2 ]
2020-04-24 23:36:52 +00:00
++ lib . optionals icuEnabled [ icu ]
++ lib . optionals enableSystemd [ systemd ]
2021-05-20 23:08:51 +00:00
++ lib . optionals gssSupport [ libkrb5 ]
2020-04-24 23:36:52 +00:00
++ lib . optionals ( ! stdenv . isDarwin ) [ libossp_uuid ] ;
2021-03-09 03:18:52 +00:00
nativeBuildInputs = [ makeWrapper ] ++ lib . optionals icuEnabled [ pkg-config ] ;
2020-04-24 23:36:52 +00:00
enableParallelBuilding = ! stdenv . isDarwin ;
2020-11-30 08:33:03 +00:00
separateDebugInfo = true ;
2020-04-24 23:36:52 +00:00
buildFlags = [ " w o r l d " ] ;
NIX_CFLAGS_COMPILE = " - I ${ libxml2 . dev } / i n c l u d e / l i b x m l 2 " ;
# Otherwise it retains a reference to compiler and fails; see #44767. TODO: better.
preConfigure = " C C = ${ stdenv . cc . targetPrefix } c c " ;
configureFlags = [
" - - w i t h - o p e n s s l "
" - - w i t h - l i b x m l "
" - - 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 "
" - - 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 "
2020-11-30 08:33:03 +00:00
" - - e n a b l e - d e b u g "
2020-04-24 23:36:52 +00:00
( lib . optionalString enableSystemd " - - w i t h - s y s t e m d " )
( 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 " )
2021-05-20 23:08:51 +00:00
] ++ lib . optionals icuEnabled [ " - - w i t h - i c u " ]
++ lib . optionals gssSupport [ " - - w i t h - g s s a p i " ] ;
2020-04-24 23:36:52 +00:00
patches =
[ ( 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
./patches/findstring.patch
2020-11-06 00:33:48 +00:00
]
++ lib . optional stdenv . isLinux ( if atLeast " 1 3 " then ./patches/socketdir-in-run-13.patch else ./patches/socketdir-in-run.patch ) ;
2020-04-24 23:36:52 +00:00
installTargets = [ " i n s t a l l - w o r l d " ] ;
LC_ALL = " C " ;
postConfigure =
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
substituteInPlace " ${ path } " - - replace HARDCODED_PGXS_PATH $ out/lib
'' ;
postInstall =
''
moveToOutput " l i b / p g x s " " $ o u t " # looks strange, but not deleting it
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 "
moveToOutput " l i b / l i b e c p g * " " $ o u t "
# 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
if [ - z " ' ' ${ dontDisableStatic:- } " ] ; then
# Remove static libraries in case dynamic are available.
for i in $ out/lib /* . a $ l i b / l i b / * . a ; d o
name = " $ ( b a s e n a m e " $ i " ) "
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
rm " $ i "
fi
done
fi
'' ;
postFixup = lib . optionalString ( ! stdenv . isDarwin && stdenv . hostPlatform . libc == " g l i b c " )
''
# initdb needs access to "locale" command from glibc.
wrapProgram $ out/bin/initdb - - prefix PATH " : " $ { glibc . bin } /bin
'' ;
doCheck = ! stdenv . isDarwin ;
# autodetection doesn't seem to able to find this, but it's there.
checkTarget = " c h e c k " ;
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 ;
doInstallCheck = false ; # needs a running daemon?
disallowedReferences = [ stdenv . cc ] ;
passthru = {
inherit readline psqlSchema ;
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 ;
2021-01-15 22:18:51 +00:00
tests . postgresql = nixosTests . postgresql-wal-receiver . ${ thisAttr } ;
2020-04-24 23:36:52 +00:00
} ;
meta = with lib ; {
homepage = " h t t p s : / / w w w . p o s t g r e s q l . o r g " ;
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 " ;
license = licenses . postgresql ;
2020-12-09 12:39:15 +00:00
maintainers = with maintainers ; [ thoughtpolice danbst globin marsam ] ;
2020-04-24 23:36:52 +00:00
platforms = platforms . unix ;
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 ! " ;
} ;
} ;
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 ] ;
2020-11-30 08:33:03 +00:00
2020-04-24 23:36:52 +00:00
# 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 " ] ;
# Note: the duplication of executables is about 4MB size.
# So a nicer solution was patching postgresql to allow setting the
# libdir explicitely.
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
'' ;
passthru . version = postgresql . version ;
passthru . psqlSchema = postgresql . psqlSchema ;
} ;
in self : {
postgresql_9_6 = self . callPackage generic {
2021-06-28 23:13:55 +00:00
version = " 9 . 6 . 2 2 " ;
2020-04-24 23:36:52 +00:00
psqlSchema = " 9 . 6 " ;
2021-06-28 23:13:55 +00:00
sha256 = " 0 c 1 9 k z r j 5 i b 5 y g m a v f 5 d 6 q v x d w r x z z z 6 j z 1 r 2 d l 5 b 8 1 5 2 0 8 c s c i x " ;
2020-04-24 23:36:52 +00:00
this = self . postgresql_9_6 ;
2021-01-15 22:18:51 +00:00
thisAttr = " p o s t g r e s q l _ 9 _ 6 " ;
2020-04-24 23:36:52 +00:00
inherit self ;
} ;
postgresql_10 = self . callPackage generic {
2021-06-28 23:13:55 +00:00
version = " 1 0 . 1 7 " ;
2020-04-24 23:36:52 +00:00
psqlSchema = " 1 0 . 0 " ; # should be 10, but changing it is invasive
2021-06-28 23:13:55 +00:00
sha256 = " 0 v 5 j a h k q m 6 g k q 6 7 s 4 b a c 3 h 7 2 9 7 b s c n 2 a b 6 y 1 2 8 i d i 7 3 c c 1 q q 1 w j s " ;
2020-04-24 23:36:52 +00:00
this = self . postgresql_10 ;
2021-01-15 22:18:51 +00:00
thisAttr = " p o s t g r e s q l _ 1 0 " ;
2020-04-24 23:36:52 +00:00
inherit self ;
2021-04-05 15:23:46 +00:00
icu = self . icu67 ;
2020-04-24 23:36:52 +00:00
} ;
postgresql_11 = self . callPackage generic {
2021-06-28 23:13:55 +00:00
version = " 1 1 . 1 2 " ;
2020-04-24 23:36:52 +00:00
psqlSchema = " 1 1 . 1 " ; # should be 11, but changing it is invasive
2021-06-28 23:13:55 +00:00
sha256 = " 0 1 6 b a c p m q x c 6 7 6 i p z c 1 l 8 z v 1 j j 4 4 m j z 7 d v 7 j h q a z g 3 i b d f q x i y c 7 " ;
2020-04-24 23:36:52 +00:00
this = self . postgresql_11 ;
2021-01-15 22:18:51 +00:00
thisAttr = " p o s t g r e s q l _ 1 1 " ;
2020-04-24 23:36:52 +00:00
inherit self ;
} ;
postgresql_12 = self . callPackage generic {
2021-06-28 23:13:55 +00:00
version = " 1 2 . 7 " ;
2020-04-24 23:36:52 +00:00
psqlSchema = " 1 2 " ;
2021-06-28 23:13:55 +00:00
sha256 = " 1 5 f r s m s l 1 n 2 i 4 p 7 6 j i 0 w n g 4 l v n l z w 6 f 0 1 b r 4 c s 5 x r 3 n 8 8 w g p 9 4 4 4 " ;
2020-04-24 23:36:52 +00:00
this = self . postgresql_12 ;
2021-01-15 22:18:51 +00:00
thisAttr = " p o s t g r e s q l _ 1 2 " ;
2020-04-24 23:36:52 +00:00
inherit self ;
} ;
2020-10-07 09:15:18 +00:00
postgresql_13 = self . callPackage generic {
2021-06-28 23:13:55 +00:00
version = " 1 3 . 3 " ;
2020-10-07 09:15:18 +00:00
psqlSchema = " 1 3 " ;
2021-06-28 23:13:55 +00:00
sha256 = " 1 8 d l i q 7 h 2 l 8 i r f f h y y h d m f w x 3 s i 5 1 5 q 6 g d s 3 c x d j b 9 n 7 m 1 7 l b n 9 w " ;
2020-10-07 09:15:18 +00:00
this = self . postgresql_13 ;
2021-01-15 22:18:51 +00:00
thisAttr = " p o s t g r e s q l _ 1 3 " ;
2020-10-07 09:15:18 +00:00
inherit self ;
} ;
2021-06-28 23:13:55 +00:00
postgresql_14 = self . callPackage generic {
version = " 1 4 b e t a 1 " ;
psqlSchema = " 1 4 " ;
sha256 = " 0 l i h 2 i y k y c h h v i s 3 m x q y p 0 8 7 m 1 h l d 3 l y i 4 8 n 3 q w d 2 j s 4 4 p r x v 4 6 4 " ;
this = self . postgresql_14 ;
thisAttr = " p o s t g r e s q l _ 1 4 " ;
inherit self ;
} ;
2020-04-24 23:36:52 +00:00
}