From 3f66a1749f074824ec3ab853944c9c57684b4e42 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sun, 3 Jul 2022 02:16:32 +0200 Subject: [PATCH 1/8] postgresql: Remove dev dependencies from closure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `pg_config` stores configure flags into the library/program for debugging or something. Since `PKG_CONFIG_PATH` somehow ends up in there, `dev` outputs of dependencies get pulled into the runtime closure. Let’s clear the paths in the variable to reduce the closure size. Reduces size of out: 287.8M → 236.5M --- pkgs/servers/sql/postgresql/default.nix | 27 +++++++++++++++++++ ...ve-refs-from-configure-flags-upto-12.patch | 13 +++++++++ .../remove-refs-from-configure-flags.patch | 13 +++++++++ 3 files changed, 53 insertions(+) create mode 100644 pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags-upto-12.patch create mode 100644 pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags.patch diff --git a/pkgs/servers/sql/postgresql/default.nix b/pkgs/servers/sql/postgresql/default.nix index ec2f95f5bd55b..44581e85c8611 100644 --- a/pkgs/servers/sql/postgresql/default.nix +++ b/pkgs/servers/sql/postgresql/default.nix @@ -3,6 +3,13 @@ let generic = # dependencies { stdenv, lib, fetchurl, makeWrapper, fetchpatch + , autoreconfHook269 + , perl + , docbook_xml_dtd_45 + , docbook_xml_dtd_42 + , libxslt + , docbook-xsl-nons + , runCommand , glibc, zlib, readline, openssl, icu, lz4, zstd, systemd, libossp_uuid , pkg-config, libxml2, tzdata, libkrb5, substituteAll, darwin @@ -68,6 +75,12 @@ let nativeBuildInputs = [ makeWrapper pkg-config + # We are patching configure.ac + autoreconfHook269 + perl + (if atLeast "13" then docbook_xml_dtd_45 else docbook_xml_dtd_42) + libxslt + docbook-xsl-nons ] ++ lib.optionals jitSupport [ llvmPackages.llvm.dev nukeReferences patchelf ]; @@ -111,6 +124,20 @@ let locale = "${if stdenv.isDarwin then darwin.adv_cmds else lib.getBin stdenv.cc.libc}/bin/locale"; }) + # Remove references to output paths from configure flags + # recorded in the software. + (if atLeast "14" then ./patches/remove-refs-from-configure-flags.patch + else if atLeast "13" then + runCommand + "remove-refs-from-configure-flags.patch" + { + patch = ./patches/remove-refs-from-configure-flags.patch; + } + '' + substitute "$patch" "$out" --replace "configure.ac" "configure.in" + '' + else ./patches/remove-refs-from-configure-flags-upto-12.patch) + ] ++ lib.optionals stdenv'.hostPlatform.isMusl ( let self = { diff --git a/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags-upto-12.patch b/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags-upto-12.patch new file mode 100644 index 0000000000000..0dbaa29f426b2 --- /dev/null +++ b/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags-upto-12.patch @@ -0,0 +1,13 @@ +--- a/src/Makefile.global.in ++++ b/src/Makefile.global.in +@@ -75,7 +75,7 @@ endif # not PGXS + vpathsearch = `for f in $(addsuffix /$(1),$(subst :, ,. $(VPATH))); do test -r $$f && echo $$f && break; done` + + # Saved arguments from configure +-configure_args = @configure_args@ ++configure_args = $(shell echo '@configure_args@' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g') + + + ########################################################################## +diff --git a/src/common/Makefile b/src/common/Makefile +index 873fbb6..b6476b4 100644 diff --git a/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags.patch b/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags.patch new file mode 100644 index 0000000000000..e16466be73ced --- /dev/null +++ b/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags.patch @@ -0,0 +1,13 @@ +diff --git a/configure.ac b/configure.ac +index 6c6f997..6e39e94 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -27,7 +27,7 @@ AC_COPYRIGHT([Copyright (c) 1996-2022, PostgreSQL Global Development Group]) + AC_CONFIG_SRCDIR([src/backend/access/common/heaptuple.c]) + AC_CONFIG_AUX_DIR(config) + AC_PREFIX_DEFAULT(/usr/local/pgsql) +-AC_DEFINE_UNQUOTED(CONFIGURE_ARGS, ["$ac_configure_args"], [Saved arguments from configure]) ++AC_DEFINE_UNQUOTED(CONFIGURE_ARGS, ["`echo "$ac_configure_args" | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g'`"], [Saved arguments from configure]) + + [PG_MAJORVERSION=`expr "$PACKAGE_VERSION" : '\([0-9][0-9]*\)'`] + [PG_MINORVERSION=`expr "$PACKAGE_VERSION" : '.*\.\([0-9][0-9]*\)'`] From cc2469cd2baf6ebd20d41a6c45c67d08cf0abf1b Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sun, 3 Jul 2022 02:46:25 +0200 Subject: [PATCH 2/8] postgresql: Remove more `dev` output references from closure No closure reduction this time since there are still more references. --- ...ve-refs-from-configure-flags-upto-12.patch | 23 +++++++++++++++++ .../remove-refs-from-configure-flags.patch | 25 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags-upto-12.patch b/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags-upto-12.patch index 0dbaa29f426b2..5ac6d8f39d37d 100644 --- a/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags-upto-12.patch +++ b/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags-upto-12.patch @@ -11,3 +11,26 @@ ########################################################################## diff --git a/src/common/Makefile b/src/common/Makefile index 873fbb6..b6476b4 100644 +--- a/src/common/Makefile ++++ b/src/common/Makefile +@@ -29,13 +29,13 @@ STD_CPPFLAGS := $(filter-out -I$(top_srcdir)/src/include -I$(top_builddir)/src/i + STD_LDFLAGS := $(filter-out -L$(top_builddir)/src/common -L$(top_builddir)/src/port,$(LDFLAGS)) + override CPPFLAGS += -DVAL_CONFIGURE="\"$(configure_args)\"" + override CPPFLAGS += -DVAL_CC="\"$(CC)\"" +-override CPPFLAGS += -DVAL_CPPFLAGS="\"$(STD_CPPFLAGS)\"" +-override CPPFLAGS += -DVAL_CFLAGS="\"$(CFLAGS)\"" +-override CPPFLAGS += -DVAL_CFLAGS_SL="\"$(CFLAGS_SL)\"" +-override CPPFLAGS += -DVAL_LDFLAGS="\"$(STD_LDFLAGS)\"" +-override CPPFLAGS += -DVAL_LDFLAGS_EX="\"$(LDFLAGS_EX)\"" +-override CPPFLAGS += -DVAL_LDFLAGS_SL="\"$(LDFLAGS_SL)\"" +-override CPPFLAGS += -DVAL_LIBS="\"$(LIBS)\"" ++override CPPFLAGS += -DVAL_CPPFLAGS="\"$(shell echo '$(STD_CPPFLAGS)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" ++override CPPFLAGS += -DVAL_CFLAGS="\"$(shell echo '$(CFLAGS)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" ++override CPPFLAGS += -DVAL_CFLAGS_SL="\"$(shell echo '$(CFLAGS_SL)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" ++override CPPFLAGS += -DVAL_LDFLAGS="\"$(shell echo '$(STD_LDFLAGS)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" ++override CPPFLAGS += -DVAL_LDFLAGS_EX="\"$(shell echo '$(LDFLAGS_EX)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" ++override CPPFLAGS += -DVAL_LDFLAGS_SL="\"$(shell echo '$(LDFLAGS_SL)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" ++override CPPFLAGS += -DVAL_LIBS="\"$(shell echo '$(LIBS)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" + + override CPPFLAGS := -DFRONTEND $(CPPFLAGS) + LIBS += $(PTHREAD_LIBS) diff --git a/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags.patch b/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags.patch index e16466be73ced..d83fa223e6c25 100644 --- a/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags.patch +++ b/pkgs/servers/sql/postgresql/patches/remove-refs-from-configure-flags.patch @@ -11,3 +11,28 @@ index 6c6f997..6e39e94 100644 [PG_MAJORVERSION=`expr "$PACKAGE_VERSION" : '\([0-9][0-9]*\)'`] [PG_MINORVERSION=`expr "$PACKAGE_VERSION" : '.*\.\([0-9][0-9]*\)'`] +diff --git a/src/common/Makefile b/src/common/Makefile +index e9af734..16fd6a1 100644 +--- a/src/common/Makefile ++++ b/src/common/Makefile +@@ -32,13 +32,13 @@ include $(top_builddir)/src/Makefile.global + STD_CPPFLAGS := $(filter-out -I$(top_srcdir)/src/include -I$(top_builddir)/src/include,$(CPPFLAGS)) + STD_LDFLAGS := $(filter-out -L$(top_builddir)/src/common -L$(top_builddir)/src/port,$(LDFLAGS)) + override CPPFLAGS += -DVAL_CC="\"$(CC)\"" +-override CPPFLAGS += -DVAL_CPPFLAGS="\"$(STD_CPPFLAGS)\"" +-override CPPFLAGS += -DVAL_CFLAGS="\"$(CFLAGS)\"" +-override CPPFLAGS += -DVAL_CFLAGS_SL="\"$(CFLAGS_SL)\"" +-override CPPFLAGS += -DVAL_LDFLAGS="\"$(STD_LDFLAGS)\"" +-override CPPFLAGS += -DVAL_LDFLAGS_EX="\"$(LDFLAGS_EX)\"" +-override CPPFLAGS += -DVAL_LDFLAGS_SL="\"$(LDFLAGS_SL)\"" +-override CPPFLAGS += -DVAL_LIBS="\"$(LIBS)\"" ++override CPPFLAGS += -DVAL_CPPFLAGS="\"$(shell echo '$(STD_CPPFLAGS)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" ++override CPPFLAGS += -DVAL_CFLAGS="\"$(shell echo '$(CFLAGS)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" ++override CPPFLAGS += -DVAL_CFLAGS_SL="\"$(shell echo '$(CFLAGS_SL)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" ++override CPPFLAGS += -DVAL_LDFLAGS="\"$(shell echo '$(STD_LDFLAGS)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" ++override CPPFLAGS += -DVAL_LDFLAGS_EX="\"$(shell echo '$(LDFLAGS_EX)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" ++override CPPFLAGS += -DVAL_LDFLAGS_SL="\"$(shell echo '$(LDFLAGS_SL)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" ++override CPPFLAGS += -DVAL_LIBS="\"$(shell echo '$(LIBS)' | sed -E 's~/nix/store/.{32}-~/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-~g')\"" + + override CPPFLAGS := -DFRONTEND -I. -I$(top_srcdir)/src/common $(CPPFLAGS) + LIBS += $(PTHREAD_LIBS) From c271f395daeb06f3acb6d22033e8d85ed5f402bf Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 9 Dec 2023 20:00:23 +0100 Subject: [PATCH 3/8] treewide: prepare for pg_config moving to dev --- doc/languages-frameworks/ruby.section.md | 8 +++----- pkgs/applications/networking/misc/zammad/default.nix | 2 +- pkgs/development/python-modules/psycopg2/default.nix | 2 +- pkgs/development/ruby-modules/gem-config/default.nix | 2 +- .../tools/rust/cargo-pgrx/buildPgrxExtension.nix | 4 ++-- .../tools/rust/cargo-pgx/buildPgxExtension.nix | 4 ++-- pkgs/tools/networking/kea/default.nix | 2 +- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/doc/languages-frameworks/ruby.section.md b/doc/languages-frameworks/ruby.section.md index 920c84eee689c..60e531e54bfb6 100644 --- a/doc/languages-frameworks/ruby.section.md +++ b/doc/languages-frameworks/ruby.section.md @@ -152,7 +152,7 @@ let defaultGemConfig = pkgs.defaultGemConfig // { pg = attrs: { buildFlags = - [ "--with-pg-config=${pkgs."postgresql_${pg_version}"}/bin/pg_config" ]; + [ "--with-pg-config=${lib.getDev pkgs."postgresql_${pg_version}"}/bin/pg_config" ]; }; }; }; @@ -170,7 +170,7 @@ let gemConfig = pkgs.defaultGemConfig // { pg = attrs: { buildFlags = - [ "--with-pg-config=${pkgs."postgresql_${pg_version}"}/bin/pg_config" ]; + [ "--with-pg-config=${lib.getDev pkgs."postgresql_${pg_version}"}/bin/pg_config" ]; }; }; }; @@ -188,9 +188,7 @@ let defaultGemConfig = super.defaultGemConfig // { pg = attrs: { buildFlags = [ - "--with-pg-config=${ - pkgs."postgresql_${pg_version}" - }/bin/pg_config" + "--with-pg-config=${lib.getDev pkgs."postgresql_${pg_version}"}/bin/pg_config" ]; }; }; diff --git a/pkgs/applications/networking/misc/zammad/default.nix b/pkgs/applications/networking/misc/zammad/default.nix index b69f90d321a48..ba90abc3a1654 100644 --- a/pkgs/applications/networking/misc/zammad/default.nix +++ b/pkgs/applications/networking/misc/zammad/default.nix @@ -74,7 +74,7 @@ let ]; gemConfig = defaultGemConfig // { pg = attrs: { - buildFlags = [ "--with-pg-config=${postgresql}/bin/pg_config" ]; + buildFlags = [ "--with-pg-config=${lib.getDev postgresql}/bin/pg_config" ]; }; rszr = attrs: { buildInputs = [ imlib2 imlib2.dev ]; diff --git a/pkgs/development/python-modules/psycopg2/default.nix b/pkgs/development/python-modules/psycopg2/default.nix index 43a06e5a9e4d4..794d5b0f44282 100644 --- a/pkgs/development/python-modules/psycopg2/default.nix +++ b/pkgs/development/python-modules/psycopg2/default.nix @@ -32,7 +32,7 @@ buildPythonPackage rec { # some linker flags are added but the linker ignores them because they're incompatible # https://github.com/psycopg/psycopg2/blob/89005ac5b849c6428c05660b23c5a266c96e677d/setup.py substituteInPlace setup.py \ - --replace "self.pg_config_exe = self.build_ext.pg_config" 'self.pg_config_exe = "${lib.getExe' buildPackages.postgresql "pg_config"}"' + --replace "self.pg_config_exe = self.build_ext.pg_config" 'self.pg_config_exe = "${lib.getDev buildPackages.postgresql}/bin/pg_config"' ''; nativeBuildInputs = [ diff --git a/pkgs/development/ruby-modules/gem-config/default.nix b/pkgs/development/ruby-modules/gem-config/default.nix index 5a3ec1f684694..ec2028996cb43 100644 --- a/pkgs/development/ruby-modules/gem-config/default.nix +++ b/pkgs/development/ruby-modules/gem-config/default.nix @@ -624,7 +624,7 @@ in # Force pkg-config lookup for libpq. # See https://github.com/ged/ruby-pg/blob/6629dec6656f7ca27619e4675b45225d9e422112/ext/extconf.rb#L34-L55 # - # Note that setting --with-pg-config=${postgresql}/bin/pg_config would add + # Note that setting --with-pg-config=${lib.getDev postgresql}/bin/pg_config would add # an unnecessary reference to the entire postgresql package. buildFlags = [ "--with-pg-config=ignore" ]; nativeBuildInputs = [ pkg-config ]; diff --git a/pkgs/development/tools/rust/cargo-pgrx/buildPgrxExtension.nix b/pkgs/development/tools/rust/cargo-pgrx/buildPgrxExtension.nix index 6aae84d3463bc..fbfe10d45efba 100644 --- a/pkgs/development/tools/rust/cargo-pgrx/buildPgrxExtension.nix +++ b/pkgs/development/tools/rust/cargo-pgrx/buildPgrxExtension.nix @@ -86,7 +86,7 @@ let preBuildAndTest = '' export PGRX_HOME=$(mktemp -d) export PGDATA="$PGRX_HOME/data-${pgrxPostgresMajor}/" - cargo-pgrx pgrx init "--pg${pgrxPostgresMajor}" ${postgresql}/bin/pg_config + cargo-pgrx pgrx init "--pg${pgrxPostgresMajor}" ${lib.getDev postgresql}/bin/pg_config echo "unix_socket_directories = '$(mktemp -d)'" > "$PGDATA/postgresql.conf" # This is primarily for Mac or other Nix systems that don't use the nixbld user. @@ -120,7 +120,7 @@ let NIX_PGLIBDIR="${postgresql}/lib" \ PGRX_BUILD_FLAGS="--frozen -j $NIX_BUILD_CORES ${builtins.concatStringsSep " " cargoBuildFlags}" \ cargo-pgrx pgrx package \ - --pg-config ${postgresql}/bin/pg_config \ + --pg-config ${lib.getDev postgresql}/bin/pg_config \ ${maybeDebugFlag} \ --features "${builtins.concatStringsSep " " buildFeatures}" \ --out-dir "$out" diff --git a/pkgs/development/tools/rust/cargo-pgx/buildPgxExtension.nix b/pkgs/development/tools/rust/cargo-pgx/buildPgxExtension.nix index 4b4f7f9d7486b..4e71ddb93fad3 100644 --- a/pkgs/development/tools/rust/cargo-pgx/buildPgxExtension.nix +++ b/pkgs/development/tools/rust/cargo-pgx/buildPgxExtension.nix @@ -86,7 +86,7 @@ let preBuildAndTest = '' export PGX_HOME=$(mktemp -d) export PGDATA="$PGX_HOME/data-${pgxPostgresMajor}/" - cargo-pgx pgx init "--pg${pgxPostgresMajor}" ${postgresql}/bin/pg_config + cargo-pgx pgx init "--pg${pgxPostgresMajor}" ${lib.getDev postgresql}/bin/pg_config echo "unix_socket_directories = '$(mktemp -d)'" > "$PGDATA/postgresql.conf" # This is primarily for Mac or other Nix systems that don't use the nixbld user. @@ -120,7 +120,7 @@ let NIX_PGLIBDIR="${postgresql}/lib" \ PGX_BUILD_FLAGS="--frozen -j $NIX_BUILD_CORES ${builtins.concatStringsSep " " cargoBuildFlags}" \ cargo-pgx pgx package \ - --pg-config ${postgresql}/bin/pg_config \ + --pg-config ${lib.getDev postgresql}/bin/pg_config \ ${maybeDebugFlag} \ --features "${builtins.concatStringsSep " " buildFeatures}" \ --out-dir "$out" diff --git a/pkgs/tools/networking/kea/default.nix b/pkgs/tools/networking/kea/default.nix index 574afb68e2372..e9d9c2b6de140 100644 --- a/pkgs/tools/networking/kea/default.nix +++ b/pkgs/tools/networking/kea/default.nix @@ -52,7 +52,7 @@ stdenv.mkDerivation rec { "--localstatedir=/var" "--with-openssl=${lib.getDev openssl}" ] - ++ lib.optional withPostgres "--with-pgsql=${postgresql}/bin/pg_config" + ++ lib.optional withPostgres "--with-pgsql=${lib.getDev postgresql}/bin/pg_config" ++ lib.optional withMysql "--with-mysql=${lib.getDev libmysqlclient}/bin/mysql_config"; postConfigure = '' From 3333c69390e2628e5cc9fba08849150d99c61155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Fri, 1 Sep 2023 16:22:08 +0200 Subject: [PATCH 4/8] python310Packages.psycopg: prepare for pg_config moving to dev --- pkgs/development/python-modules/psycopg/default.nix | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkgs/development/python-modules/psycopg/default.nix b/pkgs/development/python-modules/psycopg/default.nix index b73c74ca0ae36..412e33a945ebb 100644 --- a/pkgs/development/python-modules/psycopg/default.nix +++ b/pkgs/development/python-modules/psycopg/default.nix @@ -82,11 +82,18 @@ let nativeBuildInputs = [ cython_3 + # needed to find pg_config with strictDeps + # TODO: switch to pkg-config upstream + # https://github.com/psycopg/psycopg2/issues/1001 postgresql setuptools tomli ]; + buildInputs = [ + postgresql + ]; + # tested in psycopg doCheck = false; @@ -181,7 +188,7 @@ buildPythonPackage rec { pytestCheckHook postgresql ] - ++ lib.optional (stdenv.isLinux) postgresqlTestHook + ++ lib.optional stdenv.isLinux postgresqlTestHook ++ passthru.optional-dependencies.c ++ passthru.optional-dependencies.pool; @@ -193,7 +200,7 @@ buildPythonPackage rec { preCheck = '' cd .. - '' + lib.optionalString (stdenv.isLinux) '' + '' + lib.optionalString stdenv.isLinux '' export PSYCOPG_TEST_DSN="host=/build/run/postgresql user=$PGUSER" ''; From 716f239a2ae1bb1f2f3bdf5cbbe9306960d47e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Fri, 1 Sep 2023 16:23:08 +0200 Subject: [PATCH 5/8] python310Packages.psycopg2cffi: prepare for pg_config moving to dev --- .../python-modules/psycopg2cffi/default.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkgs/development/python-modules/psycopg2cffi/default.nix b/pkgs/development/python-modules/psycopg2cffi/default.nix index a504c8484ab24..1d2ee52dd6825 100644 --- a/pkgs/development/python-modules/psycopg2cffi/default.nix +++ b/pkgs/development/python-modules/psycopg2cffi/default.nix @@ -20,7 +20,17 @@ buildPythonPackage rec { sha256 = "09hsnjkix1c0vlhmfvrp8pchpnz2ya4xrchyq15czj527nx2dmy2"; }; - nativeBuildInputs = [ postgresql ]; + nativeBuildInputs = [ + # needed to find pg_config with strictDeps + # TODO: switch to pkg-config upstream + # https://github.com/psycopg/psycopg2/issues/1001 + postgresql + ]; + + buildInputs = [ + postgresql + ]; + propagatedBuildInputs = [ six cffi ]; nativeCheckInputs = [ pytestCheckHook ]; From 2cd0977d3d360e71d3f3e7d2fdeca337cfde087d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 2 Sep 2023 15:51:43 +0200 Subject: [PATCH 6/8] php82Packages.pdo_psql: prepare for pg_config moving to dev --- pkgs/top-level/php-packages.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/top-level/php-packages.nix b/pkgs/top-level/php-packages.nix index cda91b8c627b4..bd992e56964a5 100644 --- a/pkgs/top-level/php-packages.nix +++ b/pkgs/top-level/php-packages.nix @@ -530,7 +530,7 @@ lib.makeScope pkgs.newScope (self: with self; { { name = "pdo_pgsql"; internalDeps = [ php.extensions.pdo ]; - configureFlags = [ "--with-pdo-pgsql=${postgresql}" ]; + configureFlags = [ "--with-pdo-pgsql=${lib.getDev postgresql}" ]; doCheck = false; } { From dff2bb7cfa411836bbd3f2a345583a83ad59d672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Sat, 2 Sep 2023 16:45:30 +0200 Subject: [PATCH 7/8] php82Packages.psql: prepare for pg_config moving to dev --- pkgs/top-level/php-packages.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/top-level/php-packages.nix b/pkgs/top-level/php-packages.nix index bd992e56964a5..f96698356ef1e 100644 --- a/pkgs/top-level/php-packages.nix +++ b/pkgs/top-level/php-packages.nix @@ -543,7 +543,7 @@ lib.makeScope pkgs.newScope (self: with self; { { name = "pgsql"; buildInputs = [ pcre2 ]; - configureFlags = [ "--with-pgsql=${postgresql}" ]; + configureFlags = [ "--with-pgsql=${lib.getDev postgresql}" ]; doCheck = false; } { name = "posix"; doCheck = false; } From 8f215822a179612ea81c6aa7096f22436a4a78a8 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sun, 3 Jul 2022 02:59:26 +0200 Subject: [PATCH 8/8] postgresql: Split out dev output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The package contains some files only necessary for linking other software against PgSQL’s libraries. Those files include compiler flags that reference `dev` outputs of other libraries, unnecessarily increasing the runtime closure. Let’s move those files to a `dev` output, reducing the runtime closure of `out`. We also need to clear out some paths hardcoded into the libs to avoid a dependency cycle between the `dev` and `out` outputs. This includes the path to PGXS files for the `libpgcommon` and `postgres` server (used e.g. by `SELECT pg_config()` query); we restore the path explicitly for `pg_config` program. The `out` output will be the root of the graph. This further reduces the closure size of out from 236.5M to 235.5M. --- pkgs/servers/sql/postgresql/default.nix | 23 ++++-- .../patches/hardcode-pg_config-paths.patch | 70 +++++++++++++++++++ .../patches/hardcode-pgxs-path.patch | 14 ---- .../patches/prevent-output-cycle.patch | 17 +++++ 4 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 pkgs/servers/sql/postgresql/patches/hardcode-pg_config-paths.patch delete mode 100644 pkgs/servers/sql/postgresql/patches/hardcode-pgxs-path.patch create mode 100644 pkgs/servers/sql/postgresql/patches/prevent-output-cycle.patch diff --git a/pkgs/servers/sql/postgresql/default.nix b/pkgs/servers/sql/postgresql/default.nix index 44581e85c8611..46b7e115c8a2a 100644 --- a/pkgs/servers/sql/postgresql/default.nix +++ b/pkgs/servers/sql/postgresql/default.nix @@ -54,8 +54,7 @@ let hardeningEnable = lib.optionals (!stdenv'.cc.isClang) [ "pie" ]; - outputs = [ "out" "lib" "doc" "man" ]; - setOutputFlags = false; # $out retains configureFlags :-/ + outputs = [ "out" "dev" "lib" "doc" "man" ]; buildInputs = [ zlib @@ -100,7 +99,6 @@ let "--with-libxml" "--with-icu" "--sysconfdir=/etc" - "--libdir=$(lib)/lib" "--with-system-tzdata=${tzdata}/share/zoneinfo" "--enable-debug" (lib.optionalString enableSystemd "--with-systemd") @@ -115,7 +113,12 @@ let (if atLeast "16" then ./patches/disable-normalize_exec_path.patch else ./patches/disable-resolve_symlinks.patch) ./patches/less-is-more.patch - ./patches/hardcode-pgxs-path.patch + + # Hardcode the path to pgxs and other dirs so that pg_config returns the path in the package, + # rather than one relative to the location pg_config was executed in. + # The placeholders are resolved in postPatch. + ./patches/hardcode-pg_config-paths.patch + ./patches/specify_pkglibdir_at_runtime.patch ./patches/findstring.patch @@ -138,6 +141,9 @@ let '' else ./patches/remove-refs-from-configure-flags-upto-12.patch) + # Patch out includedir path references in libraries and programs. + ./patches/prevent-output-cycle.patch + ] ++ lib.optionals stdenv'.hostPlatform.isMusl ( let self = { @@ -190,8 +196,9 @@ let LC_ALL = "C"; postPatch = '' - # Hardcode the path to pgxs so pg_config returns the path in $out - substituteInPlace "src/common/config_info.c" --replace HARDCODED_PGXS_PATH "$out/lib" + # Substitute placeholders from hardcode-pg_config-paths.patch + substituteInPlace "src/common/config_info.c" --subst-var out + substituteInPlace "src/bin/pg_config/pg_config.c" --subst-var dev '' + lib.optionalString jitSupport '' # Force lookup of jit stuff in $out instead of $lib substituteInPlace src/backend/jit/jit.c --replace pkglib_path \"$out/lib\" @@ -205,9 +212,11 @@ let moveToOutput "lib/libpgcommon*.a" "$out" moveToOutput "lib/libpgport*.a" "$out" moveToOutput "lib/libecpg*" "$out" + moveToOutput "bin/pg_config" "$dev" + moveToOutput "lib/pgxs" "$dev" # Prevent a retained dependency on gcc-wrapper. - substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/ld ld + substituteInPlace "$dev/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/ld ld if [ -z "''${dontDisableStatic:-}" ]; then # Remove static libraries in case dynamic are available. diff --git a/pkgs/servers/sql/postgresql/patches/hardcode-pg_config-paths.patch b/pkgs/servers/sql/postgresql/patches/hardcode-pg_config-paths.patch new file mode 100644 index 0000000000000..d7ec0009c9848 --- /dev/null +++ b/pkgs/servers/sql/postgresql/patches/hardcode-pg_config-paths.patch @@ -0,0 +1,70 @@ +diff --git a/src/bin/pg_config/pg_config.c b/src/bin/pg_config/pg_config.c +index 62b97af..e5b71e5 100644 +--- a/src/bin/pg_config/pg_config.c ++++ b/src/bin/pg_config/pg_config.c +@@ -112,6 +112,11 @@ advice(void) + fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); + } + ++static char* ++get_config_val(ConfigData configdata) { ++ return strcmp(configdata.name, "PGXS") == 0 ? "@dev@/lib/pgxs/src/makefiles/pgxs.mk" : configdata.setting; ++} ++ + static void + show_item(const char *configname, + ConfigData *configdata, +@@ -122,7 +127,7 @@ show_item(const char *configname, + for (i = 0; i < configdata_len; i++) + { + if (strcmp(configname, configdata[i].name) == 0) +- printf("%s\n", configdata[i].setting); ++ printf("%s\n", get_config_val(configdata[i])); + } + } + +@@ -160,7 +165,7 @@ main(int argc, char **argv) + if (argc < 2) + { + for (i = 0; i < configdata_len; i++) +- printf("%s = %s\n", configdata[i].name, configdata[i].setting); ++ printf("%s = %s\n", configdata[i].name, get_config_val(configdata[i])); + exit(0); + } + +diff --git a/src/common/config_info.c b/src/common/config_info.c +index aa643b6..3750c14 100644 +--- a/src/common/config_info.c ++++ b/src/common/config_info.c +@@ -42,11 +42,7 @@ get_configdata(const char *my_exec_path, size_t *configdata_len) + configdata = (ConfigData *) palloc(*configdata_len * sizeof(ConfigData)); + + configdata[i].name = pstrdup("BINDIR"); +- strlcpy(path, my_exec_path, sizeof(path)); +- lastsep = strrchr(path, '/'); +- if (lastsep) +- *lastsep = '\0'; +- cleanup_path(path); ++ strlcpy(path, "@out@/bin", sizeof(path)); + configdata[i].setting = pstrdup(path); + i++; + +@@ -105,8 +101,7 @@ get_configdata(const char *my_exec_path, size_t *configdata_len) + i++; + + configdata[i].name = pstrdup("SHAREDIR"); +- get_share_path(my_exec_path, path); +- cleanup_path(path); ++ strlcpy(path, "@out@/share", sizeof(path)); + configdata[i].setting = pstrdup(path); + i++; + +@@ -117,7 +112,7 @@ get_configdata(const char *my_exec_path, size_t *configdata_len) + i++; + + configdata[i].name = pstrdup("PGXS"); +- get_pkglib_path(my_exec_path, path); ++ strlcpy(path, "/dev/null", sizeof(path)); + strlcat(path, "/pgxs/src/makefiles/pgxs.mk", sizeof(path)); + cleanup_path(path); + configdata[i].setting = pstrdup(path); diff --git a/pkgs/servers/sql/postgresql/patches/hardcode-pgxs-path.patch b/pkgs/servers/sql/postgresql/patches/hardcode-pgxs-path.patch deleted file mode 100644 index 6cd449769baac..0000000000000 --- a/pkgs/servers/sql/postgresql/patches/hardcode-pgxs-path.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff -Naur postgresql-9.6.1-orig/src/common/config_info.c postgresql-9.6.1/src/common/config_info.c ---- postgresql-9.6.1-orig/src/common/config_info.c 2016-11-22 21:39:29.231929261 +0100 -+++ postgresql-9.6.1/src/common/config_info.c 2016-11-22 23:36:53.685163543 +0100 -@@ -118,7 +118,10 @@ - i++; - - configdata[i].name = pstrdup("PGXS"); -+ strlcpy(path, "HARDCODED_PGXS_PATH", sizeof(path)); -+/* commented out to be able to point to nix $out path - get_pkglib_path(my_exec_path, path); -+*/ - strlcat(path, "/pgxs/src/makefiles/pgxs.mk", sizeof(path)); - cleanup_path(path); - configdata[i].setting = pstrdup(path); diff --git a/pkgs/servers/sql/postgresql/patches/prevent-output-cycle.patch b/pkgs/servers/sql/postgresql/patches/prevent-output-cycle.patch new file mode 100644 index 0000000000000..972dac1c4da77 --- /dev/null +++ b/pkgs/servers/sql/postgresql/patches/prevent-output-cycle.patch @@ -0,0 +1,17 @@ +diff --git a/src/port/Makefile b/src/port/Makefile +index bfe1feb..1f9f0d3 100644 +--- a/src/port/Makefile ++++ b/src/port/Makefile +@@ -152,9 +152,9 @@ pg_config_paths.h: $(top_builddir)/src/Makefile.global + echo "#define PGBINDIR \"$(bindir)\"" >$@ + echo "#define PGSHAREDIR \"$(datadir)\"" >>$@ + echo "#define SYSCONFDIR \"$(sysconfdir)\"" >>$@ +- echo "#define INCLUDEDIR \"$(includedir)\"" >>$@ +- echo "#define PKGINCLUDEDIR \"$(pkgincludedir)\"" >>$@ +- echo "#define INCLUDEDIRSERVER \"$(includedir_server)\"" >>$@ ++ echo "#define INCLUDEDIR \"/dev/null/include\"" >>$@ ++ echo "#define PKGINCLUDEDIR \"/dev/null/include\"" >>$@ ++ echo "#define INCLUDEDIRSERVER \"/dev/null/include/server\"" >>$@ + echo "#define LIBDIR \"$(libdir)\"" >>$@ + echo "#define PKGLIBDIR \"$(pkglibdir)\"" >>$@ + echo "#define LOCALEDIR \"$(localedir)\"" >>$@