From 310ec25e98407fa6c9cb38c74df0ed7d3850b9be Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Fri, 28 Feb 2025 15:44:47 +0100 Subject: [PATCH] postgresql: provide plperl extension as package This allows us to always build the extension, but still have the user explicitly enable it without causing rebuilds. --- doc/release-notes/rl-2505.section.md | 2 +- pkgs/servers/sql/postgresql/ext.nix | 3 ++ pkgs/servers/sql/postgresql/ext/plperl.nix | 45 ++++++++++++++++++++++ pkgs/servers/sql/postgresql/generic.nix | 31 ++++++++++----- 4 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 pkgs/servers/sql/postgresql/ext/plperl.nix diff --git a/doc/release-notes/rl-2505.section.md b/doc/release-notes/rl-2505.section.md index 8f7a2e2babfb..d37733131e53 100644 --- a/doc/release-notes/rl-2505.section.md +++ b/doc/release-notes/rl-2505.section.md @@ -25,7 +25,7 @@ The `nixLog` function, which logs unconditionally, was also re-introduced and modified to prefix messages with the function name of the caller. For more information, [see this PR](https://github.com/NixOS/nixpkgs/pull/370742). -- `postgresql`'s `pythonSupport` argument has been changed. It is now enabled by default, but to use PL/Python the extension needs to be added explicitly with `postgresql.withPackages`. If you were using `postgresql.override { pythonSupport = true; }` before, change it to `postgresql.withPackages (ps: [ ps.plpython3 ])`. +- `postgresql`'s `pythonSupport` argument has been changed. It is now enabled by default, but to use PL/Python the extension needs to be added explicitly with `postgresql.withPackages`. If you were using `postgresql.override { pythonSupport = true; }` before, change it to `postgresql.withPackages (ps: [ ps.plpython3 ])`. The same applies to `perlSupport`/`plperl` respectively. - The `rustPlatform.fetchCargoTarball` function is deprecated, because it relied on `cargo vendor` not changing its output format to keep fixed-output derivation hashes the same, which is a Nix invariant, and Cargo 1.84.0 changed `cargo vendor`'s output format. It should generally be replaced with `rustPlatform.fetchCargoVendor`, but `rustPlatform.importCargoLock` may also be appropriate in some circumstances. diff --git a/pkgs/servers/sql/postgresql/ext.nix b/pkgs/servers/sql/postgresql/ext.nix index 9ec29ea3eb10..c10d9ac7bbd6 100644 --- a/pkgs/servers/sql/postgresql/ext.nix +++ b/pkgs/servers/sql/postgresql/ext.nix @@ -9,6 +9,9 @@ in // { timescaledb-apache = super.callPackage ./ext/timescaledb.nix { enableUnfree = false; }; } +// lib.optionalAttrs (!self.perlSupport) { + plperl = throw "PostgreSQL extension `plperl` is not available, because `postgresql` was built without Perl support. Override with `perlSupport = true` to enable the extension."; +} // lib.optionalAttrs (!self.pythonSupport) { plpython3 = throw "PostgreSQL extension `plpython3` is not available, because `postgresql` was built without Python support. Override with `pythonSupport = true` to enable the extension."; } diff --git a/pkgs/servers/sql/postgresql/ext/plperl.nix b/pkgs/servers/sql/postgresql/ext/plperl.nix new file mode 100644 index 000000000000..dea85d23ece8 --- /dev/null +++ b/pkgs/servers/sql/postgresql/ext/plperl.nix @@ -0,0 +1,45 @@ +{ + buildEnv, + perl, + postgresql, + postgresqlTestExtension, +}: + +let + withPackages = + f: + let + perl' = perl.withPackages f; + finalPackage = buildEnv { + name = "${postgresql.pname}-plperl-${postgresql.version}"; + paths = [ postgresql.plperl ]; + passthru = { + inherit withPackages; + wrapperArgs = [ + ''--set PERL5LIB "${perl'}/${perl'.libPrefix}"'' + ]; + tests.extension = postgresqlTestExtension { + finalPackage = finalPackage.withPackages (ps: [ ps.boolean ]); + sql = '' + CREATE EXTENSION plperlu; + DO LANGUAGE plperlu $$ + use boolean; + $$; + ''; + }; + }; + meta = { + inherit (postgresql.meta) + homepage + license + changelog + maintainers + platforms + ; + description = "PL/Perl - Perl Procedural Language"; + }; + }; + in + finalPackage; +in +withPackages (_: [ ]) diff --git a/pkgs/servers/sql/postgresql/generic.nix b/pkgs/servers/sql/postgresql/generic.nix index 91c952215857..c8251dce3495 100644 --- a/pkgs/servers/sql/postgresql/generic.nix +++ b/pkgs/servers/sql/postgresql/generic.nix @@ -89,7 +89,13 @@ let linux-pam, # PL/Perl - perlSupport ? false, + perlSupport ? + lib.meta.availableOn stdenv.hostPlatform perl + # Building with perl in pkgsStatic gives this error: + # configure: error: cannot build PL/Perl because libperl is not a shared library + && !stdenv.hostPlatform.isStatic + # configure tries to call the perl executable for the version + && stdenv.buildPlatform.canExecute stdenv.hostPlatform, perl, # PL/Python @@ -153,13 +159,16 @@ let hardeningEnable = lib.optionals (!stdenv'.cc.isClang) [ "pie" ]; - outputs = [ - "out" - "dev" - "doc" - "lib" - "man" - ] ++ lib.optionals pythonSupport [ "plpython3" ]; + outputs = + [ + "out" + "dev" + "doc" + "lib" + "man" + ] + ++ lib.optionals perlSupport [ "plperl" ] + ++ lib.optionals pythonSupport [ "plpython3" ]; outputChecks = { out = { disallowedReferences = [ @@ -406,6 +415,10 @@ let substituteInPlace "$dev/lib/pgxs/src/Makefile.port" \ --replace-fail '-bundle_loader $(bindir)/postgres' "-bundle_loader $out/bin/postgres" '' + + lib.optionalString perlSupport '' + moveToOutput "lib/*plperl*" "$plperl" + moveToOutput "share/postgresql/extension/*plperl*" "$plperl" + '' + lib.optionalString pythonSupport '' moveToOutput "lib/*plpython3*" "$plpython3" moveToOutput "share/postgresql/extension/*plpython3*" "$plpython3" @@ -449,7 +462,7 @@ let pkgs = let scope = { - inherit jitSupport pythonSupport; + inherit jitSupport pythonSupport perlSupport; inherit (llvmPackages) llvm; postgresql = this; stdenv = stdenv';