nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 188 lines 5.1 kB view raw
1{ 2 # utils 3 stdenv, 4 fetchFromGitHub, 5 lib, 6 7 # runtime dependencies 8 openssl, 9 tzdata, 10 zlib, 11 12 # build dependencies 13 bison, 14 flex, 15 makeWrapper, 16 perl, 17 pkg-config, 18 19 # passthru / meta 20 postgresql, 21 buildPackages, 22 23 # Curl 24 curlSupport ? 25 lib.meta.availableOn stdenv.hostPlatform curl 26 # Building statically fails with: 27 # configure: error: library 'curl' does not provide curl_multi_init 28 # https://www.postgresql.org/message-id/487dacec-6d8d-46c0-a36f-d5b8c81a56f1%40technowledgy.de 29 && !stdenv.hostPlatform.isStatic, 30 curl, 31 32 # GSSAPI 33 gssSupport ? with stdenv.hostPlatform; !isWindows && !isStatic, 34 libkrb5, 35 36 # NLS 37 nlsSupport ? false, 38 gettext, 39}: 40 41stdenv.mkDerivation (finalAttrs: { 42 pname = "libpq"; 43 version = "18.1"; 44 45 src = fetchFromGitHub { 46 owner = "postgres"; 47 repo = "postgres"; 48 # rev, not tag, on purpose: see generic.nix. 49 rev = "refs/tags/REL_18_1"; 50 hash = "sha256-cZA2hWtr5RwsUrRWkvl/yvUzFPSfdtpyAKGXfrVUr0g="; 51 }; 52 53 __structuredAttrs = true; 54 55 outputs = [ 56 "out" 57 "dev" 58 ]; 59 outputChecks.out = { 60 disallowedReferences = [ "dev" ]; 61 disallowedRequisites = [ 62 stdenv.cc 63 ] 64 ++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs)); 65 }; 66 67 buildInputs = [ 68 zlib 69 openssl 70 ] 71 ++ lib.optionals curlSupport [ curl ] 72 ++ lib.optionals gssSupport [ libkrb5 ] 73 ++ lib.optionals nlsSupport [ gettext ]; 74 75 nativeBuildInputs = [ 76 bison 77 flex 78 makeWrapper 79 perl 80 pkg-config 81 ]; 82 83 # causes random build failures 84 enableParallelBuilding = false; 85 86 separateDebugInfo = true; 87 88 buildFlags = [ 89 "submake-libpgport" 90 "submake-libpq" 91 ]; 92 93 # libpgcommon.a and libpgport.a contain all paths normally returned by pg_config and are 94 # linked into all shared libraries. However, almost no binaries actually use those paths. 95 # The following flags will remove unused sections from all shared libraries - including 96 # those paths. This avoids a lot of circular dependency problems with different outputs, 97 # and allows splitting them cleanly. 98 env.CFLAGS = 99 "-fdata-sections -ffunction-sections" 100 + (if stdenv.cc.isClang then " -flto" else " -fmerge-constants -Wl,--gc-sections"); 101 102 # This flag was introduced upstream in: 103 # https://github.com/postgres/postgres/commit/b6c7cfac88c47a9194d76f3d074129da3c46545a 104 # It causes errors when linking against libpq.a in pkgsStatic: 105 # undefined reference to `pg_encoding_to_char' 106 # Unsetting the flag fixes it. The upstream reasoning to introduce it is about the risk 107 # to have initdb load a libpq.so from a different major version and how to avoid that. 108 # This doesn't apply to us with Nix. 109 env.NIX_CFLAGS_COMPILE = "-UUSE_PRIVATE_ENCODING_FUNCS"; 110 111 configureFlags = [ 112 "--enable-debug" 113 "--sysconfdir=/etc" 114 "--with-openssl" 115 "--with-system-tzdata=${tzdata}/share/zoneinfo" 116 "--without-icu" 117 "--without-perl" 118 "--without-readline" 119 ] 120 ++ lib.optionals curlSupport [ "--with-libcurl" ] 121 ++ lib.optionals gssSupport [ "--with-gssapi" ] 122 ++ lib.optionals nlsSupport [ "--enable-nls" ]; 123 124 patches = lib.optionals stdenv.hostPlatform.isLinux [ 125 ./patches/socketdir-in-run-13+.patch 126 ]; 127 128 postPatch = '' 129 cat ${./pg_config.env.mk} >> src/common/Makefile 130 '' 131 # Explicitly disable building the shared libs, because that would fail with pkgsStatic. 132 + lib.optionalString stdenv.hostPlatform.isStatic '' 133 substituteInPlace src/interfaces/libpq/Makefile \ 134 --replace-fail "all: all-lib libpq-refs-stamp" "all: all-lib" 135 substituteInPlace src/Makefile.shlib \ 136 --replace-fail "all-lib: all-shared-lib" "all-lib: all-static-lib" \ 137 --replace-fail "install-lib: install-lib-shared" "install-lib: install-lib-static" 138 ''; 139 140 installPhase = '' 141 runHook preInstall 142 143 make -C src/common install pg_config.env 144 make -C src/include install 145 make -C src/interfaces/libpq install 146 '' 147 + lib.optionalString curlSupport '' 148 make -C src/interfaces/libpq-oauth install 149 '' 150 + '' 151 make -C src/port install 152 153 substituteInPlace src/common/pg_config.env \ 154 --replace-fail "$out" "@out@" 155 156 install -D src/common/pg_config.env "$dev/nix-support/pg_config.env" 157 moveToOutput "lib/*.a" "$dev" 158 159 rm -rfv $out/share 160 rm -rfv $dev/lib/*_shlib.a 161 162 runHook postInstall 163 ''; 164 165 # PostgreSQL always builds both shared and static libs, so we delete those we don't want. 166 postInstall = if stdenv.hostPlatform.isStatic then "touch $out/empty" else "rm -rfv $dev/lib/*.a"; 167 168 doCheck = false; 169 170 passthru.pg_config = buildPackages.callPackage ./pg_config.nix { 171 inherit (finalAttrs) finalPackage; 172 outputs = { 173 out = lib.getOutput "out" finalAttrs.finalPackage; 174 }; 175 }; 176 177 meta = { 178 inherit (postgresql.meta) 179 homepage 180 license 181 teams 182 platforms 183 ; 184 description = "C application programmer's interface to PostgreSQL"; 185 changelog = "https://www.postgresql.org/docs/release/${finalAttrs.version}/"; 186 pkgConfigModules = [ "libpq" ]; 187 }; 188})