2020-04-24 23:36:52 +00:00
let
generic =
# dependencies
{ stdenv , lib , fetchurl , makeWrapper
2022-11-27 09:42:12 +00:00
, glibc , zlib , readline , openssl , icu , lz4 , zstd , systemd , libossp_uuid
2022-08-12 12:06:08 +00:00
, pkg-config , libxml2 , tzdata , libkrb5
2020-04-24 23:36:52 +00:00
# This is important to obtain a version of `libpq` that does not depend on systemd.
2023-01-20 10:41:00 +00:00
, enableSystemd ? lib . meta . availableOn stdenv . hostPlatform systemd && ! stdenv . hostPlatform . isStatic
2022-08-12 12:06:08 +00:00
, gssSupport ? with stdenv . hostPlatform ; ! isWindows && ! isStatic
2021-05-20 23:08:51 +00:00
2022-08-12 12:06:08 +00:00
# for postgresql.pkgs
2020-04-24 23:36:52 +00:00
, this , self , newScope , buildEnv
# source specification
2022-09-09 14:08:57 +00:00
, version , hash , psqlSchema ,
2021-01-15 22:18:51 +00:00
# for tests
nixosTests , thisAttr
2020-04-24 23:36:52 +00:00
} :
let
atLeast = lib . versionAtLeast version ;
2021-12-06 16:07:01 +00:00
lz4Enabled = atLeast " 1 4 " ;
2022-11-27 09:42:12 +00:00
zstdEnabled = atLeast " 1 5 " ;
2020-04-24 23:36:52 +00:00
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 " ;
2022-09-09 14:08:57 +00:00
inherit hash ;
2020-04-24 23:36:52 +00:00
} ;
2021-08-05 21:33:18 +00:00
hardeningEnable = lib . optionals ( ! stdenv . cc . isClang ) [ " p i e " ] ;
2021-07-21 07:28:18 +00:00
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 :-/
2022-11-21 17:40:18 +00:00
buildInputs = [
zlib
readline
openssl
libxml2
icu
]
2021-12-06 16:07:01 +00:00
++ lib . optionals lz4Enabled [ lz4 ]
2022-11-27 09:42:12 +00:00
++ lib . optionals zstdEnabled [ zstd ]
2020-04-24 23:36:52 +00:00
++ 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 ] ;
2022-11-21 17:40:18 +00:00
nativeBuildInputs = [
makeWrapper
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 "
2022-10-30 15:09:59 +00:00
" - - w i t h - i c u "
2020-04-24 23:36:52 +00: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 "
" - - 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 " )
2022-10-30 15:09:59 +00:00
] ++ lib . optionals lz4Enabled [ " - - w i t h - l z 4 " ]
2022-11-27 09:42:12 +00:00
++ lib . optionals zstdEnabled [ " - - w i t h - z s t d " ]
2021-12-06 16:07:01 +00:00
++ lib . optionals gssSupport [ " - - w i t h - g s s a p i " ]
++ lib . optionals stdenv . hostPlatform . isRiscV [ " - - d i s a b l e - s p i n l o c k s " ] ;
2020-04-24 23:36:52 +00:00
2022-11-21 17:40:18 +00:00
patches = [
./patches/disable-resolve_symlinks.patch
./patches/less-is-more.patch
./patches/hardcode-pgxs-path.patch
./patches/specify_pkglibdir_at_runtime.patch
./patches/findstring.patch
] ++ lib . optionals 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 " ;
2022-11-21 17:40:18 +00:00
postPatch = ''
# Hardcode the path to pgxs so pg_config returns the path in $out
substituteInPlace " s r c / c o m m o n / c o n f i g _ i n f o . c " - - replace HARDCODED_PGXS_PATH " $ o u t / l i b "
'' ;
2020-04-24 23:36:52 +00:00
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 ;
2021-12-06 16:07:01 +00:00
maintainers = with maintainers ; [ thoughtpolice danbst globin marsam ivan ] ;
2020-04-24 23:36:52 +00:00
platforms = platforms . unix ;
} ;
} ;
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
] ;
2022-09-09 14:08:57 +00:00
nativeBuildInputs = [ makeWrapper ] ;
2020-04-24 23:36:52 +00:00
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
2022-12-28 21:21:41 +00:00
# libdir explicitly.
2020-04-24 23:36:52 +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
'' ;
passthru . version = postgresql . version ;
passthru . psqlSchema = postgresql . psqlSchema ;
} ;
in self : {
postgresql_11 = self . callPackage generic {
2023-02-16 17:41:37 +00:00
version = " 1 1 . 1 9 " ;
2020-04-24 23:36:52 +00:00
psqlSchema = " 1 1 . 1 " ; # should be 11, but changing it is invasive
2023-02-16 17:41:37 +00:00
hash = " s h a 2 5 6 - E x C e K 3 H x E 5 Q F w n I B 2 j c z p h r O c u 4 c I o 2 c n w M g 4 G r u F M I = " ;
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 {
2023-02-16 17:41:37 +00:00
version = " 1 2 . 1 4 " ;
2020-04-24 23:36:52 +00:00
psqlSchema = " 1 2 " ;
2023-02-16 17:41:37 +00:00
hash = " s h a 2 5 6 - e F Y Q I 3 0 4 L I Q t N W 4 0 c T j l j A b / 6 u J A 5 s w L U q x e v M M N B D 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 {
2023-02-16 17:41:37 +00:00
version = " 1 3 . 1 0 " ;
2020-10-07 09:15:18 +00:00
psqlSchema = " 1 3 " ;
2023-02-16 17:41:37 +00:00
hash = " s h a 2 5 6 - W 7 z 1 p W 2 F x E 8 6 i w W P t G h i / 0 n L y R g 0 0 H 4 p X Q L m 3 j w h b f I = " ;
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 {
2023-02-16 17:41:37 +00:00
version = " 1 4 . 7 " ;
2021-06-28 23:13:55 +00:00
psqlSchema = " 1 4 " ;
2023-02-16 17:41:37 +00:00
hash = " s h a 2 5 6 - z v Y P A J j 6 g Q H B V G 9 C V O R b c i r 1 Q x M 3 l F s 3 r y B w B 2 M N s z E = " ;
2021-06-28 23:13:55 +00:00
this = self . postgresql_14 ;
thisAttr = " p o s t g r e s q l _ 1 4 " ;
inherit self ;
} ;
2022-10-21 18:38:19 +00:00
postgresql_15 = self . callPackage generic {
2023-02-16 17:41:37 +00:00
version = " 1 5 . 2 " ;
2022-10-21 18:38:19 +00:00
psqlSchema = " 1 5 " ;
2023-02-16 17:41:37 +00:00
hash = " s h a 2 5 6 - m a I X H 8 P W t b X 1 a 3 V 6 e j y 4 X V C a O O Q n O A X e 8 j l B 7 S u E a M c = " ;
2022-10-21 18:38:19 +00:00
this = self . postgresql_15 ;
thisAttr = " p o s t g r e s q l _ 1 5 " ;
inherit self ;
} ;
2020-04-24 23:36:52 +00:00
}