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.
This commit is contained in:
Wolfgang Walther 2025-02-28 15:47:12 +01:00
parent 310ec25e98
commit 527713c1db
No known key found for this signature in database
GPG Key ID: B39893FA5F65CAE1
4 changed files with 76 additions and 4 deletions

View File

@ -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.

View File

@ -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)";
}

View File

@ -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 (_: [ ])

View File

@ -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';