From 527713c1dbacf9a58a2a3ba78f3dda2ffe4f0a4b Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Fri, 28 Feb 2025 15:47:12 +0100 Subject: [PATCH] postgresql: provide pltcl 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/pltcl.nix | 53 +++++++++++++++++++++++ pkgs/servers/sql/postgresql/generic.nix | 22 ++++++++-- 4 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 pkgs/servers/sql/postgresql/ext/pltcl.nix diff --git a/doc/release-notes/rl-2505.section.md b/doc/release-notes/rl-2505.section.md index d37733131e53..ab0880093666 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 ])`. The same applies to `perlSupport`/`plperl` respectively. +- `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` and `tclSupport`/`pltcl` 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 c10d9ac7bbd6..0fe5c4b5e734 100644 --- a/pkgs/servers/sql/postgresql/ext.nix +++ b/pkgs/servers/sql/postgresql/ext.nix @@ -15,6 +15,9 @@ in // 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."; } +// lib.optionalAttrs (!self.tclSupport) { + pltcl = throw "PostgreSQL extension `pltcl` is not available, because `postgresql` was built without Tcl support. Override with `tclSupport = true` to enable the extension."; +} // lib.optionalAttrs config.allowAliases { pg_embedding = throw "PostgreSQL extension `pg_embedding` has been removed since the project has been abandoned. Upstream's recommendation is to use pgvector instead (https://neon.tech/docs/extensions/pg_embedding#migrate-from-pg_embedding-to-pgvector)"; } diff --git a/pkgs/servers/sql/postgresql/ext/pltcl.nix b/pkgs/servers/sql/postgresql/ext/pltcl.nix new file mode 100644 index 000000000000..7b0364bb8926 --- /dev/null +++ b/pkgs/servers/sql/postgresql/ext/pltcl.nix @@ -0,0 +1,53 @@ +{ + buildEnv, + lib, + postgresql, + postgresqlTestExtension, + tcl, + tclPackages, +}: + +let + withPackages = + f: + let + pkgs = f tclPackages; + paths = lib.concatMapStringsSep " " (pkg: "${pkg}/lib") pkgs; + finalPackage = buildEnv { + name = "${postgresql.pname}-pltcl-${postgresql.version}"; + paths = [ postgresql.pltcl ]; + passthru = { + inherit withPackages; + wrapperArgs = [ + ''--set TCLLIBPATH "${paths}"'' + ]; + tests.extension = postgresqlTestExtension { + finalPackage = finalPackage.withPackages (ps: [ + ps.mustache-tcl + ps.tcllib + ]); + sql = '' + CREATE EXTENSION pltclu; + CREATE FUNCTION test() RETURNS VOID + LANGUAGE pltclu AS $$ + package require mustache + $$; + SELECT test(); + ''; + }; + }; + meta = { + inherit (postgresql.meta) + homepage + license + changelog + maintainers + platforms + ; + description = "PL/Tcl - Tcl Procedural Language"; + }; + }; + in + finalPackage; +in +withPackages (_: [ ]) diff --git a/pkgs/servers/sql/postgresql/generic.nix b/pkgs/servers/sql/postgresql/generic.nix index c8251dce3495..f0c7b69e7088 100644 --- a/pkgs/servers/sql/postgresql/generic.nix +++ b/pkgs/servers/sql/postgresql/generic.nix @@ -109,7 +109,13 @@ let python3, # PL/Tcl - tclSupport ? false, + tclSupport ? + lib.meta.availableOn stdenv.hostPlatform tcl + # tcl is broken in pkgsStatic + && !stdenv.hostPlatform.isStatic + # configure fails with: + # configure: error: file 'tclConfig.sh' is required for Tcl + && stdenv.buildPlatform.canExecute stdenv.hostPlatform, tcl, # SELinux @@ -168,7 +174,8 @@ let "man" ] ++ lib.optionals perlSupport [ "plperl" ] - ++ lib.optionals pythonSupport [ "plpython3" ]; + ++ lib.optionals pythonSupport [ "plpython3" ] + ++ lib.optionals tclSupport [ "pltcl" ]; outputChecks = { out = { disallowedReferences = [ @@ -422,6 +429,10 @@ let + lib.optionalString pythonSupport '' moveToOutput "lib/*plpython3*" "$plpython3" moveToOutput "share/postgresql/extension/*plpython3*" "$plpython3" + '' + + lib.optionalString tclSupport '' + moveToOutput "lib/*pltcl*" "$pltcl" + moveToOutput "share/postgresql/extension/*pltcl*" "$pltcl" ''; postFixup = lib.optionalString stdenv'.hostPlatform.isGnu '' @@ -462,7 +473,12 @@ let pkgs = let scope = { - inherit jitSupport pythonSupport perlSupport; + inherit + jitSupport + pythonSupport + perlSupport + tclSupport + ; inherit (llvmPackages) llvm; postgresql = this; stdenv = stdenv';