2015-07-28 21:37:27 +02:00
let
2019-01-26 18:46:57 +01:00
generic =
# dependencies
{ stdenv , lib , fetchurl , makeWrapper
2022-11-23 06:45:51 +01:00
, glibc , zlib , readline , openssl , icu , lz4 , zstd , systemd , libossp_uuid
2022-07-26 10:22:34 +02:00
, pkg-config , libxml2 , tzdata , libkrb5
2019-01-26 18:46:57 +01:00
2019-07-21 21:13:06 +02:00
# This is important to obtain a version of `libpq` that does not depend on systemd.
2022-07-03 15:02:32 +02:00
, enableSystemd ? ! stdenv . isDarwin && ! stdenv . hostPlatform . isStatic
2022-07-26 10:22:34 +02:00
, gssSupport ? with stdenv . hostPlatform ; ! isWindows && ! isStatic
2021-04-28 21:42:44 +02:00
2022-07-26 10:22:34 +02:00
# for postgresql.pkgs
2019-01-26 18:46:57 +01:00
, this , self , newScope , buildEnv
# source specification
2022-08-11 23:36:01 +02:00
, version , hash , psqlSchema ,
2021-01-10 00:52:23 +01:00
# for tests
nixosTests , thisAttr
2019-01-26 18:46:57 +01:00
} :
2018-12-08 06:32:26 +01:00
let
atLeast = lib . versionAtLeast version ;
2021-11-08 12:33:49 +01:00
lz4Enabled = atLeast " 1 4 " ;
2022-11-23 06:45:51 +01:00
zstdEnabled = atLeast " 1 5 " ;
2019-01-26 18:46:57 +01:00
in stdenv . mkDerivation rec {
2019-08-15 14:41:18 +02:00
pname = " p o s t g r e s q l " ;
2018-11-27 20:16:21 +01:00
inherit version ;
2015-07-28 21:37:27 +02:00
src = fetchurl {
2019-08-15 14:41:18 +02: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 " ;
2022-08-11 23:36:01 +02:00
inherit hash ;
2015-07-28 21:37:27 +02:00
} ;
2021-07-23 22:10:53 +02:00
hardeningEnable = lib . optionals ( ! stdenv . cc . isClang ) [ " p i e " ] ;
2021-05-23 20:42:34 +02:00
2017-09-27 21:48:39 +02:00
outputs = [ " o u t " " l i b " " d o c " " m a n " ] ;
2015-10-14 05:47:54 +02:00
setOutputFlags = false ; # $out retains configureFlags :-/
2015-07-28 21:37:27 +02:00
2022-07-03 15:02:32 +02:00
buildInputs = [
zlib
readline
openssl
libxml2
icu
]
2021-11-08 12:33:49 +01:00
++ lib . optionals lz4Enabled [ lz4 ]
2022-11-23 06:45:51 +01:00
++ lib . optionals zstdEnabled [ zstd ]
2019-07-21 21:13:06 +02:00
++ lib . optionals enableSystemd [ systemd ]
2021-04-28 21:42:44 +02:00
++ lib . optionals gssSupport [ libkrb5 ]
2015-07-28 21:37:27 +02:00
++ lib . optionals ( ! stdenv . isDarwin ) [ libossp_uuid ] ;
2022-07-03 15:02:32 +02:00
nativeBuildInputs = [
makeWrapper
pkg-config
] ;
2018-12-08 06:32:26 +01:00
2018-11-27 21:13:23 +01:00
enableParallelBuilding = ! stdenv . isDarwin ;
2015-07-28 21:37:27 +02:00
2020-11-11 01:11:01 +01:00
separateDebugInfo = true ;
2019-05-31 04:30:15 +02:00
buildFlags = [ " w o r l d " ] ;
2015-07-28 21:37:27 +02:00
2019-10-30 01:40:49 +01:00
NIX_CFLAGS_COMPILE = " - I ${ libxml2 . dev } / i n c l u d e / l i b x m l 2 " ;
2018-07-31 05:23:17 +02:00
2018-08-19 09:07:00 +02:00
# Otherwise it retains a reference to compiler and fails; see #44767. TODO: better.
2018-08-20 10:07:27 +02:00
preConfigure = " C C = ${ stdenv . cc . targetPrefix } c c " ;
2018-08-19 09:07:00 +02:00
2015-10-14 05:47:54 +02:00
configureFlags = [
" - - w i t h - o p e n s s l "
2017-07-15 15:58:17 +02:00
" - - w i t h - l i b x m l "
2022-04-03 17:45:27 +02:00
" - - w i t h - i c u "
2015-10-14 05:47:54 +02: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 20:06:13 +02: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 "
2020-11-10 12:43:09 +01:00
" - - e n a b l e - d e b u g "
2019-07-21 21:13:06 +02:00
( lib . optionalString enableSystemd " - - w i t h - s y s t e m d " )
2018-08-02 22:22:42 +02: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 " )
2022-04-03 17:45:27 +02:00
] ++ lib . optionals lz4Enabled [ " - - w i t h - l z 4 " ]
2022-11-23 06:45:51 +01:00
++ lib . optionals zstdEnabled [ " - - w i t h - z s t d " ]
2021-11-28 14:58:40 +01: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 " ] ;
2015-07-28 21:37:27 +02:00
2022-07-03 15:02:32 +02: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 )
] ;
2015-07-28 21:37:27 +02:00
installTargets = [ " i n s t a l l - w o r l d " ] ;
LC_ALL = " C " ;
2022-07-03 15:02:32 +02: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 "
'' ;
2016-05-15 02:37:10 +02:00
2015-07-28 21:37:27 +02:00
postInstall =
''
2017-09-27 21:48:39 +02:00
moveToOutput " l i b / p g x s " " $ o u t " # looks strange, but not deleting it
2019-10-04 01:00:00 +02: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 10:03:23 +01:00
moveToOutput " l i b / l i b e c p g * " " $ o u t "
2015-10-14 05:47:54 +02:00
2017-09-27 21:48:39 +02: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 15:19:46 +01:00
if [ - z " ' ' ${ dontDisableStatic:- } " ] ; then
# Remove static libraries in case dynamic are available.
2019-02-19 02:31:09 +01:00
for i in $ out/lib /* . a $ l i b / l i b / * . a ; d o
2018-01-11 15:19:46 +01:00
name = " $ ( b a s e n a m e " $ i " ) "
2018-11-28 02:33:57 +01: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 15:19:46 +01:00
rm " $ i "
fi
done
fi
2015-07-28 21:37:27 +02:00
'' ;
2018-01-12 05:27:55 +01:00
postFixup = lib . optionalString ( ! stdenv . isDarwin && stdenv . hostPlatform . libc == " g l i b c " )
2016-11-22 22:48:18 +01:00
''
# initdb needs access to "locale" command from glibc.
wrapProgram $ out/bin/initdb - - prefix PATH " : " $ { glibc . bin } /bin
'' ;
2019-06-06 06:18:38 +02:00
doCheck = ! stdenv . isDarwin ;
2019-05-12 21:40:22 +02:00
# autodetection doesn't seem to able to find this, but it's there.
checkTarget = " c h e c k " ;
2019-10-26 00:31:49 +02: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 05:20:18 +02:00
doInstallCheck = false ; # needs a running daemon?
2015-07-28 21:37:27 +02:00
disallowedReferences = [ stdenv . cc ] ;
passthru = {
2020-04-23 17:08:45 +02:00
inherit readline psqlSchema ;
2019-01-26 18:46:57 +01:00
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-10 00:52:23 +01:00
tests . postgresql = nixosTests . postgresql-wal-receiver . ${ thisAttr } ;
2015-07-28 21:37:27 +02:00
} ;
meta = with lib ; {
2020-04-01 03:11:51 +02:00
homepage = " h t t p s : / / w w w . p o s t g r e s q l . o r g " ;
2015-07-28 21:37:27 +02: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 19:31:20 +01:00
license = licenses . postgresql ;
2021-11-08 12:34:41 +01:00
maintainers = with maintainers ; [ thoughtpolice danbst globin marsam ivan ] ;
2018-11-02 19:31:20 +01:00
platforms = platforms . unix ;
2015-07-28 21:37:27 +02:00
} ;
2019-01-26 18:46:57 +01: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
] ;
2022-08-15 05:40:21 +02:00
nativeBuildInputs = [ makeWrapper ] ;
2019-01-26 18:46:57 +01:00
2020-11-10 12:43:09 +01:00
2019-01-26 18:46:57 +01: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 " ] ;
2019-07-21 21:05:41 +02:00
# Note: the duplication of executables is about 4MB size.
# So a nicer solution was patching postgresql to allow setting the
2022-12-18 01:39:44 +01:00
# libdir explicitly.
2019-01-26 18:46:57 +01: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 01:57:16 +02:00
passthru . version = postgresql . version ;
passthru . psqlSchema = postgresql . psqlSchema ;
2019-01-26 18:46:57 +01:00
} ;
2015-07-28 21:37:27 +02:00
2019-02-02 21:56:52 +01:00
in self : {
2015-07-28 21:37:27 +02:00
2019-02-02 21:56:52 +01:00
postgresql_11 = self . callPackage generic {
2022-11-11 05:20:00 +01:00
version = " 1 1 . 1 8 " ;
2019-02-21 18:21:08 +01:00
psqlSchema = " 1 1 . 1 " ; # should be 11, but changing it is invasive
2022-11-11 05:20:00 +01:00
hash = " s h a 2 5 6 - 0 k 8 g 7 8 U u k Y r P v M o h 6 c 6 i j g 4 m O 4 R q D E C P z 6 w 7 P E o P d Q Q = " ;
2019-01-26 18:46:57 +01:00
this = self . postgresql_11 ;
2021-01-10 00:52:23 +01:00
thisAttr = " p o s t g r e s q l _ 1 1 " ;
2019-01-26 18:46:57 +01:00
inherit self ;
2018-10-18 15:52:29 +02:00
} ;
2019-10-04 01:00:00 +02:00
postgresql_12 = self . callPackage generic {
2022-11-11 05:20:00 +01:00
version = " 1 2 . 1 3 " ;
2019-10-04 01:00:00 +02:00
psqlSchema = " 1 2 " ;
2022-11-11 05:20:00 +01:00
hash = " s h a 2 5 6 - t s Y j B G r 0 V I 8 R q E t A e T T W d d E e 0 H D H k 9 F b B G g 7 9 f M i 4 C 0 = " ;
2019-10-04 01:00:00 +02:00
this = self . postgresql_12 ;
2021-01-10 00:52:23 +01:00
thisAttr = " p o s t g r e s q l _ 1 2 " ;
2019-10-04 01:00:00 +02:00
inherit self ;
} ;
2020-09-24 06:20:00 +02:00
postgresql_13 = self . callPackage generic {
2022-11-11 05:20:00 +01:00
version = " 1 3 . 9 " ;
2020-09-24 06:20:00 +02:00
psqlSchema = " 1 3 " ;
2022-11-11 05:20:00 +01:00
hash = " s h a 2 5 6 - 7 x l m w K X k n 7 7 T N w r S g k k o y 2 s R Z G F 6 7 q 4 W B t o o P 3 8 z p B U = " ;
2020-09-24 06:20:00 +02:00
this = self . postgresql_13 ;
2021-01-10 00:52:23 +01:00
thisAttr = " p o s t g r e s q l _ 1 3 " ;
2020-09-24 06:20:00 +02:00
inherit self ;
} ;
2021-06-02 06:20:00 +02:00
postgresql_14 = self . callPackage generic {
2022-11-11 05:20:00 +01:00
version = " 1 4 . 6 " ;
2021-06-02 06:20:00 +02:00
psqlSchema = " 1 4 " ;
2022-11-11 05:20:00 +01:00
hash = " s h a 2 5 6 - U I h A / B g J 0 5 q 3 I n T V 8 T f a u 5 / X + 0 + T P a Q W i u 6 7 I A a e 3 y I = " ;
2021-06-02 06:20:00 +02:00
this = self . postgresql_14 ;
thisAttr = " p o s t g r e s q l _ 1 4 " ;
inherit self ;
} ;
2022-10-13 17:56:40 +02:00
postgresql_15 = self . callPackage generic {
2022-11-11 05:20:00 +01:00
version = " 1 5 . 1 " ;
2022-10-13 17:56:40 +02:00
psqlSchema = " 1 5 " ;
2022-11-11 05:20:00 +01:00
hash = " s h a 2 5 6 - Z P 3 y P X N K + t D f 5 A d 9 r K l q x R 3 N a X 5 o r i 0 9 T K b E X L F O I a 4 = " ;
2022-10-13 17:56:40 +02:00
this = self . postgresql_15 ;
thisAttr = " p o s t g r e s q l _ 1 5 " ;
inherit self ;
} ;
2019-02-02 21:56:52 +01:00
}