Skip to content

Commit e3f689e

Browse files
brainrakeclaude
andauthored
perf(nix): shrink postgres-env closure (#2521)
* perf(nix): shrink postgres-env closure Strip pgrx extension .so files fully. The stdenv fixup only strips debug sections and leaves .symtab behind. Split postgres-env-* into a runtime env and postgres-env-*-debug, which carries postgresql_*_src and debug symbols. Drop supautils from the base psql_* extension set. The site profile loads it through dynamic_library_path, so install site-env on the AMI, add pg-extensions to site-env, and set dynamic_library_path. Add psql_*_latest, which ships only the latest version of each extension, and use it in postgres-env-*. Split slim from latestOnly so the base env keeps systemd support and the regular locales. Link postgres against systemdLibs instead of the full systemd. Use the main curl in pg_net, which removes a second glibc. Build sfcgal and cgal against boost with icu75, which removes a second ICU. postgres-env-17 closure on aarch64-linux: 2.54 GB to 1.00 GB. Refs: MPG-1325 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(nix): correct supautils path in checks Refs: MPG-1325 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(nix): build old pg_net versions against current curl Versions before 0.20.4 include curl/multi.h directly. With curl 8.17 the typecheck macro for curl_multi_setopt breaks the declaration in multi.h. Define CURL_DISABLE_TYPECHECK for those versions. Refs: MPG-1325 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(nix): keep all extension versions in postgres-env Drop psql_*_latest and the slim split. Add psql_*_env, the base extension set without supautils, and build postgres-env-* from it. Supautils stays in the base psql_* for tests and docker images. Refs: MPG-1325 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(nix): drop supautils and site-env changes Keep supautils in the base extension set and leave site-env and the ansible config as on develop, so this change stands alone. Use the smaller pg_net compile flag change. Refs: MPG-1325 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(nix): leave postgres-env as on develop Move the debug env split out to its own change. Refs: MPG-1325 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(nix): link darwin pg_net curl against apple libiconv Build libunistring, libidn2, and libpsl against apple libiconv for the pg_net curl on darwin, so the cli bundle has a single libiconv.2.dylib. Refs: MPG-1325 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * perf(nix): build pgbouncer against systemdLibs pgbouncer only needs sd_notify from libsystemd. The full systemd pulled in kbd, p11-kit, elfutils, tpm2-tss, gnutls, and cryptsetup as well. Refs: MPG-1325 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(nix): leave pgrx stripping as on develop Move the pgrx strip to the debug env change. Refs: MPG-1325 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(nix): pick the darwin curl at the pg_net use site Refs: MPG-1325 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent bf5e681 commit e3f689e

5 files changed

Lines changed: 36 additions & 12 deletions

File tree

‎nix/ext/pg_net.nix‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,39 @@
77
libuv,
88
makeWrapper,
99
switch-ext-version,
10-
curl_8_6,
10+
curl,
11+
libidn2,
12+
libpsl,
13+
libunistring,
14+
libiconv,
1115
latestOnly ? false,
1216
}:
1317

1418
let
15-
curl = curl_8_6;
16-
in
17-
let
19+
# nixpkgs builds libunistring against gnu libiconv on darwin, which collides with apple's in the cli bundle
20+
curlAppleIconv =
21+
let
22+
libunistringApple = libunistring.override { libiconvReal = libiconv; };
23+
libidn2Apple = libidn2.override { libunistring = libunistringApple; };
24+
libpslApple =
25+
(libpsl.override {
26+
libidn2 = libidn2Apple;
27+
libunistring = libunistringApple;
28+
}).overrideAttrs
29+
{ env.NIX_LDFLAGS = "-liconv"; };
30+
in
31+
curl.override {
32+
libidn2 = libidn2Apple;
33+
libpsl = libpslApple;
34+
};
1835
pname = "pg_net";
1936
build =
2037
version: hash:
2138
stdenv.mkDerivation rec {
2239
inherit pname version;
2340

2441
buildInputs = [
25-
curl
42+
(if stdenv.isDarwin then curlAppleIconv else curl)
2643
postgresql
2744
]
2845
++ lib.optional (version == "0.6") libuv;
@@ -35,6 +52,9 @@ let
3552
};
3653

3754
buildPhase = ''
55+
${lib.optionalString (lib.versionOlder version "0.20.4") ''
56+
export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -DCURL_DISABLE_TYPECHECK"
57+
''}
3858
make PG_CONFIG=${postgresql}/bin/pg_config
3959
'';
4060

‎nix/ext/postgis.nix‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,20 @@
2222
coreutils,
2323
cgal,
2424
sfcgal,
25+
boost,
26+
icu75,
2527
latestOnly ? false,
2628
}:
2729

2830
let
31+
boostIcu75 = boost.override { icu = icu75; };
2932
# Hold cgal back to 6.0.2 until nixpkgs bumps sfcgal past 2.2.0 (incompatible with CGAL 6.1+).
3033
sfcgal' =
3134
assert lib.assertMsg (lib.versionAtLeast "2.2.0" sfcgal.version)
3235
"sfcgal ${sfcgal.version} is newer than 2.2.0, drop the cgal 6.0.2 pin";
3336
sfcgal.override {
34-
cgal = cgal.overrideAttrs (_: {
37+
boost = boostIcu75;
38+
cgal = (cgal.override { boost = boostIcu75; }).overrideAttrs (_: {
3539
version = "6.0.2";
3640
src = fetchurl {
3741
url = "https://github.com/CGAL/cgal/releases/download/v6.0.2/CGAL-6.0.2.tar.xz";

‎nix/nixpkgs.nix‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
};
1818
in
1919
_final: _prev: {
20-
curl_8_6 = oldstable.curl;
2120
v8_oldstable = oldstable.v8;
2221
}
2322
)

‎nix/pgbouncer.nix‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
libevent,
77
c-ares,
88
pkg-config,
9-
systemd,
9+
systemdLibs,
1010
nixosTests,
1111
pandoc,
1212
python3,
@@ -31,7 +31,7 @@ stdenv.mkDerivation rec {
3131
openssl
3232
c-ares
3333
]
34-
++ lib.optional stdenv.hostPlatform.isLinux systemd;
34+
++ lib.optional stdenv.hostPlatform.isLinux systemdLibs;
3535
enableParallelBuilding = true;
3636
configureFlags = lib.optional stdenv.hostPlatform.isLinux "--with-systemd";
3737

‎nix/postgresql/generic.nix‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let
1515
icu75,
1616
lz4,
1717
zstd,
18-
systemd,
18+
systemdLibs,
1919
libossp_uuid,
2020
pkg-config,
2121
libxml2,
@@ -33,7 +33,8 @@ let
3333
libxslt,
3434

3535
# This is important to obtain a version of `libpq` that does not depend on systemd.
36-
systemdSupport ? lib.meta.availableOn stdenv.hostPlatform systemd && !stdenv.hostPlatform.isStatic,
36+
systemdSupport ?
37+
lib.meta.availableOn stdenv.hostPlatform systemdLibs && !stdenv.hostPlatform.isStatic,
3738
enableSystemd ? null,
3839
gssSupport ? with stdenv.hostPlatform; !isWindows && !isStatic,
3940

@@ -120,7 +121,7 @@ let
120121
++ lib.optionals (olderThan "13") [ libxcrypt ]
121122
++ lib.optionals lz4Enabled [ lz4 ]
122123
++ lib.optionals zstdEnabled [ zstd ]
123-
++ lib.optionals systemdSupport' [ systemd ]
124+
++ lib.optionals systemdSupport' [ systemdLibs ]
124125
++ lib.optionals pythonSupport [ python3 ]
125126
++ lib.optionals gssSupport [ libkrb5 ]
126127
++ lib.optionals stdenv.isLinux [ linux-pam ]

0 commit comments

Comments
 (0)