push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import ./generic.nix {
version = "13.22";
rev = "refs/tags/REL_13_22";
hash = "sha256-6zHA+WU1FroUbGJcTAeEbPKBVQY7SKpT5+Kxe9ZhtoM=";
muslPatches = {
disable-test-collate-icu-utf8 = {
url = "https://git.alpinelinux.org/aports/plain/main/postgresql13/disable-test-collate.icu.utf8.patch?id=69faa146ec9fff3b981511068f17f9e629d4688b";
hash = "sha256-jS/qxezaiaKhkWeMCXwpz1SDJwUWn9tzN0uKaZ3Ph2Y=";
};
dont-use-locale-a = {
url = "https://git.alpinelinux.org/aports/plain/main/postgresql13/dont-use-locale-a-on-musl.patch?id=69faa146ec9fff3b981511068f17f9e629d4688b";
hash = "sha256-fk+y/SvyA4Tt8OIvDl7rje5dLs3Zw+Ln1oddyYzerOo=";
};
};
}

View File

@@ -0,0 +1,15 @@
import ./generic.nix {
version = "14.19";
rev = "refs/tags/REL_14_19";
hash = "sha256-z8MEeLae4W4YqGBNcPtKnUENxnixugnv5Q6r+LW4uu8=";
muslPatches = {
disable-test-collate-icu-utf8 = {
url = "https://git.alpinelinux.org/aports/plain/main/postgresql14/disable-test-collate.icu.utf8.patch?id=56999e6d0265ceff5c5239f85fdd33e146f06cb7";
hash = "sha256-jXe23AxnFjEl+TZQm4R7rStk2Leo08ctxMNmu1xr5zM=";
};
dont-use-locale-a = {
url = "https://git.alpinelinux.org/aports/plain/main/postgresql14/dont-use-locale-a-on-musl.patch?id=56999e6d0265ceff5c5239f85fdd33e146f06cb7";
hash = "sha256-fk+y/SvyA4Tt8OIvDl7rje5dLs3Zw+Ln1oddyYzerOo=";
};
};
}

View File

@@ -0,0 +1,11 @@
import ./generic.nix {
version = "15.14";
rev = "refs/tags/REL_15_14";
hash = "sha256-KzN0gsEY6wFLqNYMxbTj2NH+4IWO0pplWP4XO/fqRLM=";
muslPatches = {
dont-use-locale-a = {
url = "https://git.alpinelinux.org/aports/plain/main/postgresql15/dont-use-locale-a-on-musl.patch?id=f424e934e6d076c4ae065ce45e734aa283eecb9c";
hash = "sha256-fk+y/SvyA4Tt8OIvDl7rje5dLs3Zw+Ln1oddyYzerOo=";
};
};
}

View File

@@ -0,0 +1,11 @@
import ./generic.nix {
version = "16.10";
rev = "refs/tags/REL_16_10";
hash = "sha256-1zG8+G/lNA1xm0hxLVEilIaI+25d4gfpqA2aCb4+taY=";
muslPatches = {
dont-use-locale-a = {
url = "https://git.alpinelinux.org/aports/plain/main/postgresql16/dont-use-locale-a-on-musl.patch?id=08a24be262339fd093e641860680944c3590238e";
hash = "sha256-fk+y/SvyA4Tt8OIvDl7rje5dLs3Zw+Ln1oddyYzerOo=";
};
};
}

View File

@@ -0,0 +1,11 @@
import ./generic.nix {
version = "17.6";
rev = "refs/tags/REL_17_6";
hash = "sha256-/7C+bjmiJ0/CvoAc8vzTC50vP7OsrM6o0w+lmmHvKvU=";
muslPatches = {
dont-use-locale-a = {
url = "https://git.alpinelinux.org/aports/plain/main/postgresql17/dont-use-locale-a-on-musl.patch?id=d69ead2c87230118ae7f72cef7d761e761e1f37e";
hash = "sha256-6zjz3OpMx4qTETdezwZxSJPPdOvhCNu9nXvAaU9SwH8=";
};
};
}

View File

@@ -0,0 +1,11 @@
import ./generic.nix {
version = "18.0";
rev = "refs/tags/REL_18_0";
hash = "sha256-xA6gbJe4tIV9bYRFrdI4Rfy20ZwTkvyyjt7ZxvCFEec=";
muslPatches = {
dont-use-locale-a = {
url = "https://git.alpinelinux.org/aports/plain/main/postgresql17/dont-use-locale-a-on-musl.patch?id=d69ead2c87230118ae7f72cef7d761e761e1f37e";
hash = "sha256-6zjz3OpMx4qTETdezwZxSJPPdOvhCNu9nXvAaU9SwH8=";
};
};
}

View File

@@ -0,0 +1,41 @@
self:
let
# Before removing an EOL major version, make sure to check the versioning policy in:
# <nixpkgs>/nixos/modules/services/databases/postgresql.md
#
# Before removing, make sure to update it to the last minor version - and if only in
# an immediately preceding commit. This allows people relying on that old major version
# for a bit longer to still update up to this commit to at least get the latest minor
# version. In other words: Do not remove the second-to-last minor version from nixpkgs,
# yet. Update first.
versions = {
postgresql_13 = ./13.nix;
postgresql_14 = ./14.nix;
postgresql_15 = ./15.nix;
postgresql_16 = ./16.nix;
postgresql_17 = ./17.nix;
postgresql_18 = ./18.nix;
};
mkAttributes =
jitSupport:
self.lib.mapAttrs' (
version: path:
let
attrName = if jitSupport then "${version}_jit" else version;
postgresql = import path { inherit self; };
attrValue = if jitSupport then postgresql.withJIT else postgresql.withoutJIT;
in
self.lib.nameValuePair attrName attrValue
) versions;
libpq = self.callPackage ./libpq.nix { };
in
{
# variations without and with JIT
postgresqlVersions = mkAttributes false;
postgresqlJitVersions = mkAttributes true;
inherit libpq;
}

View File

@@ -0,0 +1,23 @@
self: super:
let
inherit (self) lib config;
in
(lib.packagesFromDirectoryRecursive {
inherit (super) callPackage;
directory = ./ext;
})
// {
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.";
}
// 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,84 @@
{
bison,
fetchFromGitHub,
flex,
lib,
perl,
postgresql,
postgresqlBuildExtension,
stdenv,
}:
let
hashes = {
# Issue tracking PostgreSQL 17 support: https://github.com/apache/age/issues/2111
# "17" = "";
"16" = "sha256-sXh/vmGyYj00ALfFVdeql2DZ6nCJQDNKyNgzlOZnPAw=";
"15" = "sha256-webZWgWZGnSoXwTpk816tjbtHV1UIlXkogpBDAEL4gM=";
"14" = "sha256-jZXhcYBubpjIJ8M5JHXKV5f6VK/2BkypH3P7nLxZz3E=";
"13" = "sha256-HR6nnWt/V2a0rD5eHHUsFIZ1y7lmvLz36URt9pPJnCw=";
};
in
postgresqlBuildExtension (finalAttrs: {
pname = "age";
version = "1.5.0-rc0";
src = fetchFromGitHub {
owner = "apache";
repo = "age";
tag = "PG${lib.versions.major postgresql.version}/v${
builtins.replaceStrings [ "." ] [ "_" ] finalAttrs.version
}";
hash =
hashes.${lib.versions.major postgresql.version}
or (throw "Source for Age is not available for ${postgresql.version}");
};
makeFlags = [
"BISON=${bison}/bin/bison"
"FLEX=${flex}/bin/flex"
"PERL=${perl}/bin/perl"
];
enableUpdateScript = false;
passthru.tests = stdenv.mkDerivation {
inherit (finalAttrs) version src;
pname = "age-regression";
dontConfigure = true;
buildPhase =
let
postgresqlAge = postgresql.withPackages (_: [ finalAttrs.finalPackage ]);
in
''
# The regression tests need to be run in the order specified in the Makefile.
echo -e "include Makefile\nfiles:\n\t@echo \$(REGRESS)" > Makefile.regress
REGRESS_TESTS=$(make -f Makefile.regress files)
${lib.getDev postgresql}/lib/pgxs/src/test/regress/pg_regress \
--inputdir=./ \
--bindir='${postgresqlAge}/bin' \
--encoding=UTF-8 \
--load-extension=age \
--inputdir=./regress --outputdir=./regress --temp-instance=./regress/instance \
--port=61958 --dbname=contrib_regression \
$REGRESS_TESTS
'';
installPhase = ''
touch $out
'';
};
meta = {
broken = !builtins.elem (lib.versions.major postgresql.version) (builtins.attrNames hashes);
description = "Graph database extension for PostgreSQL";
homepage = "https://age.apache.org/";
changelog = "https://github.com/apache/age/raw/v${finalAttrs.src.rev}/RELEASE";
maintainers = [ ];
platforms = postgresql.meta.platforms;
license = lib.licenses.asl20;
};
})

View File

@@ -0,0 +1,29 @@
{
cargo-pgrx_0_16_0,
jitSupport,
lib,
nixosTests,
pg-dump-anon,
postgresql,
buildPgrxExtension,
runtimeShell,
}:
buildPgrxExtension {
pname = "postgresql_anonymizer";
inherit (pg-dump-anon) version src;
inherit postgresql;
cargo-pgrx = cargo-pgrx_0_16_0;
cargoHash = "sha256-Z1uH6Z2qLV1Axr8dXqPznuEZcacAZnv11tb3lWBh1yw=";
# Tries to copy extension into postgresql's store path.
doCheck = false;
passthru.tests = nixosTests.postgresql.anonymizer.passthru.override postgresql;
meta = lib.getAttrs [ "homepage" "teams" "license" ] pg-dump-anon.meta // {
description = "Extension to mask or replace personally identifiable information (PII) or commercially sensitive data from a PostgreSQL database";
};
}

View File

@@ -0,0 +1,71 @@
{
boost186,
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
}:
let
version = "1.7.0";
main_src = fetchFromGitHub {
name = "datasketches-postgresql";
owner = "apache";
repo = "datasketches-postgresql";
tag = version;
hash = "sha256-W41uAs3W4V7c9O/wBw3rut65bcmY8EdQS1/tPszMGqA=";
};
cpp_src = fetchFromGitHub {
name = "datasketches-cpp";
owner = "apache";
repo = "datasketches-cpp";
tag = "5.0.2";
hash = "sha256-yGk1OckYipAgLTQK6w6p6EdHMxBIQSjPV/MMND3cDks=";
};
in
postgresqlBuildExtension (finalAttrs: {
pname = "apache_datasketches";
inherit version;
srcs = [
main_src
cpp_src
];
sourceRoot = main_src.name;
# fails to build with boost 1.87
buildInputs = [ boost186 ];
patchPhase = ''
runHook prePatch
cp -r ../${cpp_src.name} .
runHook postPatch
'';
enableUpdateScript = false;
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = ''
CREATE EXTENSION datasketches;
SELECT hll_sketch_to_string(hll_sketch_build(1));
'';
};
meta = {
description = "PostgreSQL extension providing approximate algorithms for distinct item counts, quantile estimation and frequent items detection";
longDescription = ''
apache_datasketches is an extension to support approximate algorithms on PostgreSQL. The implementation
is based on the Apache Datasketches CPP library, and provides support for HyperLogLog,
Compressed Probabilistic Counting, KLL, Frequent strings, and Theta sketches.
'';
homepage = "https://datasketches.apache.org/";
platforms = postgresql.meta.platforms;
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ mmusnjak ];
};
})

View File

@@ -0,0 +1,84 @@
{
curl,
fetchFromGitHub,
fetchpatch,
lib,
lz4,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "citus";
version = "13.0.3";
src = fetchFromGitHub {
owner = "citusdata";
repo = "citus";
tag = "v${finalAttrs.version}";
hash = "sha256-tQ2YkMUeziz+dhfXtfuK0x8PWH3vfoJiVbE+YvQ/Gzc=";
};
patches = [
# Even though this commit is on main since Sep 2023, it hasn't made its way to the release-13.0 branch, yet.
# https://github.com/citusdata/citus/pull/7221
# Fixes build for PG 16 + 17 on darwin
(fetchpatch {
url = "https://github.com/citusdata/citus/commit/0f28a69f12418d211ffba5f7ddd222fd0c47daeb.patch";
hash = "sha256-8JAM+PUswzbdlAZUpRApgO0eBsMbUHFdFGsdATsG88I=";
})
];
buildInputs = [
curl
lz4
];
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
postgresqlExtraSettings = ''
shared_preload_libraries=citus
'';
sql = ''
CREATE EXTENSION citus;
CREATE TABLE examples (
id bigserial,
shard_key int,
PRIMARY KEY (id, shard_key)
);
SELECT create_distributed_table('examples', 'shard_key');
INSERT INTO examples (shard_key) SELECT shard % 10 FROM generate_series(1,1000) shard;
'';
asserts = [
{
query = "SELECT count(*) FROM examples";
expected = "1000";
description = "Distributed table can be queried successfully.";
}
];
};
meta = {
# "Our soft policy for Postgres version compatibility is to support Citus'
# latest release with Postgres' 3 latest releases."
# https://www.citusdata.com/updates/v12-0/#deprecated_features
broken =
lib.versionOlder postgresql.version "15"
||
# PostgreSQL 18 support issue upstream: https://github.com/citusdata/citus/issues/7978
# Check after next package update.
lib.warnIf (finalAttrs.version != "13.0.3") "Is postgresql18Packages.citus still broken?" (
lib.versionAtLeast postgresql.version "18"
);
description = "Distributed PostgreSQL as an extension";
homepage = "https://www.citusdata.com/";
changelog = "https://github.com/citusdata/citus/blob/${finalAttrs.src.rev}/CHANGELOG.md";
license = lib.licenses.agpl3Only;
maintainers = [ ];
inherit (postgresql.meta) platforms;
};
})

View File

@@ -0,0 +1,31 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
protobufc,
}:
postgresqlBuildExtension {
pname = "cstore_fdw";
version = "1.7.0-unstable-2021-03-08";
buildInputs = [ protobufc ];
nativeBuildInputs = [ protobufc ];
src = fetchFromGitHub {
owner = "citusdata";
repo = "cstore_fdw";
rev = "90e22b62fbee6852529104fdd463f532cf7a3311";
hash = "sha256-02wcCqs8A5ZOZX080fgcNJTQrYQctnlwnA8+YPaRTZc=";
};
meta = {
broken = lib.versionAtLeast postgresql.version "14";
description = "Columnar storage for PostgreSQL";
homepage = "https://github.com/citusdata/cstore_fdw";
maintainers = with lib.maintainers; [ thoughtpolice ];
platforms = postgresql.meta.platforms;
license = lib.licenses.asl20;
};
}

View File

@@ -0,0 +1,59 @@
{
cmake,
fetchFromGitHub,
h3_4,
lib,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
stdenv,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "h3-pg";
version = "4.2.3";
src = fetchFromGitHub {
owner = "zachasme";
repo = "h3-pg";
tag = "v${finalAttrs.version}";
hash = "sha256-kTh0Y0C2pNB5Ul1rp77ets/5VeU1zw1WasGHkOaDMh8=";
};
postPatch = ''
substituteInPlace CMakeLists.txt \
--replace-fail "add_subdirectory(cmake/h3)" "include_directories(${lib.getDev h3_4}/include/h3)"
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
substituteInPlace cmake/AddPostgreSQLExtension.cmake \
--replace-fail "INTERPROCEDURAL_OPTIMIZATION TRUE" ""
'';
nativeBuildInputs = [
cmake
];
buildInputs = [
h3_4
];
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
withPackages = [ "postgis" ];
sql = ''
CREATE EXTENSION h3;
CREATE EXTENSION h3_postgis CASCADE;
SELECT h3_lat_lng_to_cell(POINT('37.3615593,-122.0553238'), 5);
SELECT ST_NPoints(h3_cell_to_boundary_geometry('8a63a9a99047fff'));
'';
};
meta = {
description = "PostgreSQL bindings for H3, a hierarchical hexagonal geospatial indexing system";
homepage = "https://github.com/zachasme/h3-pg";
license = lib.licenses.asl20;
maintainers = [ ];
inherit (postgresql.meta) platforms;
};
})

View File

@@ -0,0 +1,34 @@
{
fetchFromGitHub,
gitUpdater,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "hypopg";
version = "1.4.2";
src = fetchFromGitHub {
owner = "HypoPG";
repo = "hypopg";
tag = finalAttrs.version;
hash = "sha256-J1ltvNHB2v2I9IbYjM8w2mhXvBX31NkMasCL0O7bV8w=";
};
passthru = {
updateScript = gitUpdater {
ignoredVersions = "beta";
};
};
meta = {
description = "Hypothetical Indexes for PostgreSQL";
homepage = "https://hypopg.readthedocs.io";
changelog = "https://github.com/HypoPG/hypopg/releases/tag/${finalAttrs.version}";
license = lib.licenses.postgresql;
platforms = postgresql.meta.platforms;
maintainers = with lib.maintainers; [ bbigras ];
};
})

View File

@@ -0,0 +1,34 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "ip4r";
version = "2.4.2";
src = fetchFromGitHub {
owner = "RhodiumToad";
repo = "ip4r";
tag = "${finalAttrs.version}";
hash = "sha256-3chAD4f4A6VlXVSI0kfC/ANcnFy4vBp4FZpT6QRAueQ=";
};
passthru.tests = {
extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = "CREATE EXTENSION ip4r;";
};
};
meta = {
description = "IPv4/v6 and IPv4/v6 range index type for PostgreSQL";
homepage = "https://github.com/RhodiumToad/ip4r";
license = lib.licenses.postgresql;
maintainers = with lib.maintainers; [ lukegb ];
inherit (postgresql.meta) platforms;
};
})

View File

@@ -0,0 +1,26 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension {
pname = "jsonb_deep_sum";
version = "0-unstable-2021-12-24";
src = fetchFromGitHub {
owner = "furstenheim";
repo = "jsonb_deep_sum";
rev = "d9c69aa6b7da860e5522a9426467e67cb787980c";
hash = "sha256-W1wNILAwTAjFPezq+grdRMA59KEnMZDz69n9xQUqdc0=";
};
meta = {
description = "PostgreSQL extension to easily add jsonb numeric";
homepage = "https://github.com/furstenheim/jsonb_deep_sum";
maintainers = with lib.maintainers; [ _1000101 ];
platforms = postgresql.meta.platforms;
license = lib.licenses.mit;
};
}

View File

@@ -0,0 +1,66 @@
{
cmake,
fetchFromGitHub,
lib,
openssl,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "postgresql-lantern";
version = "0.5.0";
src = fetchFromGitHub {
owner = "lanterndata";
repo = "lantern";
tag = "v${finalAttrs.version}";
hash = "sha256-IsDD/um5pVvbzin8onf45DQVszl+Id/pJSQ2iijgHmg=";
fetchSubmodules = true;
};
postPatch = ''
patchShebangs --build lantern_hnsw/scripts/link_llvm_objects.sh
'';
nativeBuildInputs = [
cmake
];
buildInputs = [
openssl
];
cmakeFlags = [
"-DBUILD_FOR_DISTRIBUTING=ON"
"-S ../lantern_hnsw"
];
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = ''
CREATE EXTENSION lantern;
CREATE TABLE small_world (id integer, vector real[3]);
INSERT INTO small_world (id, vector) VALUES (0, '{0,0,0}'), (1, '{0,0,1}');
CREATE INDEX ON small_world USING lantern_hnsw (vector dist_l2sq_ops)
WITH (M=2, ef_construction=10, ef=4, dim=3);
'';
};
meta = {
# PostgreSQL 18 support issue upstream: https://github.com/lanterndata/lantern/issues/375
# Check after next package update.
broken = lib.warnIf (
finalAttrs.version != "0.5.0"
) "Is postgresql18Packages.lantern still broken?" (lib.versionAtLeast postgresql.version "18");
description = "PostgreSQL vector database extension for building AI applications";
homepage = "https://lantern.dev/";
changelog = "https://github.com/lanterndata/lantern/blob/${finalAttrs.src.rev}/CHANGELOG.md";
license = lib.licenses.agpl3Only;
maintainers = [ ];
platforms = postgresql.meta.platforms;
};
})

View File

@@ -0,0 +1,100 @@
{
brotli,
clang_18,
cmake,
fetchFromGitHub,
flex,
lib,
netcat,
perl,
pkg-config,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
python3,
stdenv,
unstableGitUpdater,
}:
let
pgWithExtensions = postgresql.withPackages (ps: [ ps.plpython3 ]);
in
postgresqlBuildExtension (finalAttrs: {
pname = "omnigres";
version = "0-unstable-2025-09-26";
src = fetchFromGitHub {
owner = "omnigres";
repo = "omnigres";
rev = "247383198a95d045df0d97ece5a81adffb5c08e8";
hash = "sha256-RrdtUtrs0Mh1VyMbF89qJhr2fnCVcQy2l1/85/mJ/4Y=";
};
# This matches postInstall of PostgreSQL's generic.nix, which does this for the PGXS Makefile.
# Since omnigres uses a CMake file, which tries to replicate the things that PGXS does, we need
# to apply the same fix for darwin.
# The reason we need to do this is, because PG_BINARY will point at the postgres wrapper of
# postgresql.withPackages, which does not contain the same symbols as the original file, ofc.
postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
substituteInPlace "cmake/PostgreSQLExtension.cmake" \
--replace-fail '-bundle_loader ''${PG_BINARY}' "-bundle_loader ${postgresql}/bin/postgres"
'';
strictDeps = true;
nativeBuildInputs = [
clang_18
cmake
flex
netcat
pkg-config
perl
python3
];
buildInputs = postgresql.buildInputs ++ [
brotli
];
cmakeFlags = [
"-DOPENSSL_CONFIGURED=1"
"-DPG_CONFIG=${pgWithExtensions.pg_config}/bin/pg_config"
"-DPostgreSQL_TARGET_EXTENSION_DIR=${placeholder "out"}/share/postgresql/extension/"
"-DPostgreSQL_TARGET_PACKAGE_LIBRARY_DIR=${placeholder "out"}/lib/"
];
enableParallelBuilding = true;
doCheck = false;
preInstall = ''
patchShebangs script_omni*
mkdir -p $out/lib/
mkdir -p $out/share/postgresql/extension/
'';
# https://github.com/omnigres/omnigres?tab=readme-ov-file#building--using-extensions
installTargets = [ "install_extensions" ];
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = ''
-- https://docs.omnigres.org/omni_id/identity_type/#usage
CREATE EXTENSION omni_id;
SELECT identity_type('user_id');
'';
};
passthru.updateScript = unstableGitUpdater {
hardcodeZeroVersion = true;
};
meta = {
description = "Postgres as a Business Operating System";
homepage = "https://docs.omnigres.org";
maintainers = with lib.maintainers; [ mtrsk ];
platforms = postgresql.meta.platforms;
license = lib.licenses.asl20;
broken = lib.versionOlder postgresql.version "14";
};
})

View File

@@ -0,0 +1,26 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "periods";
version = "1.2.3";
src = fetchFromGitHub {
owner = "xocolatl";
repo = "periods";
tag = "v${finalAttrs.version}";
hash = "sha256-97v6+WNDcYb/KivlE/JBlRIZ3gYHj68AlK0fylp1cPo=";
};
meta = {
description = "PostgreSQL extension implementing SQL standard functionality for PERIODs and SYSTEM VERSIONING";
homepage = "https://github.com/xocolatl/periods";
maintainers = with lib.maintainers; [ ivan ];
platforms = postgresql.meta.platforms;
license = lib.licenses.postgresql;
};
})

View File

@@ -0,0 +1,47 @@
{
cmake,
fetchFromGitHub,
glib,
gvm-libs,
icu,
lib,
libical,
pcre2,
pkg-config,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg-gvm";
version = "22.6.11";
src = fetchFromGitHub {
owner = "greenbone";
repo = "pg-gvm";
tag = "v${finalAttrs.version}";
hash = "sha256-jkpZg1LMWuH5R4I/kTO3cofL3uNt11yXSgfFppSNC+o=";
};
nativeBuildInputs = [
cmake
pkg-config
];
buildInputs = [
glib
gvm-libs
icu
libical
pcre2
];
meta = {
description = "Greenbone Library for helper functions in PostgreSQL";
homepage = "https://github.com/greenbone/pg-gvm";
changelog = "https://github.com/greenbone/pg-gvm/releases/tag/v${finalAttrs.version}";
license = lib.licenses.gpl3Only;
maintainers = with lib.maintainers; [ tochiaha ];
platforms = postgresql.meta.platforms;
};
})

View File

@@ -0,0 +1,35 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg-semver";
version = "0.40.0";
src = fetchFromGitHub {
owner = "theory";
repo = "pg-semver";
tag = "v${finalAttrs.version}";
hash = "sha256-9f+QuGupjTUK3cQk7DFDrL7MOIwDE9SAUyVZ9RfrdDM=";
};
passthru.tests = {
extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = "CREATE EXTENSION semver;";
};
};
meta = {
description = "Semantic version data type for PostgreSQL";
homepage = "https://github.com/theory/pg-semver";
changelog = "https://github.com/theory/pg-semver/blob/main/Changes";
maintainers = with lib.maintainers; [ grgi ];
inherit (postgresql.meta) platforms;
license = lib.licenses.postgresql;
};
})

View File

@@ -0,0 +1,35 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_auto_failover";
version = "2.2";
src = fetchFromGitHub {
owner = "citusdata";
repo = "pg_auto_failover";
tag = "v${finalAttrs.version}";
hash = "sha256-lsnVry+5n08kLOun8u0B7XFvI5ijTKJtFJ84fixMHe4=";
};
buildInputs = postgresql.buildInputs;
meta = {
# PostgreSQL 18 support issue upstream: https://github.com/hapostgres/pg_auto_failover/issues/1083
# Check after next package update.
broken =
lib.warnIf (finalAttrs.version != "2.2") "Is postgresql18Packages.pg_auto_failover still broken?"
(lib.versionAtLeast postgresql.version "18");
description = "PostgreSQL extension and service for automated failover and high-availability";
mainProgram = "pg_autoctl";
homepage = "https://github.com/citusdata/pg_auto_failover";
changelog = "https://github.com/citusdata/pg_auto_failover/blob/v${finalAttrs.version}/CHANGELOG.md";
maintainers = [ ];
platforms = postgresql.meta.platforms;
license = lib.licenses.postgresql;
};
})

View File

@@ -0,0 +1,28 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_bigm";
version = "1.2-20250903";
src = fetchFromGitHub {
owner = "pgbigm";
repo = "pg_bigm";
tag = "v${finalAttrs.version}";
hash = "sha256-8V+sGebagYxXW1o2k2cNlGG4cFOObdRAvqCXKyR95hI=";
};
makeFlags = [ "USE_PGXS=1" ];
meta = {
description = "Text similarity measurement and index searching based on bigrams";
homepage = "https://pgbigm.osdn.jp/";
maintainers = [ ];
platforms = postgresql.meta.platforms;
license = lib.licenses.postgresql;
};
})

View File

@@ -0,0 +1,50 @@
{
fetchFromGitHub,
file,
lib,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_byteamagic";
version = "0.2.4";
src = fetchFromGitHub {
owner = "nmandery";
repo = "pg_byteamagic";
tag = "v${finalAttrs.version}";
hash = "sha256-0RRElMMVUm3cXLI7G3SkIVr8yA/Rk3gBsgXG+EFU3CI=";
};
buildInputs = [
file
];
passthru.tests = {
extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = ''
CREATE EXTENSION byteamagic;
SELECT byteamagic_mime('test');
'';
asserts = [
{
query = "SELECT byteamagic_mime('test')";
expected = "'text/plain'";
description = "`byteamagic_mime(...) should return proper mimetype.";
}
];
};
};
meta = {
description = "PostgreSQL extension to determinate the filetypes of bytea BLOBs";
homepage = "https://github.com/nmandery/pg_byteamagic";
changelog = "https://raw.githubusercontent.com/nmandery/pg_byteamagic/refs/tags/v${finalAttrs.version}/Changes";
license = lib.licenses.bsd2WithViews;
teams = [ lib.teams.apm ];
platforms = postgresql.meta.platforms;
};
})

View File

@@ -0,0 +1,27 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_cron";
version = "1.6.7";
src = fetchFromGitHub {
owner = "citusdata";
repo = "pg_cron";
tag = "v${finalAttrs.version}";
hash = "sha256-oQjaQeIEMbg5pipY8tT4I7bNdyDOwcr/ZJikqgcEZOs=";
};
meta = {
description = "Run Cron jobs through PostgreSQL";
homepage = "https://github.com/citusdata/pg_cron";
changelog = "https://github.com/citusdata/pg_cron/releases/tag/v${finalAttrs.version}";
maintainers = with lib.maintainers; [ thoughtpolice ];
platforms = postgresql.meta.platforms;
license = lib.licenses.postgresql;
};
})

View File

@@ -0,0 +1,27 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_csv";
version = "1.0.1";
src = fetchFromGitHub {
owner = "PostgREST";
repo = "pg_csv";
tag = "v${finalAttrs.version}";
hash = "sha256-hRTNFlNUmc3mjDf0wgn4CGmHoYPQ+2yfZApzooLwgW4=";
};
meta = {
description = "Flexible CSV processing for Postgres";
homepage = "https://github.com/PostgREST/pg_csv";
changelog = "https://github.com/PostgREST/pg_csv/releases/tag/v${finalAttrs.version}";
maintainers = with lib.maintainers; [ steve-chavez ];
platforms = postgresql.meta.platforms;
license = lib.licenses.mit;
};
})

View File

@@ -0,0 +1,28 @@
{
fetchFromGitLab,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_ed25519";
version = "0.2";
src = fetchFromGitLab {
owner = "dwagin";
repo = "pg_ed25519";
tag = finalAttrs.version;
hash = "sha256-IOL3ogbPCMNmwDwpeaCZSoaFLJRX0Oah+ysgyUfHg5s=";
};
meta = {
description = "PostgreSQL extension for signing and verifying ed25519 signatures";
homepage = "https://gitlab.com/dwagin/pg_ed25519";
maintainers = with lib.maintainers; [ renzo ];
platforms = postgresql.meta.platforms;
license = lib.licenses.mit;
# Broken with no upstream fix available.
broken = lib.versionAtLeast postgresql.version "16";
};
})

View File

@@ -0,0 +1,50 @@
{
buildPgrxExtension,
cargo-pgrx_0_16_0,
fetchFromGitHub,
lib,
nix-update-script,
postgresql,
}:
buildPgrxExtension (finalAttrs: {
inherit postgresql;
cargo-pgrx = cargo-pgrx_0_16_0;
pname = "pg_graphql";
version = "1.5.12-unstable-2025-09-01";
src = fetchFromGitHub {
owner = "supabase";
repo = "pg_graphql";
# ToDo: 1.5.12 has not been tagged in Git yet, hence `rev` is used instead for now
#tag = "v${finalAttrs.version}";
rev = "bae1cb506d48d14ccf2b05f6a42331f3c9c71a76";
hash = "sha256-aJPstwzizWzVIo1N/4CHKgJBJ7DJpRkrwYrzNL+z7zQ=";
};
cargoHash = "sha256-Gfvu6YY+pRGrcAXAgEIa1iZKLJlbkvMv0F3pg3X/CXQ=";
# pgrx tests try to install the extension into postgresql nix store
doCheck = false;
passthru = {
updateScript = nix-update-script { };
};
meta = {
description = "GraphQL support for PostgreSQL";
homepage = "https://supabase.github.io/pg_graphql";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ julm ];
broken =
lib.versionOlder postgresql.version "14"
|| (
# ToDo: check after next package update.
lib.versionAtLeast postgresql.version "18"
&& (
finalAttrs.version == "1.5.12-unstable-2025-09-01"
|| lib.warn "Is postgresql18Packages.pg_graphql still broken?" false
)
);
};
})

View File

@@ -0,0 +1,70 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
let
sources = {
"18" = {
version = "1.8.0";
hash = "sha256-QsDppGN5TE7CSii3mNmwqT/riNNjyRTJk6d6Xcf0JMw=";
};
"17" = {
version = "1.7.1";
hash = "sha256-9GKqyrNpi80I4WWIiRN8zeXBm5bkRuzOWrZVfpYOzag=";
};
"16" = {
version = "1.6.2";
hash = "sha256-WMmtnuGOvLwtiEmgHpYURC1k5NmkBiDg+PnQCIZp7Sk=";
};
"15" = {
version = "1.5.3";
hash = "sha256-jkU0zt1waPTdFrBLAxYNvlo+RwdhCtKQq7iqAuxthNA=";
};
"14" = {
version = "1.4.4";
hash = "sha256-8rJ4Ck0Axf9zKhOXaJ4EA/M783YZRLuWx+GMGccadVo=";
};
"13" = {
version = "1.3.11";
hash = "sha256-XTxCw1Uj6rVLcXJuHoT3RkEhdKVLGjOdR7rhFI8YJas=";
};
};
source =
sources.${lib.versions.major postgresql.version} or {
version = "";
hash = throw "Source for pg_hint_plan is not available for ${postgresql.version}";
};
in
postgresqlBuildExtension {
pname = "pg_hint_plan";
inherit (source) version;
src = fetchFromGitHub {
owner = "ossc-db";
repo = "pg_hint_plan";
tag = "REL${lib.versions.major postgresql.version}_${
builtins.replaceStrings [ "." ] [ "_" ] source.version
}";
inherit (source) hash;
};
postPatch = lib.optionalString (lib.versionOlder postgresql.version "14") ''
# https://github.com/ossc-db/pg_hint_plan/commit/e9e564ad59b8bd4a03e0f13b95b5122712e573e6
substituteInPlace Makefile --replace "LDFLAGS+=-Wl,--build-id" ""
'';
enableUpdateScript = false;
meta = {
broken = !builtins.elem (lib.versions.major postgresql.version) (builtins.attrNames sources);
description = "Extension to tweak PostgreSQL execution plans using so-called 'hints' in SQL comments";
homepage = "https://github.com/ossc-db/pg_hint_plan";
maintainers = with lib.maintainers; [ _1000101 ];
platforms = postgresql.meta.platforms;
license = lib.licenses.bsd3;
};
}

View File

@@ -0,0 +1,36 @@
{
fetchFromGitHub,
fetchpatch,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_hll";
version = "2.18";
src = fetchFromGitHub {
owner = "citusdata";
repo = "postgresql-hll";
tag = "v${finalAttrs.version}";
hash = "sha256-Latdxph1Ura8yKEokEjalJ+/GY+pAKOT3GXjuLprj6c=";
};
patches = [
(fetchpatch {
name = "fix-postgresql-18.patch";
url = "https://github.com/citusdata/postgresql-hll/commit/f998e234653ea397ddddc1278d1c02d8d011bd16.patch";
hash = "sha256-gF4f+B4Gu/QEyCGMfKLmRK6lNwgfd8lML55wMkhsSY4=";
})
];
meta = {
description = "HyperLogLog for PostgreSQL";
homepage = "https://github.com/citusdata/postgresql-hll";
changelog = "https://github.com/citusdata/postgresql-hll/blob/v${finalAttrs.version}/CHANGELOG.md";
maintainers = with lib.maintainers; [ thoughtpolice ];
platforms = postgresql.meta.platforms;
license = lib.licenses.asl20;
};
})

View File

@@ -0,0 +1,27 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_ivm";
version = "1.12";
src = fetchFromGitHub {
owner = "sraoss";
repo = "pg_ivm";
tag = "v${finalAttrs.version}";
hash = "sha256-UeRcxoUkpPw4EcQXKUxHamjczOaE59d00kSrYsijnH8=";
};
meta = {
description = "Materialized views with IVM (Incremental View Maintenance) for PostgreSQL";
homepage = "https://github.com/sraoss/pg_ivm";
changelog = "https://github.com/sraoss/pg_ivm/releases/tag/v${finalAttrs.version}";
maintainers = with lib.maintainers; [ ivan ];
platforms = postgresql.meta.platforms;
license = lib.licenses.postgresql;
};
})

View File

@@ -0,0 +1,39 @@
{
fetchFromGitHub,
gitUpdater,
lib,
libversion,
pkg-config,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_libversion";
version = "2.0.1";
src = fetchFromGitHub {
owner = "repology";
repo = "postgresql-libversion";
tag = finalAttrs.version;
hash = "sha256-3nqXaBwPRUSo6wUY5YMjJ/nFFKmhgP1zFKapD+RqSDw=";
};
nativeBuildInputs = [
pkg-config
];
buildInputs = [
libversion
];
passthru.updateScript = gitUpdater { };
meta = {
description = "PostgreSQL extension with support for version string comparison";
homepage = "https://github.com/repology/postgresql-libversion";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ jopejoe1 ];
platforms = postgresql.meta.platforms;
};
})

View File

@@ -0,0 +1,30 @@
{
curl,
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_net";
version = "0.19.7";
src = fetchFromGitHub {
owner = "supabase";
repo = "pg_net";
tag = "v${finalAttrs.version}";
hash = "sha256-HQiFD8vhox7SmjJIDyVnnwt8DCENKABIZTMfTjGElwU=";
};
buildInputs = [ curl ];
meta = {
description = "Async networking for Postgres";
homepage = "https://github.com/supabase/pg_net";
changelog = "https://github.com/supabase/pg_net/releases/tag/v${finalAttrs.version}";
maintainers = with lib.maintainers; [ thoughtpolice ];
platforms = postgresql.meta.platforms;
license = lib.licenses.postgresql;
};
})

View File

@@ -0,0 +1,28 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_partman";
version = "5.2.4";
src = fetchFromGitHub {
owner = "pgpartman";
repo = "pg_partman";
tag = "v${finalAttrs.version}";
hash = "sha256-i/o+JZEXnJRO17kfdTw87aca28+I8pvuFZsPMA/kf+w=";
};
meta = {
description = "Partition management extension for PostgreSQL";
homepage = "https://github.com/pgpartman/pg_partman";
changelog = "https://github.com/pgpartman/pg_partman/blob/v${finalAttrs.version}/CHANGELOG.md";
maintainers = with lib.maintainers; [ ggpeti ];
platforms = postgresql.meta.platforms;
license = lib.licenses.postgresql;
broken = lib.versionOlder postgresql.version "14";
};
})

View File

@@ -0,0 +1,26 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_rational";
version = "0.0.2";
src = fetchFromGitHub {
owner = "begriffs";
repo = "pg_rational";
tag = "v${finalAttrs.version}";
hash = "sha256-Sp5wuX2nP3KGyWw7MFa11rI1CPIKIWBt8nvBSsASIEw=";
};
meta = {
description = "Precise fractional arithmetic for PostgreSQL";
homepage = "https://github.com/begriffs/pg_rational";
maintainers = with lib.maintainers; [ netcrns ];
platforms = postgresql.meta.platforms;
license = lib.licenses.mit;
};
})

View File

@@ -0,0 +1,26 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_relusage";
version = "0.0.1";
src = fetchFromGitHub {
owner = "adept";
repo = "pg_relusage";
tag = "${finalAttrs.version}";
hash = "sha256-8hJNjQ9MaBk3J9a73l+yQMwMW/F2N8vr5PO2o+5GvYs=";
};
meta = {
description = "pg_relusage extension for PostgreSQL: discover and log the relations used in your statements";
homepage = "https://github.com/adept/pg_relusage";
maintainers = with lib.maintainers; [ thenonameguy ];
platforms = postgresql.meta.platforms;
license = lib.licenses.postgresql;
};
})

View File

@@ -0,0 +1,52 @@
{
fetchFromGitHub,
gitUpdater,
lib,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
testers,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_repack";
version = "1.5.2";
buildInputs = postgresql.buildInputs;
src = fetchFromGitHub {
owner = "reorg";
repo = "pg_repack";
tag = "ver_${finalAttrs.version}";
hash = "sha256-wfjiLkx+S3zVrAynisX1GdazueVJ3EOwQEPcgUQt7eA=";
};
passthru.updateScript = gitUpdater {
rev-prefix = "ver_";
};
passthru.tests = {
version = testers.testVersion {
package = finalAttrs.finalPackage;
};
extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = "CREATE EXTENSION pg_repack;";
};
};
meta = {
description = "Reorganize tables in PostgreSQL databases with minimal locks";
longDescription = ''
pg_repack is a PostgreSQL extension which lets you remove bloat from tables and indexes, and optionally restore
the physical order of clustered indexes. Unlike CLUSTER and VACUUM FULL it works online, without holding an
exclusive lock on the processed tables during processing. pg_repack is efficient to boot,
with performance comparable to using CLUSTER directly.
'';
homepage = "https://github.com/reorg/pg_repack";
license = lib.licenses.bsd3;
maintainers = with lib.maintainers; [ danbst ];
inherit (postgresql.meta) platforms;
mainProgram = "pg_repack";
};
})

View File

@@ -0,0 +1,27 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_roaringbitmap";
version = "0.5.5";
src = fetchFromGitHub {
owner = "ChenHuajun";
repo = "pg_roaringbitmap";
tag = "v${finalAttrs.version}";
hash = "sha256-5tThowu8k7R33rD/SXINOmzfgSkc4P3lVJ35BeCinZw=";
};
meta = {
description = "RoaringBitmap extension for PostgreSQL";
homepage = "https://github.com/ChenHuajun/pg_roaringbitmap";
changelog = "https://github.com/ChenHuajun/pg_roaringbitmap/blob/${finalAttrs.src.rev}/CHANGELOG.md";
license = lib.licenses.asl20;
maintainers = [ ];
inherit (postgresql.meta) platforms;
};
})

View File

@@ -0,0 +1,63 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
let
sources = {
"13" = {
version = "1.4";
hash = "sha256-1cyvVEC9MQGMr7Tg6EUbsVBrMc8ahdFS3+CmDkmAq4Y=";
};
"14" = {
version = "1.5";
hash = "sha256-RRSpkWLFuif+6RCncnsb1NnjKnIIRY9KgebKkjCN5cs=";
};
"15" = {
version = "1.5";
hash = "sha256-RRSpkWLFuif+6RCncnsb1NnjKnIIRY9KgebKkjCN5cs=";
};
"16" = {
version = "1.5";
hash = "sha256-RRSpkWLFuif+6RCncnsb1NnjKnIIRY9KgebKkjCN5cs=";
};
"17" = {
version = "1.5";
hash = "sha256-RRSpkWLFuif+6RCncnsb1NnjKnIIRY9KgebKkjCN5cs=";
};
"18" = {
version = "1.5";
hash = "sha256-RRSpkWLFuif+6RCncnsb1NnjKnIIRY9KgebKkjCN5cs=";
};
};
source =
sources."${lib.versions.major postgresql.version}" or {
version = "";
hash = throw "pg_safeupdate: version specification for pg ${postgresql.version} missing.";
};
in
postgresqlBuildExtension {
pname = "pg-safeupdate";
inherit (source) version;
src = fetchFromGitHub {
owner = "eradman";
repo = "pg-safeupdate";
tag = source.version;
inherit (source) hash;
};
meta = {
broken = !builtins.elem (lib.versions.major postgresql.version) (builtins.attrNames sources);
description = "Simple extension to PostgreSQL that requires criteria for UPDATE and DELETE";
homepage = "https://github.com/eradman/pg-safeupdate";
changelog = "https://github.com/eradman/pg-safeupdate/raw/${source.version}/NEWS";
platforms = postgresql.meta.platforms;
maintainers = with lib.maintainers; [ wolfgangwalther ];
license = lib.licenses.postgresql;
};
}

View File

@@ -0,0 +1,43 @@
{
fetchFromGitHub,
fetchpatch,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension {
pname = "pg_similarity";
version = "pg_similarity_1_0-unstable-2021-01-12";
src = fetchFromGitHub {
owner = "eulerto";
repo = "pg_similarity";
rev = "b9cb0a2d501b91e33cd1ef550b05483ca3563f71";
hash = "sha256-L04ANvyfzHgW7fINeJEY6T77Vojq3SI8P1TWiCRSPs0=";
};
patches = [
(fetchpatch {
# https://github.com/eulerto/pg_similarity/pull/43
# Also applied in debian as https://sources.debian.org/data/main/p/pg-similarity/1.0-8/debian/patches/pg16
name = "pg16.patch";
url = "https://github.com/eulerto/pg_similarity/commit/f7781ea5ace80f697a8249e03e3ce47d4b0f6b2f.patch";
hash = "sha256-MPDvWfNzSg28lXL5u5/Un9pOCJjqJ4Fz9b8XCfalgts=";
})
];
makeFlags = [ "USE_PGXS=1" ];
meta = {
description = "Extension to support similarity queries on PostgreSQL";
longDescription = ''
pg_similarity is an extension to support similarity queries on PostgreSQL. The implementation
is tightly integrated in the RDBMS in the sense that it defines operators so instead of the traditional
operators (= and <>) you can use ~~~ and ~!~ (any of these operators represents a similarity function).
'';
platforms = postgresql.meta.platforms;
license = lib.licenses.bsd3;
maintainers = with lib.maintainers; [ danbst ];
};
}

View File

@@ -0,0 +1,51 @@
{
fetchFromGitHub,
lib,
nix-update-script,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_squeeze";
version = "1.9.1";
src = fetchFromGitHub {
owner = "cybertec-postgresql";
repo = "pg_squeeze";
tag = "REL${lib.replaceString "." "_" finalAttrs.version}";
hash = "sha256-KbCS3kg2MoxKHl+35UOFCSF4kPPsIMeO7AfwfHZYZVg=";
};
passthru.updateScript = nix-update-script {
extraArgs = [ "--version-regex=^REL(\\d+)_(\\d+)_(\\d+)$" ];
};
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
postgresqlExtraSettings = ''
wal_level = logical
shared_preload_libraries = 'pg_squeeze'
'';
sql = ''
CREATE EXTENSION pg_squeeze;
SELECT squeeze.start_worker();
CREATE TABLE a(i int PRIMARY KEY, j int);
INSERT INTO a(i, j) SELECT x, x FROM generate_series(1, 20) AS g(x);
INSERT INTO squeeze.tables (tabschema, tabname, schedule)
VALUES ('public', 'a', ('{30}', '{22}', NULL, NULL, '{3, 5}'));
SELECT squeeze.squeeze_table('public', 'a', NULL, NULL, NULL);
'';
};
meta = {
description = "PostgreSQL extension for automatic bloat cleanup";
homepage = "https://github.com/cybertec-postgresql/pg_squeeze";
changelog = "https://github.com/cybertec-postgresql/pg_squeeze/blob/${finalAttrs.src.rev}/NEWS";
license = lib.licenses.mit;
maintainers = [ ];
platforms = postgresql.meta.platforms;
};
})

View File

@@ -0,0 +1,29 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension rec {
pname = "pg_tle";
version = "1.5.2";
src = fetchFromGitHub {
owner = "aws";
repo = "pg_tle";
tag = "v${version}";
hash = "sha256-DB7aPSgW2/cjDWwXsFiEfJ5xhlHnhtII0quxtgwZg5c=";
};
buildInputs = postgresql.buildInputs;
meta = {
description = "Framework for building trusted language extensions for PostgreSQL";
homepage = "https://github.com/aws/pg_tle";
changelog = "https://github.com/aws/pg_tle/releases/tag/v${version}";
maintainers = [ lib.maintainers.benchand ];
platforms = postgresql.meta.platforms;
license = lib.licenses.asl20;
};
}

View File

@@ -0,0 +1,27 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension rec {
pname = "pg_topn";
version = "2.7.0";
src = fetchFromGitHub {
owner = "citusdata";
repo = "postgresql-topn";
tag = "v${version}";
hash = "sha256-lP6Iil/BUv4ga+co+oBpKv1FBqFuBGfNjueEolM6png=";
};
meta = {
description = "Efficient querying of 'top values' for PostgreSQL";
homepage = "https://github.com/citusdata/postgresql-topn";
changelog = "https://github.com/citusdata/postgresql-topn/raw/v${version}/CHANGELOG.md";
maintainers = with lib.maintainers; [ thoughtpolice ];
platforms = postgresql.meta.platforms;
license = lib.licenses.agpl3Only;
};
}

View File

@@ -0,0 +1,27 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pg_uuidv7";
version = "1.6.0";
src = fetchFromGitHub {
owner = "fboulnois";
repo = "pg_uuidv7";
tag = "v${finalAttrs.version}";
hash = "sha256-lG6dCnbLALnfQc4uclqXXXfYjK/WXLV0lo5I8l1E5p4=";
};
meta = {
description = "Tiny Postgres extension to create version 7 UUIDs";
homepage = "https://github.com/fboulnois/pg_uuidv7";
changelog = "https://github.com/fboulnois/pg_uuidv7/blob/main/CHANGELOG.md";
maintainers = with lib.maintainers; [ gaelreyrol ];
platforms = postgresql.meta.platforms;
license = lib.licenses.mpl20;
};
})

View File

@@ -0,0 +1,70 @@
{
fetchFromGitHub,
lib,
libkrb5,
openssl,
postgresql,
postgresqlBuildExtension,
}:
let
sources = {
# v18: No upstream ticket, yet (2025-07-07)
"17" = {
version = "17.1";
hash = "sha256-9St/ESPiFq2NiPKqbwHLwkIyATKUkOGxFcUrWgT+Iqo=";
};
"16" = {
version = "16.1";
hash = "sha256-fzoAcXEKmA+xD4HtcHZgcduh1XmSgL8ZS4R72og7RGQ=";
};
"15" = {
version = "1.7.1";
hash = "sha256-emwoTowT7WKFX0RQDqJXjIblrzqaUIUkzqSqBCHVKQ8=";
};
"14" = {
version = "1.6.3";
hash = "sha256-KgLidJHjUK9BTp6ffmGUj1chcwIe6IzlcadRpGCfNdM=";
};
"13" = {
version = "1.5.3";
hash = "sha256-IU4Clec3DkKWT7+kw0VtQNybt94i7M2rSSgJG/XdcRs=";
};
};
source =
sources.${lib.versions.major postgresql.version} or {
version = "";
hash = throw "Source for pgaudit is not available for ${postgresql.version}";
};
in
postgresqlBuildExtension {
pname = "pgaudit";
inherit (source) version;
src = fetchFromGitHub {
owner = "pgaudit";
repo = "pgaudit";
tag = source.version;
inherit (source) hash;
};
buildInputs = [
libkrb5
openssl
];
makeFlags = [ "USE_PGXS=1" ];
enableUpdateScript = false;
meta = {
broken = !builtins.elem (lib.versions.major postgresql.version) (builtins.attrNames sources);
description = "Open Source PostgreSQL Audit Logging";
homepage = "https://github.com/pgaudit/pgaudit";
changelog = "https://github.com/pgaudit/pgaudit/releases/tag/${source.version}";
maintainers = with lib.maintainers; [ idontgetoutmuch ];
platforms = postgresql.meta.platforms;
license = lib.licenses.postgresql;
};
}

View File

@@ -0,0 +1,49 @@
{
fetchFromGitHub,
lib,
perl,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pgddl";
version = "0.30";
src = fetchFromGitHub {
owner = "lacanoid";
repo = "pgddl";
tag = finalAttrs.version;
hash = "sha256-w08IgnobIhlwRGrz+feEnZbI1KrWrMRI4BvNVUZFSSg=";
};
nativeBuildInputs = [
perl
];
preBuild = ''
patchShebangs --build ./bin/ ./docs
'';
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = ''
CREATE EXTENSION ddlx;
CREATE TABLE a(i int PRIMARY KEY, j int);
SELECT ddlx_create('a'::regclass);
SELECT ddlx_drop('a'::regclass);
SELECT ddlx_script('a'::regclass);
'';
};
meta = {
description = "DDL eXtractor functions for PostgreSQL";
homepage = "https://github.com/lacanoid/pgddl";
changelog = "https://github.com/lacanoid/pgddl/releases/tag/${finalAttrs.version}";
platforms = postgresql.meta.platforms;
maintainers = [ lib.maintainers.joshainglis ];
license = lib.licenses.postgresql;
};
})

View File

@@ -0,0 +1,45 @@
{
fetchFromGitHub,
lib,
nixosTests,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
unstableGitUpdater,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pgjwt";
version = "0-unstable-2023-03-02";
src = fetchFromGitHub {
owner = "michelp";
repo = "pgjwt";
rev = "f3d82fd30151e754e19ce5d6a06c71c20689ce3d";
hash = "sha256-nDZEDf5+sFc1HDcG2eBNQj+kGcdAYRXJseKi9oww+JU=";
};
passthru.updateScript = unstableGitUpdater { };
passthru.tests = lib.recurseIntoAttrs {
pgjwt = nixosTests.postgresql.pgjwt.passthru.override postgresql;
extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = ''
CREATE EXTENSION pgjwt CASCADE;
SELECT sign('{"sub":"1234567890","name":"John Doe","admin":true}', 'secret');
'';
};
};
meta = {
description = "PostgreSQL implementation of JSON Web Tokens";
longDescription = ''
sign() and verify() functions to create and verify JSON Web Tokens.
'';
license = lib.licenses.mit;
platforms = postgresql.meta.platforms;
maintainers = with lib.maintainers; [ spinus ];
};
})

View File

@@ -0,0 +1,31 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pgmq";
version = "1.7.0";
src = fetchFromGitHub {
owner = "tembo-io";
repo = "pgmq";
tag = "v${finalAttrs.version}";
hash = "sha256-CnXweDsLO2yE+z1tPADqz54Q1rswsKoUVYbdiZFEbPs=";
};
sourceRoot = "${finalAttrs.src.name}/pgmq-extension";
dontConfigure = true;
meta = {
description = "Lightweight message queue like AWS SQS and RSMQ but on Postgres";
homepage = "https://tembo.io/pgmq";
changelog = "https://github.com/tembo-io/pgmq/releases/tag/v${finalAttrs.version}";
maintainers = with lib.maintainers; [ takeda ];
platforms = postgresql.meta.platforms;
license = lib.licenses.postgresql;
};
})

View File

@@ -0,0 +1,50 @@
{
fetchFromGitHub,
groonga,
lib,
msgpack-c,
pkg-config,
postgresql,
postgresqlBuildExtension,
xxHash,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pgroonga";
version = "4.0.4";
src = fetchFromGitHub {
owner = "pgroonga";
repo = "pgroonga";
tag = "${finalAttrs.version}";
hash = "sha256-SXQH+L7FKhu+2+9QyQTNi+3nFYtkE7WXv2A5LdvjG2w=";
};
nativeBuildInputs = [ pkg-config ];
buildInputs = [
msgpack-c
groonga
xxHash
];
makeFlags = [
"HAVE_XXHASH=1"
"HAVE_MSGPACK=1"
"MSGPACK_PACKAGE_NAME=msgpack-c"
];
meta = {
description = "PostgreSQL extension to use Groonga as the index";
longDescription = ''
PGroonga is a PostgreSQL extension to use Groonga as the index.
PostgreSQL supports full text search against languages that use only alphabet and digit.
It means that PostgreSQL doesn't support full text search against Japanese, Chinese and so on.
You can use super fast full text search feature against all languages by installing PGroonga into your PostgreSQL.
'';
homepage = "https://pgroonga.github.io/";
changelog = "https://github.com/pgroonga/pgroonga/releases/tag/${finalAttrs.version}";
license = lib.licenses.postgresql;
platforms = postgresql.meta.platforms;
maintainers = with lib.maintainers; [ DerTim1 ];
};
})

View File

@@ -0,0 +1,37 @@
{
boost,
cmake,
fetchFromGitHub,
lib,
perl,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pgrouting";
version = "3.8.0";
nativeBuildInputs = [
cmake
perl
];
buildInputs = [ boost ];
src = fetchFromGitHub {
owner = "pgRouting";
repo = "pgrouting";
tag = "v${finalAttrs.version}";
hash = "sha256-Lvf7TQ3GywbzZmcd9wi3s8I5sCXIQAPeXNTRk/J46to=";
};
meta = {
description = "PostgreSQL/PostGIS extension that provides geospatial routing functionality";
homepage = "https://pgrouting.org/";
changelog = "https://github.com/pgRouting/pgrouting/releases/tag/v${finalAttrs.version}";
maintainers = with lib.maintainers; [ steve-chavez ];
teams = [ lib.teams.geospatial ];
platforms = postgresql.meta.platforms;
license = lib.licenses.gpl2Plus;
};
})

View File

@@ -0,0 +1,55 @@
{
bash,
fetchFromGitHub,
lib,
libsodium,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pgsodium";
version = "3.1.9";
src = fetchFromGitHub {
owner = "michelp";
repo = "pgsodium";
tag = "v${finalAttrs.version}";
hash = "sha256-Y8xL3PxF1GQV1JIgolMI1e8oGcUvWAgrPv84om7wKP8=";
};
buildInputs = [
bash # required for patchShebangs
libsodium
];
postInstall = ''
install -D -t $out/share/pgsodium/getkey_scripts getkey_scripts/*
ln -s $out/share/pgsodium/getkey_scripts/pgsodium_getkey_urandom.sh $out/share/postgresql/extension/pgsodium_getkey
'';
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
postgresqlExtraSettings = ''
shared_preload_libraries=pgsodium
'';
sql = ''
CREATE EXTENSION pgsodium;
SELECT pgsodium.version();
SELECT pgsodium.crypto_auth_keygen();
SELECT pgsodium.randombytes_random() FROM generate_series(0, 5);
SELECT * FROM pgsodium.crypto_box_new_keypair();
'';
};
meta = {
description = "Modern cryptography for PostgreSQL using libsodium";
homepage = "https://github.com/michelp/pgsodium";
changelog = "https://github.com/michelp/pgsodium/releases/tag/v${finalAttrs.version}";
license = lib.licenses.postgresql;
maintainers = [ ];
platforms = postgresql.meta.platforms;
};
})

View File

@@ -0,0 +1,31 @@
{
curl,
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pgsql-http";
version = "1.7.0";
src = fetchFromGitHub {
owner = "pramsey";
repo = "pgsql-http";
tag = "v${finalAttrs.version}";
hash = "sha256-tgmty8ZYpSEccwQouI/Ho2M495k6DizbMaaJ0+aW03Q=";
};
buildInputs = [ curl ];
nativeBuildInputs = [ curl ];
meta = {
description = "HTTP client for PostgreSQL, retrieve a web page from inside the database";
homepage = "https://github.com/pramsey/pgsql-http";
changelog = "https://github.com/pramsey/pgsql-http/releases/tag/v${finalAttrs.version}";
maintainers = [ ];
platforms = postgresql.meta.platforms;
license = lib.licenses.mit;
};
})

View File

@@ -0,0 +1,69 @@
{
fetchFromGitHub,
lib,
perl,
perlPackages,
postgresql,
postgresqlBuildExtension,
postgresqlTestHook,
stdenv,
which,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pgtap";
version = "1.3.3";
src = fetchFromGitHub {
owner = "theory";
repo = "pgtap";
tag = "v${finalAttrs.version}";
hash = "sha256-YgvfLGF7pLVcCKD66NnWAydDxtoYHH1DpLiYTEKHJ0E=";
};
nativeBuildInputs = [
perl
perlPackages.TAPParserSourceHandlerpgTAP
which
];
passthru.tests.extension = stdenv.mkDerivation {
name = "pgtap-test";
dontUnpack = true;
doCheck = true;
nativeCheckInputs = [
postgresqlTestHook
(postgresql.withPackages (_: [ finalAttrs.finalPackage ]))
];
passAsFile = [ "sql" ];
sql = ''
CREATE EXTENSION pgtap;
BEGIN;
SELECT plan(1);
SELECT pass('Test passed');
SELECT * FROM finish();
ROLLBACK;
'';
checkPhase = ''
runHook preCheck
psql -a -v ON_ERROR_STOP=1 -f $sqlPath
runHook postCheck
'';
installPhase = "touch $out";
};
meta = {
description = "Unit testing framework for PostgreSQL";
longDescription = ''
pgTAP is a unit testing framework for PostgreSQL written in PL/pgSQL and PL/SQL.
It includes a comprehensive collection of TAP-emitting assertion functions,
as well as the ability to integrate with other TAP-emitting test frameworks.
It can also be used in the xUnit testing style.
'';
maintainers = [ ];
homepage = "https://pgtap.org";
inherit (postgresql.meta) platforms;
license = lib.licenses.mit;
};
})

View File

@@ -0,0 +1,19 @@
diff --git a/crates/c/build.rs b/crates/c/build.rs
index 8d822e5..8b7e371 100644
--- a/crates/c/build.rs
+++ b/crates/c/build.rs
@@ -1,9 +1,13 @@
fn main() {
println!("cargo:rerun-if-changed=src/f16.h");
println!("cargo:rerun-if-changed=src/f16.c");
+ println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS");
cc::Build::new()
- .compiler("clang-16")
+ .compiler("@clang@")
.file("./src/f16.c")
+ // read env var set by rustPlatform.bindgenHook
+ .try_flags_from_environment("BINDGEN_EXTRA_CLANG_ARGS")
+ .expect("the BINDGEN_EXTRA_CLANG_ARGS environment variable must be specified and UTF-8")
.opt_level(3)
.debug(true)
.compile("vectorsc");

View File

@@ -0,0 +1,21 @@
diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs
index 18172b9..6fc7e82 100644
--- a/crates/common/src/lib.rs
+++ b/crates/common/src/lib.rs
@@ -1,3 +1,4 @@
+#![warn(dangerous_implicit_autorefs)]
pub mod clean;
pub mod dir_ops;
pub mod file_atomic;
diff --git a/src/lib.rs b/src/lib.rs
index 068c65d..82609e9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,6 +6,7 @@
#![allow(clippy::needless_range_loop)]
#![allow(clippy::single_match)]
#![allow(clippy::too_many_arguments)]
+#![warn(dangerous_implicit_autorefs)]
mod bgworker;
mod datatype;

View File

@@ -0,0 +1,119 @@
{
buildPgrxExtension,
cargo-pgrx_0_12_0_alpha_1,
clang,
fetchFromGitHub,
lib,
nix-update-script,
openssl,
pkg-config,
postgresql,
postgresqlTestExtension,
replaceVars,
}:
buildPgrxExtension (finalAttrs: {
inherit postgresql;
cargo-pgrx = cargo-pgrx_0_12_0_alpha_1;
pname = "pgvecto-rs";
version = "0.3.0";
buildInputs = [ openssl ];
nativeBuildInputs = [ pkg-config ];
patches = [
# Tell the `c` crate to use the flags from the rust bindgen hook
(replaceVars ./0001-read-clang-flags-from-environment.diff {
clang = lib.getExe clang;
})
# Rust 1.89 denies implicit autorefs by default, making the compilation fail.
# This restores the behaviour of previous rust versions by making the lint throw a warning instead.
./0002-allow-dangerous-implicit-autorefs.diff
];
src = fetchFromGitHub {
owner = "tensorchord";
repo = "pgvecto.rs";
tag = "v${finalAttrs.version}";
hash = "sha256-X7BY2Exv0xQNhsS/GA7GNvj9OeVDqVCd/k3lUkXtfgE=";
};
cargoHash = "sha256-8otJ1uqGrCmlxAqvfAL3OjhBI4I6dAu6EoajstO46Sw=";
# Set appropriate version on vectors.control, otherwise it won't show up on PostgreSQL
postPatch = ''
substituteInPlace ./vectors.control --subst-var-by CARGO_VERSION ${finalAttrs.version}
'';
# Include upgrade scripts in the final package
# https://github.com/tensorchord/pgvecto.rs/blob/v0.2.0/scripts/ci_package.sh#L6-L8
postInstall = ''
cp sql/upgrade/* $out/share/postgresql/extension/
'';
env = {
# Needed to get openssl-sys to use pkg-config.
OPENSSL_NO_VENDOR = 1;
# Bypass rust nightly features not being available on rust stable
RUSTC_BOOTSTRAP = 1;
};
# This crate does not have the "pg_test" feature
usePgTestCheckFeature = false;
passthru = {
updateScript = nix-update-script { };
tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
postgresqlExtraSettings = ''
shared_preload_libraries='vectors'
'';
sql = ''
CREATE EXTENSION vectors;
CREATE TABLE items (
id bigserial PRIMARY KEY,
content text NOT NULL,
embedding vectors.vector(3) NOT NULL -- 3 dimensions
);
INSERT INTO items (content, embedding) VALUES
('a fat cat sat on a mat and ate a fat rat', '[1, 2, 3]'),
('a fat dog sat on a mat and ate a fat rat', '[4, 5, 6]'),
('a thin cat sat on a mat and ate a thin rat', '[7, 8, 9]'),
('a thin dog sat on a mat and ate a thin rat', '[10, 11, 12]');
'';
asserts = [
{
query = "SELECT default_version FROM pg_available_extensions WHERE name = 'vectors'";
expected = "'${finalAttrs.version}'";
description = "Extension vectors has correct version.";
}
{
query = "SELECT COUNT(embedding) FROM items WHERE to_tsvector('english', content) @@ 'cat & rat'::tsquery";
expected = "2";
description = "Stores and returns vectors.";
}
];
};
};
meta = {
# Upstream removed support for PostgreSQL 13 on 0.3.0: https://github.com/tensorchord/pgvecto.rs/issues/343
broken =
(lib.versionOlder postgresql.version "14")
||
# PostgreSQL 17 support issue upstream: https://github.com/tensorchord/pgvecto.rs/issues/607
# Check after next package update.
lib.versionAtLeast postgresql.version "17" && finalAttrs.version == "0.3.0";
description = "Scalable, Low-latency and Hybrid-enabled Vector Search in Postgres";
homepage = "https://github.com/tensorchord/pgvecto.rs";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [
diogotcorreia
esclear
];
};
})

View File

@@ -0,0 +1,27 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "pgvector";
version = "0.8.1";
src = fetchFromGitHub {
owner = "pgvector";
repo = "pgvector";
tag = "v${finalAttrs.version}";
hash = "sha256-4EqazYWstczL9T3YFqq2gtbcKIj6zWU8ItYt2nnwPYo=";
};
meta = {
description = "Open-source vector similarity search for PostgreSQL";
homepage = "https://github.com/pgvector/pgvector";
changelog = "https://github.com/pgvector/pgvector/raw/v${finalAttrs.version}/CHANGELOG.md";
license = lib.licenses.postgresql;
platforms = postgresql.meta.platforms;
maintainers = [ ];
};
})

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,80 @@
{
buildPgrxExtension,
cargo-pgrx_0_12_6,
postgresql,
fetchFromGitHub,
lib,
postgresqlTestExtension,
}:
buildPgrxExtension (finalAttrs: {
pname = "pgvectorscale";
version = "0.7.0";
src = fetchFromGitHub {
owner = "timescale";
repo = "pgvectorscale";
tag = finalAttrs.version;
hash = "sha256-dy481k2SvyYXwwcsyLZSl3XlhSk9C5+4LfEfciB1DK4=";
};
doCheck = false;
cargoHash = "sha256-CeRyDn9VhxfjWFJ1/Z/XvOUQOSnDoHHZAqgfYTeKU0o=";
cargoPatches = [
./add-Cargo.lock.patch
];
cargoPgrxFlags = [
"-p"
"vectorscale"
];
inherit postgresql;
cargo-pgrx = cargo-pgrx_0_12_6;
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
withPackages = [ "pgvector" ];
sql = ''
CREATE EXTENSION vectorscale CASCADE;
CREATE TABLE document_embedding (
id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
embedding VECTOR(3)
);
INSERT INTO document_embedding (id, embedding) VALUES
(10, '[1,2,4]'),
(20, '[1,2,5]');
CREATE INDEX document_embedding_idx ON document_embedding
USING diskann (embedding vector_cosine_ops);
'';
asserts = [
{
query = "SELECT id FROM document_embedding WHERE embedding <-> '[1,2,3]' = 1";
expected = "10";
description = "Expected vector of row with ID=10 to have an euclidean distance from [1,2,3] of 1.";
}
{
query = "SELECT id FROM document_embedding WHERE embedding <-> '[1,2,3]' = 2";
expected = "20";
description = "Expected vector of row with ID=20 to have an euclidean distance from [1,2,3] of 2.";
}
];
};
meta = {
# PostgreSQL 18 support issue upstream: https://github.com/timescale/pgvectorscale/issues/249
# Check after next package update.
broken =
lib.warnIf (finalAttrs.version != "0.7.0") "Is postgresql18Packages.pgvectorscale still broken?"
(lib.versionAtLeast postgresql.version "18");
homepage = "https://github.com/timescale/pgvectorscale";
teams = [ lib.teams.flyingcircus ];
description = "Complement to pgvector for high performance, cost efficient vector search on large workloads";
license = lib.licenses.postgresql;
platforms = postgresql.meta.platforms;
changelog = "https://github.com/timescale/pgvectorscale/releases/tag/${finalAttrs.version}";
};
})

View File

@@ -0,0 +1,58 @@
{
buildPgrxExtension,
cargo-pgrx_0_12_6,
fetchFromGitHub,
lib,
nix-update-script,
postgresql,
util-linux,
}:
buildPgrxExtension (finalAttrs: {
inherit postgresql;
cargo-pgrx = cargo-pgrx_0_12_6;
pname = "pgx_ulid";
version = "0.2.0";
src = fetchFromGitHub {
owner = "pksunkara";
repo = "pgx_ulid";
tag = "v${finalAttrs.version}";
hash = "sha256-VdLWwkUA0sVs5Z/Lyf5oTRhcHVzPmhgnYQhIM8MWJ0c=";
};
cargoHash = "sha256-OyrfwLMHn2aihfijHxE5oaz+XQC1HFlYbTp8Sw8RcK0=";
postInstall = ''
# Upstream renames the extension when packaging
# https://github.com/pksunkara/pgx_ulid/blob/084778c3e2af08d16ec5ec3ef4e8f345ba0daa33/.github/workflows/release.yml#L81
# Upgrade scripts should be added later, so we also rename them with wildcard
# https://github.com/pksunkara/pgx_ulid/issues/49
${util-linux}/bin/rename pgx_ulid ulid $out/share/postgresql/extension/pgx_ulid*
'';
# pgrx tests try to install the extension into postgresql nix store
doCheck = false;
passthru = {
updateScript = nix-update-script { };
};
meta = {
# Support for PostgreSQL 13 was removed in 0.2.0: https://github.com/pksunkara/pgx_ulid/blob/084778c3e2af08d16ec5ec3ef4e8f345ba0daa33/CHANGELOG.md?plain=1#L6
broken =
lib.versionOlder postgresql.version "14"
||
# PostgreSQL 18 support issue upstream: https://github.com/pksunkara/pgx_ulid/issues/65
# Note: already fixed on `master` branch.
# Check after next package update.
lib.warnIf (finalAttrs.version != "0.2.0") "Is postgresql18Packages.pgx_ulid still broken?" (
lib.versionAtLeast postgresql.version "18"
);
description = "ULID Postgres extension written in Rust";
homepage = "https://github.com/pksunkara/pgx_ulid";
changelog = "https://github.com/pksunkara/pgx_ulid/blob/v${finalAttrs.version}/CHANGELOG.md";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ myypo ];
};
})

View File

@@ -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
teams
platforms
;
description = "PL/Perl - Perl Procedural Language";
};
};
in
finalPackage;
in
withPackages (_: [ ])

View File

@@ -0,0 +1,34 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "plpgsql-check";
version = "2.8.2";
src = fetchFromGitHub {
owner = "okbob";
repo = "plpgsql_check";
tag = "v${finalAttrs.version}";
hash = "sha256-NjqnXbQ+wyKVFFdffOQpxrCWT9vrzgh8lk2G3L9i6G8=";
};
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = "CREATE EXTENSION plpgsql_check;";
};
meta = {
description = "Linter tool for language PL/pgSQL";
homepage = "https://github.com/okbob/plpgsql_check";
changelog = "https://github.com/okbob/plpgsql_check/releases/tag/v${finalAttrs.version}";
platforms = postgresql.meta.platforms;
license = lib.licenses.mit;
maintainers = [ ];
broken = lib.versionOlder postgresql.version "14";
};
})

View File

@@ -0,0 +1,45 @@
{
buildEnv,
postgresql,
postgresqlTestExtension,
python3,
}:
let
withPackages =
f:
let
python = python3.withPackages f;
finalPackage = buildEnv {
name = "${postgresql.pname}-plpython3-${postgresql.version}";
paths = [ postgresql.plpython3 ];
passthru = {
inherit withPackages;
wrapperArgs = [
''--set PYTHONPATH "${python}/${python.sitePackages}"''
];
tests.extension = postgresqlTestExtension {
finalPackage = finalPackage.withPackages (ps: [ ps.base58 ]);
sql = ''
CREATE EXTENSION plpython3u;
DO LANGUAGE plpython3u $$
import base58
$$;
'';
};
};
meta = {
inherit (postgresql.meta)
homepage
license
changelog
teams
platforms
;
description = "PL/Python - Python Procedural Language";
};
};
in
finalPackage;
in
withPackages (_: [ ])

View File

@@ -0,0 +1,67 @@
{
buildEnv,
fetchFromGitHub,
lib,
nix-update-script,
pkg-config,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
R,
rPackages,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "plr";
version = "8.4.8";
src = fetchFromGitHub {
owner = "postgres-plr";
repo = "plr";
tag = "REL${lib.replaceString "." "_" finalAttrs.version}";
hash = "sha256-FLL61HsZ6WaWBP9NqrJjhMFSVyVBIpVO0wv+kXMuAaU=";
};
nativeBuildInputs = [ pkg-config ];
buildInputs = [ R ];
makeFlags = [ "USE_PGXS=1" ];
passthru = {
updateScript = nix-update-script {
extraArgs = [ "--version-regex=^REL(\\d+)_(\\d+)_(\\d+)$" ];
};
withPackages =
f:
let
pkgs = f rPackages;
paths = lib.concatMapStringsSep ":" (pkg: "${pkg}/library") pkgs;
in
buildEnv {
name = "${finalAttrs.pname}-with-packages-${finalAttrs.version}";
paths = [ finalAttrs.finalPackage ];
passthru.wrapperArgs = [
''--set R_LIBS_SITE "${paths}"''
];
};
tests.extension = postgresqlTestExtension {
finalPackage = finalAttrs.finalPackage.withPackages (ps: [ ps.base64enc ]);
sql = ''
CREATE EXTENSION plr;
DO LANGUAGE plr $$
require('base64enc')
base64encode(1:100)
$$;
'';
};
};
meta = {
description = "PL/R - R Procedural Language for PostgreSQL";
homepage = "https://github.com/postgres-plr/plr";
changelog = "https://github.com/postgres-plr/plr/blob/${finalAttrs.src.rev}/changelog.md";
maintainers = with lib.maintainers; [ qoelet ];
platforms = postgresql.meta.platforms;
license = lib.licenses.gpl2Only;
};
})

View File

@@ -0,0 +1,52 @@
{
buildEnv,
lib,
postgresql,
postgresqlTestExtension,
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
teams
platforms
;
description = "PL/Tcl - Tcl Procedural Language";
};
};
in
finalPackage;
in
withPackages (_: [ ])

View File

@@ -0,0 +1,44 @@
diff --git a/Makefile b/Makefile
index a705c11..08b952b 100644
--- a/Makefile
+++ b/Makefile
@@ -13,11 +13,14 @@ OBJS = $(SRCS:.cc=.o)
MODULE_big = plv8-$(PLV8_VERSION)
EXTENSION = plv8
PLV8_DATA = plv8.control plv8--$(PLV8_VERSION).sql
+USE_SYSTEM_V8 = 0
ifeq ($(OS),Windows_NT)
# noop for now
else
+ ifeq ($(USE_SYSTEM_V8),0)
SHLIB_LINK += -Ldeps/v8-cmake/build
+ endif
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
CCFLAGS += -stdlib=libc++
@@ -34,6 +37,7 @@ ifeq ($(NUMPROC),0)
NUMPROC = 1
endif
+ifeq ($(USE_SYSTEM_V8),0)
SHLIB_LINK += -Ldeps/v8-cmake/build
all: v8 $(OBJS)
@@ -46,11 +50,16 @@ deps/v8-cmake/build/libv8_libbase.a:
@cd deps/v8-cmake && mkdir -p build && cd build && cmake -Denable-fPIC=ON -DCMAKE_BUILD_TYPE=Release ../ && make -j $(NUMPROC)
v8: deps/v8-cmake/build/libv8_libbase.a
+else
+all: $(OBJS)
+endif
# enable direct jsonb conversion by default
CCFLAGS += -DJSONB_DIRECT_CONVERSION
+ifeq ($(USE_SYSTEM_V8),0)
CCFLAGS += -Ideps/v8-cmake/v8/include -std=c++17
+endif
ifdef EXECUTION_TIMEOUT
CCFLAGS += -DEXECUTION_TIMEOUT

View File

@@ -0,0 +1,141 @@
{
fetchFromGitHub,
lib,
nodejs_20,
perl,
postgresql,
postgresqlBuildExtension,
stdenv,
# For test
coreutils,
gnugrep,
runCommand,
}:
let
libv8 = nodejs_20.libv8;
in
postgresqlBuildExtension (finalAttrs: {
pname = "plv8";
version = "3.2.4";
src = fetchFromGitHub {
owner = "plv8";
repo = "plv8";
tag = "v${finalAttrs.version}";
hash = "sha256-v4r/6qwDwb3+PQPYV3FqmIcDEkSr8F46PVlFnhUWUGc=";
};
patches = [
# Allow building with system v8.
# https://github.com/plv8/plv8/pull/505 (rejected)
./0001-build-Allow-using-V8-from-system.patch
];
nativeBuildInputs = [
perl
];
buildInputs = [
libv8
];
buildFlags = [ "all" ];
makeFlags = [
# Nixpkgs build a v8 monolith instead of separate v8_libplatform.
"USE_SYSTEM_V8=1"
"SHLIB_LINK=-lv8"
"V8_OUTDIR=${libv8}/lib"
];
# No configure script.
dontConfigure = true;
postPatch = ''
patchShebangs ./generate_upgrade.sh
'';
passthru = {
tests =
let
postgresqlWithSelf = postgresql.withPackages (_: [
finalAttrs.finalPackage
]);
in
{
smoke = runCommand "plv8-smoke-test" { } ''
export PATH=${
lib.makeBinPath [
postgresqlWithSelf
coreutils
gnugrep
]
}
db="$PWD/testdb"
initdb "$db"
postgres -k "$db" -D "$db" &
pid="$!"
for i in $(seq 1 100); do
if psql -h "$db" -d postgres -c "" 2>/dev/null; then
break
elif ! kill -0 "$pid"; then
exit 1
else
sleep 0.1
fi
done
psql -h "$db" -d postgres -c 'CREATE EXTENSION plv8; DO $$ plv8.elog(NOTICE, plv8.version); $$ LANGUAGE plv8;' 2> "$out"
grep -q "${finalAttrs.version}" "$out"
kill -0 "$pid"
'';
regression = stdenv.mkDerivation {
name = "plv8-regression";
inherit (finalAttrs)
src
patches
nativeBuildInputs
buildInputs
dontConfigure
;
buildPhase = ''
runHook preBuild
# The regression tests need to be run in the order specified in the Makefile.
echo -e "include Makefile\nprint_regress_files:\n\t@echo \$(REGRESS)" > Makefile.regress
REGRESS_TESTS=$(make -f Makefile.regress print_regress_files)
${lib.getDev postgresql}/lib/pgxs/src/test/regress/pg_regress \
--bindir='${postgresqlWithSelf}/bin' \
--temp-instance=regress-instance \
--dbname=contrib_regression \
$REGRESS_TESTS
runHook postBuild
'';
installPhase = ''
runHook preInstall
touch "$out"
runHook postInstall
'';
};
};
};
meta = {
description = "V8 Engine Javascript Procedural Language add-on for PostgreSQL";
homepage = "https://plv8.github.io/";
changelog = "https://github.com/plv8/plv8/blob/v${finalAttrs.version}/Changes";
maintainers = [ ];
platforms = postgresql.meta.platforms;
license = lib.licenses.postgresql;
broken = stdenv.hostPlatform.isDarwin;
};
})

View File

@@ -0,0 +1,178 @@
{
autoconf,
automake,
cunit,
docbook5,
fetchFromGitHub,
gdalMinimal,
geos,
jitSupport,
json_c,
lib,
libiconv,
libtool,
libxml2,
libxslt,
llvm,
pcre2,
perl,
pkg-config,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
postgresqlTestHook,
proj,
protobufc,
stdenv,
which,
withSfcgal ? false,
sfcgal,
}:
let
gdal = gdalMinimal;
in
postgresqlBuildExtension (finalAttrs: {
pname = "postgis";
version = "3.6.0";
outputs = [
"out"
"doc"
];
src = fetchFromGitHub {
owner = "postgis";
repo = "postgis";
tag = finalAttrs.version;
hash = "sha256-L8k3yk1Dn4Dk7UyHse+8RJsjYsYMebdsiZp6fS7cC0Y=";
};
buildInputs = [
geos
proj
gdal
json_c
protobufc
pcre2.dev
]
++ lib.optional stdenv.hostPlatform.isDarwin libiconv
++ lib.optional withSfcgal sfcgal;
nativeBuildInputs = [
autoconf
automake
libtool
libxml2
perl
pkg-config
protobufc
which
]
++ lib.optional jitSupport llvm;
dontDisableStatic = true;
checkInputs = [
cunit
];
nativeCheckInputs = [
postgresql
postgresqlTestHook
libxslt
];
postgresqlTestUserOptions = "LOGIN SUPERUSER";
# postgis config directory assumes /include /lib from the same root for json-c library
env.NIX_LDFLAGS = "-L${lib.getLib json_c}/lib";
setOutputFlags = false;
preConfigure = ''
./autogen.sh
'';
configureFlags =
let
isCross = stdenv.hostPlatform.config != stdenv.buildPlatform.config;
in
[
(lib.enableFeature false "extension-upgrades-install")
(lib.withFeatureAs true "pgconfig" "${postgresql.pg_config}/bin/pg_config")
(lib.withFeatureAs true "gdalconfig" "${gdal}/bin/gdal-config")
(lib.withFeatureAs true "jsondir" (lib.getDev json_c))
(lib.withFeatureAs true "xml2config" (lib.getExe' (lib.getDev libxml2) "xml2-config"))
(lib.withFeatureAs withSfcgal "sfcgal" "${sfcgal}/bin/sfcgal-config")
(lib.withFeature (!isCross) "json") # configure: error: cannot check for file existence when cross compiling
];
makeFlags = [
"PERL=${perl}/bin/perl"
];
doCheck = stdenv.hostPlatform.isLinux;
preCheck = ''
substituteInPlace doc/postgis-out.xml --replace-fail "http://docbook.org/xml/5.0/dtd/docbook.dtd" "${docbook5}/xml/dtd/docbook/docbookx.dtd"
# The test suite hardcodes it to use /tmp.
export PGIS_REG_TMPDIR="$TMPDIR/pgis_reg"
'';
# create aliases for all commands adding version information
postInstall = ''
for prog in $out/bin/*; do # */
ln -s $prog $prog-${finalAttrs.version}
done
mkdir -p $doc/share/doc/postgis
mv doc/* $doc/share/doc/postgis/
'';
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = ''
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_raster;
CREATE EXTENSION postgis_topology;
-- st_makepoint goes through c code
select st_makepoint(1, 1);
''
+ lib.optionalString withSfcgal ''
CREATE EXTENSION postgis_sfcgal;
CREATE TABLE geometries (
name varchar,
geom geometry(PolygonZ) NOT NULL
);
INSERT INTO geometries(name, geom) VALUES
('planar geom', 'PolygonZ((1 1 0, 1 2 0, 2 2 0, 2 1 0, 1 1 0))'),
('nonplanar geom', 'PolygonZ((1 1 1, 1 2 -1, 2 2 2, 2 1 0, 1 1 1))');
SELECT name from geometries where cg_isplanar(geom);
'';
asserts = [
{
query = "postgis_version()";
expected = "'${lib.versions.major finalAttrs.version}.${lib.versions.minor finalAttrs.version} USE_GEOS=1 USE_PROJ=1 USE_STATS=1'";
description = "postgis_version() returns correct values.";
}
]
++ lib.optional withSfcgal {
query = "postgis_sfcgal_version()";
expected = "'${sfcgal.version}'";
description = "postgis_sfcgal_version() returns correct value.";
};
};
meta = {
description = "Geographic Objects for PostgreSQL";
homepage = "https://postgis.net/";
changelog = "https://git.osgeo.org/gitea/postgis/postgis/raw/tag/${finalAttrs.version}/NEWS";
license = lib.licenses.gpl2Plus;
maintainers = with lib.maintainers; [ marcweber ];
teams = [ lib.teams.geospatial ];
inherit (postgresql.meta) platforms;
};
})

View File

@@ -0,0 +1,36 @@
{
curl,
fetchFromGitHub,
flex,
json_c,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "repmgr";
version = "5.5.0";
src = fetchFromGitHub {
owner = "EnterpriseDB";
repo = "repmgr";
tag = "v${finalAttrs.version}";
hash = "sha256-8G2CzzkWTKEglpUt1Gr7d/DuHJvCIEjsbYDMl3Zt3cs=";
};
nativeBuildInputs = [ flex ];
buildInputs = postgresql.buildInputs ++ [
curl
json_c
];
meta = {
homepage = "https://repmgr.org/";
description = "Replication manager for PostgreSQL cluster";
license = lib.licenses.postgresql;
platforms = postgresql.meta.platforms;
maintainers = with lib.maintainers; [ zimbatm ];
};
})

View File

@@ -0,0 +1,43 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "rum";
version = "1.3.14";
src = fetchFromGitHub {
owner = "postgrespro";
repo = "rum";
tag = finalAttrs.version;
hash = "sha256-VsfpxQqRBu9bIAP+TfMRXd+B3hSjuhU2NsutocNiCt8=";
};
makeFlags = [ "USE_PGXS=1" ];
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = ''
CREATE EXTENSION rum;
CREATE TABLE test_table (t text, v tsvector);
CREATE INDEX test_table_rumindex ON test_table USING rum (v rum_tsvector_ops);
'';
};
meta = {
# PostgreSQL 18 support issue upstream: https://github.com/postgrespro/rum/issues/156
# Check after next package update.
broken = lib.warnIf (finalAttrs.version != "1.3.14") "Is postgresql18Packages.rum still broken?" (
lib.versionAtLeast postgresql.version "18"
);
description = "Full text search index method for PostgreSQL";
homepage = "https://github.com/postgrespro/rum";
license = lib.licenses.postgresql;
platforms = postgresql.meta.platforms;
maintainers = with lib.maintainers; [ DeeUnderscore ];
};
})

View File

@@ -0,0 +1,29 @@
{
fetchgit,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension {
pname = "smlar-unstable";
version = "2021-11-08";
src = fetchgit {
url = "git://sigaev.ru/smlar.git";
rev = "f2522d5f20a46a3605a761d34a3aefcdffb94e71";
hash = "sha256-AC6w7uYw0OW70pQpWbK1A3rkCnMvTJzTCAdFiY3rO7A=";
};
makeFlags = [ "USE_PGXS=1" ];
meta = {
description = "Compute similary of any one-dimensional arrays";
homepage = "http://sigaev.ru/git/gitweb.cgi?p=smlar.git";
platforms = postgresql.meta.platforms;
license = lib.licenses.bsd2;
maintainers = [ ];
# Broken with no upstream fix available.
broken = lib.versionAtLeast postgresql.version "16";
};
}

View File

@@ -0,0 +1,38 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
sqlite,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "sqlite_fdw";
version = "2.5.0";
src = fetchFromGitHub {
owner = "pgspider";
repo = "sqlite_fdw";
tag = "v${finalAttrs.version}";
hash = "sha256-zPVIFzUv6UFFHq0Zi5MeQOcvgsfZAKGkkNIGxkTJ+oo=";
};
buildInputs = [ sqlite ];
makeFlags = [ "USE_PGXS=1" ];
meta = {
# PostgreSQL 18 support issue upstream: https://github.com/pgspider/sqlite_fdw/issues/117
# Note: already fixed on `master` branch.
# Check after next package update.
broken = lib.warnIf (
finalAttrs.version != "2.5.0"
) "Is postgresql18Packages.sqlite_fdw still broken?" (lib.versionAtLeast postgresql.version "18");
description = "SQLite Foreign Data Wrapper for PostgreSQL";
homepage = "https://github.com/pgspider/sqlite_fdw";
changelog = "https://github.com/pgspider/sqlite_fdw/releases/tag/v${finalAttrs.version}";
maintainers = with lib.maintainers; [ apfelkuchen6 ];
platforms = lib.platforms.unix;
license = lib.licenses.postgresql;
};
})

View File

@@ -0,0 +1,28 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "system_stats";
version = "3.2";
src = fetchFromGitHub {
owner = "EnterpriseDB";
repo = "system_stats";
tag = "v${finalAttrs.version}";
hash = "sha256-/xXnui0S0ZjRw7P8kMAgttHVv8T41aOhM3pM8P0OTig=";
};
buildFlags = [ "PG_CFLAGS=-Wno-error=vla" ];
meta = {
description = "Postgres extension for exposing system metrics such as CPU, memory and disk information";
homepage = "https://github.com/EnterpriseDB/system_stats";
changelog = "https://github.com/EnterpriseDB/system_stats/raw/v${finalAttrs.version}/CHANGELOG.md";
maintainers = with lib.maintainers; [ shivaraj-bh ];
platforms = postgresql.meta.platforms;
license = lib.licenses.postgresql;
};
})

View File

@@ -0,0 +1,30 @@
{
fetchFromGitHub,
freetds,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "tds_fdw";
version = "2.0.5";
buildInputs = [ freetds ];
src = fetchFromGitHub {
owner = "tds-fdw";
repo = "tds_fdw";
tag = "v${finalAttrs.version}";
hash = "sha256-4ecdErksaZ7SyCKzvSY5sD7rrKljq7BMn+gI9Yz49r0=";
};
meta = {
description = "PostgreSQL foreign data wrapper to connect to TDS databases (Sybase and Microsoft SQL Server)";
homepage = "https://github.com/tds-fdw/tds_fdw";
changelog = "https://github.com/tds-fdw/tds_fdw/releases/tag/v${finalAttrs.version}";
maintainers = with lib.maintainers; [ steve-chavez ];
platforms = postgresql.meta.platforms;
license = lib.licenses.postgresql;
};
})

View File

@@ -0,0 +1,26 @@
{
fetchFromGitHub,
lib,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "temporal_tables";
version = "1.2.2";
src = fetchFromGitHub {
owner = "arkhipov";
repo = "temporal_tables";
tag = "v${finalAttrs.version}";
hash = "sha256-7+DCSPAPhsokWDq/5IXNhd7jY6FfzxxUjlsg/VJeD3k=";
};
meta = {
description = "Temporal Tables PostgreSQL Extension";
homepage = "https://github.com/arkhipov/temporal_tables";
maintainers = with lib.maintainers; [ ggpeti ];
platforms = postgresql.meta.platforms;
license = lib.licenses.bsd2;
};
})

View File

@@ -0,0 +1,113 @@
{
cmake,
fetchFromGitHub,
lib,
libkrb5,
openssl,
postgresql,
postgresqlBuildExtension,
postgresqlTestExtension,
enableUnfree ? true,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "timescaledb${lib.optionalString (!enableUnfree) "-apache"}";
version = "2.22.1";
src = fetchFromGitHub {
owner = "timescale";
repo = "timescaledb";
tag = finalAttrs.version;
hash = "sha256-SEuxHbSxgTC4Uk6nnznVzUqvoZMGgF+KSMNzkYfgfpI=";
};
nativeBuildInputs = [ cmake ];
buildInputs = [
openssl
libkrb5
];
cmakeFlags = [
(lib.cmakeBool "SEND_TELEMETRY_DEFAULT" false)
(lib.cmakeBool "REGRESS_CHECKS" false)
(lib.cmakeBool "TAP_CHECKS" false)
(lib.cmakeBool "APACHE_ONLY" (!enableUnfree))
];
# Fix the install phase which tries to install into the pgsql extension dir,
# and cannot be manually overridden. This is rather fragile but works OK.
postPatch = ''
for x in CMakeLists.txt sql/CMakeLists.txt; do
substituteInPlace "$x" \
--replace-fail 'DESTINATION "''${PG_SHAREDIR}/extension"' "DESTINATION \"$out/share/postgresql/extension\""
done
for x in src/CMakeLists.txt src/loader/CMakeLists.txt tsl/src/CMakeLists.txt; do
substituteInPlace "$x" \
--replace-fail 'DESTINATION ''${PG_PKGLIBDIR}' "DESTINATION \"$out/lib\""
done
'';
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
withPackages = [ "timescaledb_toolkit" ];
postgresqlExtraSettings = ''
shared_preload_libraries='timescaledb'
'';
sql = ''
CREATE EXTENSION timescaledb;
CREATE EXTENSION timescaledb_toolkit;
CREATE TABLE sth (
time TIMESTAMPTZ NOT NULL,
value DOUBLE PRECISION
);
SELECT create_hypertable('sth', 'time');
INSERT INTO sth (time, value) VALUES
('2003-04-12 04:05:06 America/New_York', 1.0),
('2003-04-12 04:05:07 America/New_York', 2.0),
('2003-04-12 04:05:08 America/New_York', 3.0),
('2003-04-12 04:05:09 America/New_York', 4.0),
('2003-04-12 04:05:10 America/New_York', 5.0)
;
WITH t AS (
SELECT
time_bucket('1 day'::interval, time) AS dt,
stats_agg(value) AS stats
FROM sth
GROUP BY time_bucket('1 day'::interval, time)
)
SELECT
average(stats)
FROM t;
'';
asserts = [
{
query = "SELECT count(*) FROM sth";
expected = "5";
description = "hypertable can be queried successfully.";
}
];
};
meta = {
description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space";
homepage = "https://www.timescale.com/";
changelog = "https://github.com/timescale/timescaledb/blob/${finalAttrs.version}/CHANGELOG.md";
maintainers = with lib.maintainers; [ kirillrdy ];
platforms = postgresql.meta.platforms;
license = with lib.licenses; if enableUnfree then tsl else asl20;
broken =
lib.versionOlder postgresql.version "15"
||
# PostgreSQL 18 support issue upstream: https://github.com/timescale/timescaledb/issues/8233
# Check after next package update.
lib.warnIf (finalAttrs.version != "2.22.1") "Is postgresql18Packages.timescaledb still broken?" (
lib.versionAtLeast postgresql.version "18"
);
};
})

View File

@@ -0,0 +1,53 @@
{
buildPgrxExtension,
cargo-pgrx_0_12_6,
fetchFromGitHub,
lib,
nix-update-script,
postgresql,
}:
buildPgrxExtension (finalAttrs: {
inherit postgresql;
cargo-pgrx = cargo-pgrx_0_12_6;
pname = "timescaledb_toolkit";
version = "1.21.0";
src = fetchFromGitHub {
owner = "timescale";
repo = "timescaledb-toolkit";
tag = finalAttrs.version;
hash = "sha256-gGGSNvvJprqLkVwPr7cfmGY1qEUTXMdqdvwPYIzXaTA=";
};
cargoHash = "sha256-kyUpfNEXJ732VO6JDxU+dIoL57uWzG4Ff03/GnvsxLE=";
buildAndTestSubdir = "extension";
postInstall = ''
cargo run --manifest-path ./tools/post-install/Cargo.toml -- --dir "$out"
'';
passthru = {
updateScript = nix-update-script { };
tests = postgresql.pkgs.timescaledb.tests;
};
# tests take really long
doCheck = false;
meta = {
description = "Provide additional tools to ease all things analytic when using TimescaleDB";
homepage = "https://github.com/timescale/timescaledb-toolkit";
maintainers = with lib.maintainers; [ typetetris ];
platforms = postgresql.meta.platforms;
license = lib.licenses.tsl;
broken =
lib.versionOlder postgresql.version "15"
||
# Check after next package update.
lib.warnIf (finalAttrs.version != "1.21.0")
"Is postgresql18Packages.timescaledb_toolkit still broken?"
(lib.versionAtLeast postgresql.version "18");
};
})

View File

@@ -0,0 +1,60 @@
{
fetchzip,
lib,
mecab,
postgresql,
postgresqlTestExtension,
stdenv,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "tsja";
version = "0.5.0";
src = fetchzip {
url = "https://www.amris.jp/tsja/tsja-${finalAttrs.version}.tar.xz";
hash = "sha256-h59UhUG/7biN8NaDiGK6kXDqfhR9uMzt8CpwbJ+PpEM=";
};
postPatch = ''
substituteInPlace Makefile \
--replace-fail /usr/local/pgsql ${lib.getDev postgresql} \
--replace-fail -L/usr/local/lib "" \
--replace-fail -I/usr/local/include ""
substituteInPlace tsja.c --replace-fail /usr/local/lib/mecab ${mecab}/lib/mecab
'';
buildInputs = [
mecab
postgresql
];
installPhase = ''
mkdir -p $out/lib $out/share/postgresql/extension
mv libtsja.so $out/lib
mv dbinit_libtsja.txt $out/share/postgresql/extension/libtsja_dbinit.sql
'';
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
sql = ''
\i ${finalAttrs.finalPackage}/share/postgresql/extension/libtsja_dbinit.sql
'';
asserts = [
{
query = "EXISTS (SELECT 1 FROM ts_debug('japanese', 'PostgreSQL') WHERE lexemes = '{}')";
expected = "true";
description = "make sure '' is parsed as a separate lexeme";
}
];
};
meta = {
description = "PostgreSQL extension implementing Japanese text search";
homepage = "https://www.amris.jp/tsja/index.html";
maintainers = with lib.maintainers; [ chayleaf ];
# GNU-specific linker options are used
platforms = lib.platforms.gnu;
license = lib.licenses.gpl2Only;
};
})

View File

@@ -0,0 +1,29 @@
diff --git a/crates/simd/build.rs b/crates/simd/build.rs
index 12ce198..aed5588 100644
--- a/crates/simd/build.rs
+++ b/crates/simd/build.rs
@@ -17,17 +17,24 @@ use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
println!("cargo::rerun-if-changed=cshim");
+ println!("cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS");
let target_arch = var("CARGO_CFG_TARGET_ARCH")?;
match target_arch.as_str() {
"aarch64" => {
let mut build = cc::Build::new();
build.file("./cshim/aarch64.c");
+ build.compiler("@clang@");
+ // read env var set by rustPlatform.bindgenHook
+ build.try_flags_from_environment("BINDGEN_EXTRA_CLANG_ARGS").expect("the BINDGEN_EXTRA_CLANG_ARGS environment variable must be specified and UTF-8");
build.opt_level(3);
build.compile("simd_cshim");
}
"x86_64" => {
let mut build = cc::Build::new();
build.file("./cshim/x86_64.c");
+ build.compiler("@clang@");
+ // read env var set by rustPlatform.bindgenHook
+ build.try_flags_from_environment("BINDGEN_EXTRA_CLANG_ARGS").expect("the BINDGEN_EXTRA_CLANG_ARGS environment variable must be specified and UTF-8");
build.opt_level(3);
build.compile("simd_cshim");
}

View File

@@ -0,0 +1,24 @@
diff --git a/crates/algorithm/src/lib.rs b/crates/algorithm/src/lib.rs
index 853a280..f88acbf 100644
--- a/crates/algorithm/src/lib.rs
+++ b/crates/algorithm/src/lib.rs
@@ -13,6 +13,7 @@
// Copyright (c) 2025 TensorChord Inc.
#![feature(select_unpredictable)]
+#![feature(let_chains)]
#![allow(clippy::type_complexity)]
mod build;
diff --git a/src/lib.rs b/src/lib.rs
index 654b4d1..2b11d03 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -13,6 +13,7 @@
// Copyright (c) 2025 TensorChord Inc.
#![allow(unsafe_code)]
+#![feature(let_chains)]
mod datatype;
mod index;

View File

@@ -0,0 +1,141 @@
{
buildPgrxExtension,
cargo-pgrx_0_14_1,
clang,
fetchFromGitHub,
lib,
nix-update-script,
postgresql,
postgresqlTestExtension,
replaceVars,
rust-jemalloc-sys,
stdenv,
}:
let
# Follow upstream and use rust-jemalloc-sys on linux aarch64 and x86_64
# Additionally, disable init exec TLS, since it causes issues with postgres.
# https://github.com/tensorchord/VectorChord/blob/0.4.2/Cargo.toml#L43-L44
useSystemJemalloc =
stdenv.hostPlatform.isLinux && (stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isx86_64);
rust-jemalloc-sys' = (
rust-jemalloc-sys.override (old: {
jemalloc = old.jemalloc.override { disableInitExecTls = true; };
})
);
in
buildPgrxExtension (finalAttrs: {
inherit postgresql;
cargo-pgrx = cargo-pgrx_0_14_1;
pname = "vectorchord";
version = "0.4.2";
src = fetchFromGitHub {
owner = "tensorchord";
repo = "vectorchord";
tag = finalAttrs.version;
hash = "sha256-EdMuSNcWwCBsAY0e3d0WVug1KBWYWldvKStF6cf/uRs=";
};
patches = [
# Tell the `simd` crate to use the flags from the rust bindgen hook
(replaceVars ./0001-read-clang-flags-from-environment.diff {
clang = lib.getExe clang;
})
# Add feature flags needed for features not yet stabilised in rustc stable
./0002-add-feature-flags.diff
];
buildInputs = lib.optionals useSystemJemalloc [
rust-jemalloc-sys'
];
cargoHash = "sha256-8NwfsJn5dnvog3fexzLmO3v7/3+L7xtv+PHWfCCWoHY=";
# Include upgrade scripts in the final package
# https://github.com/tensorchord/VectorChord/blob/0.4.2/crates/make/src/main.rs#L224
postInstall = ''
cp sql/upgrade/* $out/share/postgresql/extension/
'';
env = {
# Bypass rust nightly features not being available on rust stable
RUSTC_BOOTSTRAP = 1;
};
# This crate does not have the "pg_test" feature
usePgTestCheckFeature = false;
passthru = {
updateScript = nix-update-script { };
tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;
withPackages = [ "pgvector" ]; # vectorchord depends on pgvector at runtime
postgresqlExtraSettings = ''
shared_preload_libraries = 'vchord'
'';
sql = ''
CREATE EXTENSION vchord CASCADE;
CREATE TABLE items (id bigint PRIMARY KEY, embedding vector(3));
INSERT INTO items (id, embedding) VALUES
(1, '[1,2,4]'),
(2, '[1,2,5]'),
(3, '[0,0,3]'),
(4, '[0,0,2]'),
(5, '[0,0,1]');
CREATE INDEX ON items USING vchordrq (embedding vector_l2_ops) WITH (options = $$
residual_quantization = true
[build.internal]
lists = [4096]
spherical_centroids = false
$$);
SET vchordrq.probes = 1;
'';
asserts = [
{
query = "SELECT extversion FROM pg_extension WHERE extname = 'vchord'";
expected = "'${finalAttrs.version}'";
description = "Expected installed version to match the derivation's version";
}
{
query = "SELECT id FROM items WHERE embedding <-> '[1,2,3]' = 1";
expected = "1";
description = "Expected vector of row with ID=1 to have an euclidean distance from [1,2,3] of 1.";
}
{
query = "SELECT id FROM items WHERE embedding <-> '[1,2,3]' = 2";
expected = "2";
description = "Expected vector of row with ID=2 to have an euclidean distance from [1,2,3] of 2.";
}
{
query = "SELECT id FROM items ORDER BY embedding <-> '[2,3,7]' LIMIT 1";
expected = "2";
description = "Expected vector of row with ID=2 to be the closest to [2,3,7].";
}
];
};
};
meta = {
# PostgreSQL 18 is not yet supported
# Will be supported in the next release (likely 0.5.0), as it's already supported in the main branch
# Check after next package update.
broken = lib.warnIf (
finalAttrs.version != "0.4.2"
) "Is postgresql18Packages.vectorchord still broken?" (lib.versionAtLeast postgresql.version "18");
changelog = "https://github.com/tensorchord/VectorChord/releases/tag/${finalAttrs.version}";
description = "Scalable, fast, and disk-friendly vector search in Postgres, the successor of pgvecto.rs";
homepage = "https://github.com/tensorchord/VectorChord";
license = lib.licenses.agpl3Only; # dual licensed with Elastic License v2 (ELv2)
maintainers = with lib.maintainers; [
diogotcorreia
];
platforms = postgresql.meta.platforms;
};
})

View File

@@ -0,0 +1,36 @@
{
fetchFromGitHub,
lib,
nix-update-script,
nixosTests,
postgresql,
postgresqlBuildExtension,
}:
postgresqlBuildExtension (finalAttrs: {
pname = "wal2json";
version = "2.6";
src = fetchFromGitHub {
owner = "eulerto";
repo = "wal2json";
tag = "wal2json_${lib.replaceString "." "_" finalAttrs.version}";
hash = "sha256-+QoACPCKiFfuT2lJfSUmgfzC5MXf75KpSoc2PzPxKyM=";
};
makeFlags = [ "USE_PGXS=1" ];
passthru.updateScript = nix-update-script {
extraArgs = [ "--version-regex=^wal2json_(\\d+)_(\\d+)$" ];
};
passthru.tests = nixosTests.postgresql.wal2json.passthru.override postgresql;
meta = {
description = "PostgreSQL JSON output plugin for changeset extraction";
homepage = "https://github.com/eulerto/wal2json";
changelog = "https://github.com/eulerto/wal2json/releases/tag/${finalAttrs.src.rev}";
maintainers = with lib.maintainers; [ euank ];
platforms = postgresql.meta.platforms;
license = lib.licenses.bsd3;
};
})

View File

@@ -0,0 +1,741 @@
let
generic =
# utils
{
stdenv,
fetchFromGitHub,
fetchurl,
lib,
replaceVars,
writeShellScriptBin,
# source specification
hash,
muslPatches ? { },
rev,
version,
# runtime dependencies
darwin,
freebsd,
glibc,
libuuid,
libxml2,
lz4,
openssl,
readline,
tzdata,
zlib,
zstd,
# build dependencies
bison,
docbook-xsl-nons,
docbook_xml_dtd_45,
flex,
libxslt,
makeBinaryWrapper,
pkg-config,
removeReferencesTo,
# passthru
buildEnv,
buildPackages,
newScope,
nixosTests,
postgresqlTestHook,
self,
stdenvNoCC,
testers,
# Block size
# Changing the block size will break on-disk database compatibility. See:
# https://www.postgresql.org/docs/current/install-make.html#CONFIGURE-OPTION-WITH-BLOCKSIZE
withBlocksize ? null,
withWalBlocksize ? null,
# bonjour
bonjourSupport ? false,
# Curl
curlSupport ?
lib.versionAtLeast version "18"
&& lib.meta.availableOn stdenv.hostPlatform curl
# Building statically fails with:
# configure: error: library 'curl' does not provide curl_multi_init
# https://www.postgresql.org/message-id/487dacec-6d8d-46c0-a36f-d5b8c81a56f1%40technowledgy.de
&& !stdenv.hostPlatform.isStatic,
curl,
# GSSAPI
gssSupport ? with stdenv.hostPlatform; !isWindows && !isStatic,
libkrb5,
# icu
# Building with icu in pkgsStatic gives tons of "undefined reference" errors like this:
# /nix/store/452lkaak37d3mzzn3p9ak7aa3wzhdqaj-icu4c-74.2-x86_64-unknown-linux-musl/lib/libicuuc.a(chariter.ao):
# (.data.rel.ro._ZTIN6icu_7417CharacterIteratorE[_ZTIN6icu_7417CharacterIteratorE]+0x0):
# undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
icuSupport ? !stdenv.hostPlatform.isStatic,
icu,
# JIT
jitSupport ?
stdenv.hostPlatform.canExecute stdenv.buildPlatform
# Building with JIT in pkgsStatic fails like this:
# fatal error: 'stdio.h' file not found
&& !stdenv.hostPlatform.isStatic,
llvmPackages_20,
nukeReferences,
overrideCC,
# LDAP
ldapSupport ? false,
openldap,
# NLS
nlsSupport ? false,
gettext,
# NUMA
numaSupport ? lib.versionAtLeast version "18" && lib.meta.availableOn stdenv.hostPlatform numactl,
numactl,
# PAM
pamSupport ?
lib.meta.availableOn stdenv.hostPlatform linux-pam
# Building with linux-pam in pkgsStatic gives a few "undefined reference" errors like this:
# /nix/store/3s55icpsbc36sgn7sa8q3qq4z6al6rlr-linux-pam-static-x86_64-unknown-linux-musl-1.6.1/lib/libpam.a(pam_audit.o):
# in function `pam_modutil_audit_write':(.text+0x571):
# undefined reference to `audit_close'
&& !stdenv.hostPlatform.isStatic,
linux-pam,
# PL/Perl
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
pythonSupport ?
lib.meta.availableOn stdenv.hostPlatform python3
# Building with python in pkgsStatic gives this error:
# checking how to link an embedded Python application... configure: error: could not find shared library for Python
&& !stdenv.hostPlatform.isStatic
# configure tries to call the python executable
&& stdenv.buildPlatform.canExecute stdenv.hostPlatform,
python3,
# PL/Tcl
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
selinuxSupport ? false,
libselinux,
# Systemd
systemdSupport ? lib.meta.availableOn stdenv.hostPlatform systemdLibs,
systemdLibs,
# Uring
uringSupport ? lib.versionAtLeast version "18" && lib.meta.availableOn stdenv.hostPlatform liburing,
liburing,
}@args:
let
atLeast = lib.versionAtLeast version;
olderThan = lib.versionOlder version;
lz4Enabled = atLeast "14";
zstdEnabled = atLeast "15";
dlSuffix = if olderThan "16" then ".so" else stdenv.hostPlatform.extensions.sharedLibrary;
# Pin LLVM 20 until upstream has resolved:
# https://www.postgresql.org/message-id/flat/d25e6e4a-d1b4-84d3-2f8a-6c45b975f53d%40applied-asynchrony.com
# TODO: Remove with next minor releases
llvmPackages = lib.warnIf (
version == "17.7"
) "PostgreSQL: Is the pin for LLVM 20 still needed?" llvmPackages_20;
stdenv' =
if !stdenv.cc.isClang then
overrideCC llvmPackages.stdenv (
llvmPackages.stdenv.cc.override {
# LLVM bintools are not used by default, but are needed to make -flto work below.
bintools = llvmPackages.bintools;
}
)
else
stdenv;
in
stdenv'.mkDerivation (finalAttrs: {
inherit version;
pname = "postgresql";
src = fetchFromGitHub {
owner = "postgres";
repo = "postgres";
# rev, not tag, on purpose: allows updating when new versions
# are "stamped" a few days before release (tag).
inherit hash rev;
};
__structuredAttrs = true;
outputs = [
"out"
"dev"
"doc"
"lib"
"man"
]
++ lib.optionals jitSupport [ "jit" ]
++ lib.optionals perlSupport [ "plperl" ]
++ lib.optionals pythonSupport [ "plpython3" ]
++ lib.optionals tclSupport [ "pltcl" ];
outputChecks = {
out = {
disallowedReferences = [
"dev"
"doc"
"man"
]
++ lib.optionals jitSupport [ "jit" ];
disallowedRequisites = [
stdenv'.cc
llvmPackages.llvm.out
llvmPackages.llvm.lib
]
++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs));
};
lib = {
disallowedReferences = [
"out"
"dev"
"doc"
"man"
]
++ lib.optionals jitSupport [ "jit" ];
disallowedRequisites = [
stdenv'.cc
llvmPackages.llvm.out
llvmPackages.llvm.lib
]
++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs));
};
doc = {
disallowedReferences = [
"out"
"dev"
"man"
]
++ lib.optionals jitSupport [ "jit" ];
};
man = {
disallowedReferences = [
"out"
"dev"
"doc"
]
++ lib.optionals jitSupport [ "jit" ];
};
}
// lib.optionalAttrs jitSupport {
jit = {
disallowedReferences = [
"dev"
"doc"
"man"
];
disallowedRequisites = [
stdenv'.cc
llvmPackages.llvm.out
]
++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs));
};
};
strictDeps = true;
buildInputs = [
zlib
readline
openssl
libxml2
libuuid
]
++ lib.optionals icuSupport [ icu ]
++ lib.optionals jitSupport [ llvmPackages.llvm ]
++ lib.optionals lz4Enabled [ lz4 ]
++ lib.optionals zstdEnabled [ zstd ]
++ lib.optionals systemdSupport [ systemdLibs ]
++ lib.optionals uringSupport [ liburing ]
++ lib.optionals curlSupport [ curl ]
++ lib.optionals numaSupport [ numactl ]
++ lib.optionals gssSupport [ libkrb5 ]
++ lib.optionals pamSupport [ linux-pam ]
++ lib.optionals perlSupport [ perl ]
++ lib.optionals ldapSupport [ openldap ]
++ lib.optionals selinuxSupport [ libselinux ]
++ lib.optionals nlsSupport [ gettext ];
nativeBuildInputs = [
bison
docbook-xsl-nons
docbook_xml_dtd_45
flex
libxml2
libxslt
makeBinaryWrapper
perl
pkg-config
removeReferencesTo
]
++ lib.optionals jitSupport [
llvmPackages.llvm.dev
nukeReferences
];
enableParallelBuilding = true;
separateDebugInfo = true;
buildFlags = [ "world" ];
env = {
# libpgcommon.a and libpgport.a contain all paths returned by pg_config and are linked
# into all binaries. However, almost no binaries actually use those paths. The following
# flags will remove unused sections from all shared libraries and binaries - including
# those paths. This avoids a lot of circular dependency problems with different outputs,
# and allows splitting them cleanly.
CFLAGS = "-fdata-sections -ffunction-sections -flto";
# This flag was introduced upstream in:
# https://github.com/postgres/postgres/commit/b6c7cfac88c47a9194d76f3d074129da3c46545a
# It causes errors when linking against libpq.a in pkgsStatic:
# undefined reference to `pg_encoding_to_char'
# Unsetting the flag fixes it. The upstream reasoning to introduce it is about the risk
# to have initdb load a libpq.so from a different major version and how to avoid that.
# This doesn't apply to us with Nix.
NIX_CFLAGS_COMPILE = "-UUSE_PRIVATE_ENCODING_FUNCS";
}
// lib.optionalAttrs perlSupport { PERL = lib.getExe perl; }
// lib.optionalAttrs pythonSupport { PYTHON = lib.getExe python3; }
// lib.optionalAttrs tclSupport { TCLSH = "${lib.getBin tcl}/bin/tclsh"; };
configureFlags =
let
inherit (lib) withFeature;
in
[
"--with-openssl"
"--with-libxml"
(withFeature icuSupport "icu")
"--sysconfdir=/etc"
"--with-system-tzdata=${tzdata}/share/zoneinfo"
"--enable-debug"
(lib.optionalString systemdSupport "--with-systemd")
(if stdenv.hostPlatform.isFreeBSD then "--with-uuid=bsd" else "--with-uuid=e2fs")
(withFeature perlSupport "perl")
]
++ lib.optionals (withBlocksize != null) [ "--with-blocksize=${toString withBlocksize}" ]
++ lib.optionals (withWalBlocksize != null) [ "--with-wal-blocksize=${toString withWalBlocksize}" ]
++ lib.optionals lz4Enabled [ "--with-lz4" ]
++ lib.optionals zstdEnabled [ "--with-zstd" ]
++ lib.optionals uringSupport [ "--with-liburing" ]
++ lib.optionals curlSupport [ "--with-libcurl" ]
++ lib.optionals numaSupport [ "--with-libnuma" ]
++ lib.optionals gssSupport [ "--with-gssapi" ]
++ lib.optionals pythonSupport [ "--with-python" ]
++ lib.optionals jitSupport [ "--with-llvm" ]
++ lib.optionals pamSupport [ "--with-pam" ]
# This can be removed once v17 is removed. v18+ ships with it.
++ lib.optionals (stdenv'.hostPlatform.isDarwin && atLeast "16" && olderThan "18") [
"LDFLAGS_EX_BE=-Wl,-export_dynamic"
]
# some version of this flag is required in all cross configurations
# since it cannot be automatically detected
++
lib.optionals
(
(!stdenv'.hostPlatform.isDarwin)
&& (!(stdenv'.buildPlatform.canExecute stdenv.hostPlatform))
&& atLeast "16"
)
[
"LDFLAGS_EX_BE=-Wl,--export-dynamic"
]
++ lib.optionals ldapSupport [ "--with-ldap" ]
++ lib.optionals tclSupport [ "--with-tcl" ]
++ lib.optionals selinuxSupport [ "--with-selinux" ]
++ lib.optionals nlsSupport [ "--enable-nls" ]
++ lib.optionals bonjourSupport [ "--with-bonjour" ];
patches = [
(
if atLeast "16" then
./patches/relative-to-symlinks-16+.patch
else
./patches/relative-to-symlinks.patch
)
(
if atLeast "15" then
./patches/empty-pg-config-view-15+.patch
else
./patches/empty-pg-config-view.patch
)
./patches/less-is-more.patch
./patches/paths-for-split-outputs.patch
./patches/paths-with-postgresql-suffix.patch
(replaceVars ./patches/locale-binary-path.patch {
locale = "${
if stdenv.hostPlatform.isDarwin then
darwin.adv_cmds
else if stdenv.hostPlatform.isFreeBSD then
freebsd.locale
else
lib.getBin stdenv.cc.libc
}/bin/locale";
})
]
++ lib.optionals stdenv'.hostPlatform.isMusl (
# Using fetchurl instead of fetchpatch on purpose: https://github.com/NixOS/nixpkgs/issues/240141
map fetchurl (lib.attrValues muslPatches)
)
++ lib.optionals stdenv'.hostPlatform.isLinux [
./patches/socketdir-in-run-13+.patch
]
++ lib.optionals (stdenv'.hostPlatform.isDarwin && olderThan "16") [
./patches/export-dynamic-darwin-15-.patch
];
installTargets = [ "install-world" ];
postPatch = ''
substituteInPlace "src/Makefile.global.in" --subst-var out
substituteInPlace "src/common/config_info.c" --subst-var dev
cat ${./pg_config.env.mk} >> src/common/Makefile
''
# This test always fails on hardware with >1 NUMA node: the sysfs
# dirs providing information about the topology are hidden in the sandbox,
# so postgres assumes there's only a single node `0`. However,
# the test checks on which NUMA nodes the allocated pages are which is >1
# on such hardware. This in turn triggers a safeguard in the view
# which breaks the test.
# Manual tests confirm that the testcase behaves properly outside of the
# Nix sandbox.
+ lib.optionalString (atLeast "18") ''
substituteInPlace src/test/regress/parallel_schedule \
--replace-fail numa ""
''
# This check was introduced upstream to prevent calls to "exit" inside libpq.
# However, this doesn't work reliably with static linking, see this and following:
# https://postgr.es/m/flat/20210703001639.GB2374652%40rfd.leadboat.com#52584ca4bd3cb9dac376f3158c419f97
# Thus, disable the check entirely, as it would currently fail with this:
# > libpq.so.5.17: U atexit
# > libpq.so.5.17: U pthread_exit
# > libpq must not be calling any function which invokes exit
# Don't mind the fact that this checks libpq.**so** in pkgsStatic - that's correct, since PostgreSQL
# still needs a shared library internally.
+ lib.optionalString (atLeast "15" && stdenv'.hostPlatform.isStatic) ''
substituteInPlace src/interfaces/libpq/Makefile \
--replace-fail "echo 'libpq must not be calling any function which invokes exit'; exit 1;" "echo;"
'';
postInstall = ''
moveToOutput "bin/ecpg" "$dev"
moveToOutput "lib/pgxs" "$dev"
''
+ lib.optionalString (stdenv'.buildPlatform.canExecute stdenv'.hostPlatform) ''
mkdir -p "$dev/nix-support"
"$out/bin/pg_config" > "$dev/nix-support/pg_config.expected"
''
+ ''
rm "$out/bin/pg_config"
make -C src/common pg_config.env
substituteInPlace src/common/pg_config.env \
--replace-fail "$out" "@out@" \
--replace-fail "$man" "@man@"
install -D src/common/pg_config.env "$dev/nix-support/pg_config.env"
# postgres exposes external symbols get_pkginclude_path and similar. Those
# can't be stripped away by --gc-sections/LTO, because they could theoretically
# be used by dynamically loaded modules / extensions. To avoid circular dependencies,
# references to -dev, -doc and -man are removed here. References to -lib must be kept,
# because there is a realistic use-case for extensions to locate the /lib directory to
# load other shared modules.
remove-references-to -t "$dev" -t "$doc" -t "$man" "$out/bin/postgres"
''
+ lib.optionalString (!stdenv'.hostPlatform.isStatic) ''
if [ -z "''${dontDisableStatic:-}" ]; then
# Remove static libraries in case dynamic are available.
for i in $lib/lib/*.a; do
name="$(basename "$i")"
ext="${stdenv'.hostPlatform.extensions.sharedLibrary}"
if [ -e "$lib/lib/''${name%.a}$ext" ] || [ -e "''${i%.a}$ext" ]; then
rm "$i"
fi
done
fi
''
+ ''
# The remaining static libraries are libpgcommon.a, libpgport.a and related.
# Those are only used when building e.g. extensions, so go to $dev.
moveToOutput "lib/*.a" "$dev"
''
+ lib.optionalString jitSupport ''
# In the case of JIT support, prevent useless dependencies on header files
find "$out/lib" -iname '*.bc' -type f -exec nuke-refs '{}' +
# Stop lib depending on the -dev output of llvm
remove-references-to -t ${llvmPackages.llvm.dev} "$out/lib/llvmjit${dlSuffix}"
moveToOutput "lib/bitcode" "$jit"
moveToOutput "lib/llvmjit*" "$jit"
''
+ lib.optionalString stdenv'.hostPlatform.isDarwin ''
# The darwin specific Makefile for PGXS contains a reference to the postgres
# binary. Some extensions (here: postgis), which are able to set bindir correctly
# to their own output for installation, will then fail to find "postgres" during linking.
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"
''
+ lib.optionalString tclSupport ''
moveToOutput "lib/*pltcl*" "$pltcl"
moveToOutput "share/postgresql/extension/*pltcl*" "$pltcl"
'';
postFixup = lib.optionalString stdenv'.hostPlatform.isGnu ''
# initdb needs access to "locale" command from glibc.
wrapProgram $out/bin/initdb --prefix PATH ":" ${glibc.bin}/bin
'';
# Running tests as "install check" to work around SIP issue on macOS:
# https://www.postgresql.org/message-id/flat/4D8E1BC5-BBCF-4B19-8226-359201EA8305%40gmail.com
# Also see <nixpkgs>/doc/stdenv/platform-notes.chapter.md
doCheck = false;
doInstallCheck =
!(stdenv'.hostPlatform.isStatic)
&&
# Tests currently can't be run on darwin, because of a Nix bug:
# https://github.com/NixOS/nix/issues/12548
# https://git.lix.systems/lix-project/lix/issues/691
# The error appears as this in the initdb logs:
# FATAL: could not create shared memory segment: Cannot allocate memory
# Don't let yourself be fooled when trying to remove this condition: Running
# the tests works fine most of the time. But once the tests (or any package using
# postgresqlTestHook) fails on the same machine for a few times, enough IPC objects
# will be stuck around, and any future builds with the tests enabled *will* fail.
!(stdenv'.hostPlatform.isDarwin)
&&
# Regression tests currently fail in pkgsMusl because of a difference in EXPLAIN output.
!(stdenv'.hostPlatform.isMusl)
&&
# Modifying block sizes is expected to break regression tests.
# https://www.postgresql.org/message-id/E1TJOeZ-000717-Lg%40wrigleys.postgresql.org
(withBlocksize == null && withWalBlocksize == null);
installCheckTarget = "check-world";
passthru =
let
this = self.callPackage generic args;
in
{
inherit dlSuffix;
psqlSchema = lib.versions.major version;
withJIT = this.withPackages (_: [ this.jit ]);
withoutJIT = this;
pkgs =
let
scope = {
inherit
jitSupport
pythonSupport
perlSupport
tclSupport
;
inherit (llvmPackages) llvm;
postgresql = this;
stdenv = stdenv';
postgresqlTestExtension = newSuper.callPackage ./postgresqlTestExtension.nix { };
postgresqlBuildExtension = newSuper.callPackage ./postgresqlBuildExtension.nix { };
};
newSelf = self // scope;
newSuper = {
callPackage = newScope (scope // this.pkgs);
};
in
import ./ext.nix newSelf newSuper;
withPackages = postgresqlWithPackages {
inherit buildEnv lib makeBinaryWrapper;
postgresql = this;
};
pg_config = buildPackages.callPackage ./pg_config.nix {
inherit (finalAttrs) finalPackage;
outputs = {
out = lib.getOutput "out" finalAttrs.finalPackage;
man = lib.getOutput "man" finalAttrs.finalPackage;
};
};
tests = {
postgresql = nixosTests.postgresql.postgresql.passthru.override finalAttrs.finalPackage;
postgresql-tls-client-cert = nixosTests.postgresql.postgresql-tls-client-cert.passthru.override finalAttrs.finalPackage;
postgresql-wal-receiver = nixosTests.postgresql.postgresql-wal-receiver.passthru.override finalAttrs.finalPackage;
pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
}
// lib.optionalAttrs jitSupport {
postgresql-jit = nixosTests.postgresql.postgresql-jit.passthru.override finalAttrs.finalPackage;
};
};
meta = with lib; {
homepage = "https://www.postgresql.org";
description = "Powerful, open source object-relational database system";
license = licenses.postgresql;
changelog = "https://www.postgresql.org/docs/release/${finalAttrs.version}/";
teams = [ teams.postgres ];
pkgConfigModules = [
"libecpg"
"libecpg_compat"
"libpgtypes"
"libpq"
];
platforms = platforms.unix;
# JIT support doesn't work with cross-compilation. It is attempted to build LLVM-bytecode
# (`%.bc` is the corresponding `make(1)`-rule) for each sub-directory in `backend/` for
# the JIT apparently, but with a $(CLANG) that can produce binaries for the build, not the
# host-platform.
#
# I managed to get a cross-build with JIT support working with
# `depsBuildBuild = [ llvmPackages.clang ] ++ buildInputs`, but considering that the
# resulting LLVM IR isn't platform-independent this doesn't give you much.
# In fact, I tried to test the result in a VM-test, but as soon as JIT was used to optimize
# a query, postgres would coredump with `Illegal instruction`.
#
# Note: This is "host canExecute build" on purpose, since this is about the LLVM that is called
# to do JIT at **runtime**.
broken = jitSupport && !stdenv.hostPlatform.canExecute stdenv.buildPlatform;
};
});
postgresqlWithPackages =
{
postgresql,
buildEnv,
lib,
makeBinaryWrapper,
}:
f:
let
installedExtensions = f postgresql.pkgs;
finalPackage = buildEnv {
name = "${postgresql.pname}-and-plugins-${postgresql.version}";
paths = installedExtensions ++ [
# consider keeping in-sync with `postBuild` below
postgresql
postgresql.man # in case user installs this into environment
];
pathsToLink = [
"/"
"/bin"
"/share/postgresql/extension"
# Unbreaks Omnigres' build system
"/share/postgresql/timezonesets"
"/share/postgresql/tsearch_data"
];
nativeBuildInputs = [ makeBinaryWrapper ];
postBuild =
let
args = lib.concatMap (ext: ext.wrapperArgs or [ ]) installedExtensions;
in
''
wrapProgram "$out/bin/postgres" ${lib.concatStringsSep " " args}
'';
passthru = {
inherit installedExtensions;
inherit (postgresql)
pkgs
psqlSchema
version
;
pg_config = postgresql.pg_config.override {
outputs = {
out = finalPackage;
man = finalPackage;
};
};
withJIT = postgresqlWithPackages {
inherit
buildEnv
lib
makeBinaryWrapper
postgresql
;
} (_: installedExtensions ++ [ postgresql.jit ]);
withoutJIT = postgresqlWithPackages {
inherit
buildEnv
lib
makeBinaryWrapper
postgresql
;
} (_: lib.remove postgresql.jit installedExtensions);
withPackages =
f':
postgresqlWithPackages {
inherit
buildEnv
lib
makeBinaryWrapper
postgresql
;
} (ps: installedExtensions ++ f' ps);
};
};
in
finalPackage;
in
# passed by <major>.nix
versionArgs:
# passed by default.nix
{ self, ... }@defaultArgs:
self.callPackage generic (defaultArgs // versionArgs)

View File

@@ -0,0 +1,174 @@
{
# utils
stdenv,
fetchFromGitHub,
lib,
# runtime dependencies
openssl,
tzdata,
zlib,
# build dependencies
bison,
flex,
makeWrapper,
perl,
pkg-config,
# passthru / meta
postgresql,
buildPackages,
# GSSAPI
gssSupport ? with stdenv.hostPlatform; !isWindows && !isStatic,
libkrb5,
# NLS
nlsSupport ? false,
gettext,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "libpq";
version = "17.6";
src = fetchFromGitHub {
owner = "postgres";
repo = "postgres";
# rev, not tag, on purpose: see generic.nix.
rev = "refs/tags/REL_17_6";
hash = "sha256-/7C+bjmiJ0/CvoAc8vzTC50vP7OsrM6o0w+lmmHvKvU=";
};
__structuredAttrs = true;
hardeningEnable = lib.optionals (!stdenv.cc.isClang) [ "pie" ];
outputs = [
"out"
"dev"
];
outputChecks.out = {
disallowedReferences = [ "dev" ];
disallowedRequisites = [
stdenv.cc
]
++ (map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs));
};
buildInputs = [
zlib
openssl
]
++ lib.optionals gssSupport [ libkrb5 ]
++ lib.optionals nlsSupport [ gettext ];
nativeBuildInputs = [
bison
flex
makeWrapper
perl
pkg-config
];
# causes random build failures
enableParallelBuilding = false;
separateDebugInfo = true;
buildFlags = [
"submake-libpgport"
"submake-libpq"
];
# libpgcommon.a and libpgport.a contain all paths normally returned by pg_config and are
# linked into all shared libraries. However, almost no binaries actually use those paths.
# The following flags will remove unused sections from all shared libraries - including
# those paths. This avoids a lot of circular dependency problems with different outputs,
# and allows splitting them cleanly.
env.CFLAGS =
"-fdata-sections -ffunction-sections"
+ (if stdenv.cc.isClang then " -flto" else " -fmerge-constants -Wl,--gc-sections");
# This flag was introduced upstream in:
# https://github.com/postgres/postgres/commit/b6c7cfac88c47a9194d76f3d074129da3c46545a
# It causes errors when linking against libpq.a in pkgsStatic:
# undefined reference to `pg_encoding_to_char'
# Unsetting the flag fixes it. The upstream reasoning to introduce it is about the risk
# to have initdb load a libpq.so from a different major version and how to avoid that.
# This doesn't apply to us with Nix.
env.NIX_CFLAGS_COMPILE = "-UUSE_PRIVATE_ENCODING_FUNCS";
configureFlags = [
"--enable-debug"
"--sysconfdir=/etc"
"--with-openssl"
"--with-system-tzdata=${tzdata}/share/zoneinfo"
"--without-icu"
"--without-perl"
"--without-readline"
]
++ lib.optionals gssSupport [ "--with-gssapi" ]
++ lib.optionals nlsSupport [ "--enable-nls" ];
patches = lib.optionals stdenv.hostPlatform.isLinux [
./patches/socketdir-in-run-13+.patch
];
postPatch = ''
cat ${./pg_config.env.mk} >> src/common/Makefile
''
# Explicitly disable building the shared libs, because that would fail with pkgsStatic.
+ lib.optionalString stdenv.hostPlatform.isStatic ''
substituteInPlace src/interfaces/libpq/Makefile \
--replace-fail "all: all-lib libpq-refs-stamp" "all: all-lib"
substituteInPlace src/Makefile.shlib \
--replace-fail "all-lib: all-shared-lib" "all-lib: all-static-lib" \
--replace-fail "install-lib: install-lib-shared" "install-lib: install-lib-static"
'';
installPhase = ''
runHook preInstall
make -C src/common install pg_config.env
make -C src/include install
make -C src/interfaces/libpq install
make -C src/port install
substituteInPlace src/common/pg_config.env \
--replace-fail "$out" "@out@"
install -D src/common/pg_config.env "$dev/nix-support/pg_config.env"
moveToOutput "lib/*.a" "$dev"
rm -rfv $out/share
rm -rfv $dev/lib/*_shlib.a
runHook postInstall
'';
# PostgreSQL always builds both shared and static libs, so we delete those we don't want.
postInstall = if stdenv.hostPlatform.isStatic then "touch $out/empty" else "rm -rfv $dev/lib/*.a";
doCheck = false;
passthru.pg_config = buildPackages.callPackage ./pg_config.nix {
inherit (finalAttrs) finalPackage;
outputs = {
out = lib.getOutput "out" finalAttrs.finalPackage;
};
};
meta = {
inherit (postgresql.meta)
homepage
license
teams
platforms
;
description = "C application programmer's interface to PostgreSQL";
changelog = "https://www.postgresql.org/docs/release/${finalAttrs.version}/";
pkgConfigModules = [ "libpq" ];
};
})

View File

@@ -0,0 +1,54 @@
Empty the pg_config system information view. This view keeps references to
several -dev outputs, which we want to avoid to keep closure size down.
The alternative to this patch would be to nuke references across the board,
but this will also affect the output of the pg_config utility. By emptying
the view only, we keep the pg_config binary intact. It resides in the -dev
output, so it's fine to have all those references there.
---
--- a/src/backend/utils/misc/pg_config.c
+++ b/src/backend/utils/misc/pg_config.c
@@ -32,20 +32,5 @@ pg_config(PG_FUNCTION_ARGS)
/* initialize our tuplestore */
InitMaterializedSRF(fcinfo, 0);
- configdata = get_configdata(my_exec_path, &configdata_len);
- for (i = 0; i < configdata_len; i++)
- {
- Datum values[2];
- bool nulls[2];
-
- memset(values, 0, sizeof(values));
- memset(nulls, 0, sizeof(nulls));
-
- values[0] = CStringGetTextDatum(configdata[i].name);
- values[1] = CStringGetTextDatum(configdata[i].setting);
-
- tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
- }
-
return (Datum) 0;
}
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -29,7 +29,7 @@ select name, ident, parent, level, total_bytes >= free_bytes
(1 row)
-- At introduction, pg_config had 23 entries; it may grow
-select count(*) > 20 as ok from pg_config;
+select count(*) = 0 as ok from pg_config;
ok
----
t
--- a/src/test/regress/sql/sysviews.sql
+++ b/src/test/regress/sql/sysviews.sql
@@ -18,7 +18,7 @@ select name, ident, parent, level, total_bytes >= free_bytes
from pg_backend_memory_contexts where level = 0;
-- At introduction, pg_config had 23 entries; it may grow
-select count(*) > 20 as ok from pg_config;
+select count(*) = 0 as ok from pg_config;
-- We expect no cursors in this test; see also portals.sql
select count(*) = 0 as ok from pg_cursors;

View File

@@ -0,0 +1,50 @@
Empty the pg_config system information view. This view keeps references to
several -dev outputs, which we want to avoid to keep closure size down.
The alternative to this patch would be to nuke references across the board,
but this will also affect the output of the pg_config utility. By emptying
the view only, we keep the pg_config binary intact. It resides in the -dev
output, so it's fine to have all those references there.
---
--- a/src/backend/utils/misc/pg_config.c
+++ b/src/backend/utils/misc/pg_config.c
@@ -69,16 +69,6 @@ pg_config(PG_FUNCTION_ARGS)
/* initialize our tuplestore */
tupstore = tuplestore_begin_heap(true, false, work_mem);
- configdata = get_configdata(my_exec_path, &configdata_len);
- for (i = 0; i < configdata_len; i++)
- {
- values[0] = configdata[i].name;
- values[1] = configdata[i].setting;
-
- tuple = BuildTupleFromCStrings(attinmeta, values);
- tuplestore_puttuple(tupstore, tuple);
- }
-
/*
* no longer need the tuple descriptor reference created by
* TupleDescGetAttInMetadata()
--- a/src/test/regress/expected/sysviews.out
+++ b/src/test/regress/expected/sysviews.out
@@ -20,7 +20,7 @@ select count(*) >= 0 as ok from pg_available_extensions;
(1 row)
-- At introduction, pg_config had 23 entries; it may grow
-select count(*) > 20 as ok from pg_config;
+select count(*) = 0 as ok from pg_config;
ok
----
t
--- a/src/test/regress/sql/sysviews.sql
+++ b/src/test/regress/sql/sysviews.sql
@@ -13,7 +13,7 @@ select count(*) >= 0 as ok from pg_available_extension_versions;
select count(*) >= 0 as ok from pg_available_extensions;
-- At introduction, pg_config had 23 entries; it may grow
-select count(*) > 20 as ok from pg_config;
+select count(*) = 0 as ok from pg_config;
-- We expect no cursors in this test; see also portals.sql
select count(*) = 0 as ok from pg_cursors;

View File

@@ -0,0 +1,13 @@
See https://postgr.es/m/eb249761-56e2-4e42-a2c5-b9ae18c1ca1f%40technowledgy.de
---
--- a/src/makefiles/Makefile.darwin
+++ b/src/makefiles/Makefile.darwin
@@ -5,6 +5,8 @@ DLSUFFIX = .so
# env var name to use in place of LD_LIBRARY_PATH
ld_library_path_var = DYLD_LIBRARY_PATH
+export_dynamic = -Wl,-export_dynamic
+
ifdef PGXS
BE_DLLLIBS = -bundle_loader $(bindir)/postgres
else

View File

@@ -0,0 +1,11 @@
--- a/src/include/fe_utils/print.h
+++ b/src/include/fe_utils/print.h
@@ -18,7 +18,7 @@
/* This is not a particularly great place for this ... */
#ifndef __CYGWIN__
-#define DEFAULT_PAGER "more"
+#define DEFAULT_PAGER "less"
#else
#define DEFAULT_PAGER "less"
#endif

View File

@@ -0,0 +1,11 @@
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -611,7 +611,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
aliases = (CollAliasData *) palloc(maxaliases * sizeof(CollAliasData));
naliases = 0;
- locale_a_handle = OpenPipeStream("locale -a", "r");
+ locale_a_handle = OpenPipeStream("@locale@ -a", "r");
if (locale_a_handle == NULL)
ereport(ERROR,
(errcode_for_file_access(),

View File

@@ -0,0 +1,22 @@
--- a/src/common/config_info.c
+++ b/src/common/config_info.c
@@ -118,7 +118,7 @@
i++;
configdata[i].name = pstrdup("PGXS");
+ strlcpy(path, "@dev@/lib", sizeof(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);
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -116,7 +116,7 @@ endif
libdir := @libdir@
-pkglibdir = $(libdir)
+pkglibdir = @out@/lib
ifeq "$(findstring pgsql, $(pkglibdir))" ""
ifeq "$(findstring postgres, $(pkglibdir))" ""
override pkglibdir := $(pkglibdir)/postgresql

View File

@@ -0,0 +1,41 @@
Nix outputs put the `name' in each store path like
/nix/store/...-<name>. This was confusing the Postgres make script
because it thought its data directory already had postgresql in its
directory. This lead to Postgres installing all of its fils in
$out/share. To fix this, we just look for postgres or psql in the part
after the / using make's notdir.
---
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -102,15 +102,15 @@ datarootdir := @datarootdir@
bindir := @bindir@
datadir := @datadir@
-ifeq "$(findstring pgsql, $(datadir))" ""
-ifeq "$(findstring postgres, $(datadir))" ""
+ifeq "$(findstring pgsql, $(notdir $(datadir)))" ""
+ifeq "$(findstring postgres, $(notdir $(datadir)))" ""
override datadir := $(datadir)/postgresql
endif
endif
sysconfdir := @sysconfdir@
-ifeq "$(findstring pgsql, $(sysconfdir))" ""
-ifeq "$(findstring postgres, $(sysconfdir))" ""
+ifeq "$(findstring pgsql, $(notdir $(sysconfdir)))" ""
+ifeq "$(findstring postgres, $(notdir $(sysconfdir)))" ""
override sysconfdir := $(sysconfdir)/postgresql
endif
endif
@@ -136,8 +136,8 @@ endif
mandir := @mandir@
docdir := @docdir@
-ifeq "$(findstring pgsql, $(docdir))" ""
-ifeq "$(findstring postgres, $(docdir))" ""
+ifeq "$(findstring pgsql, $(notdir $(docdir)))" ""
+ifeq "$(findstring postgres, $(notdir $(docdir)))" ""
override docdir := $(docdir)/postgresql
endif
endif

View File

@@ -0,0 +1,13 @@
On NixOS we *want* stuff relative to symlinks.
---
--- a/src/common/exec.c
+++ b/src/common/exec.c
@@ -238,6 +238,8 @@
static int
normalize_exec_path(char *path)
{
+ return 0;
+
/*
* We used to do a lot of work ourselves here, but now we just let
* realpath(3) do all the heavy lifting.

View File

@@ -0,0 +1,13 @@
On NixOS we *want* stuff relative to symlinks.
---
--- a/src/common/exec.c
+++ b/src/common/exec.c
@@ -218,6 +218,8 @@
static int
resolve_symlinks(char *path)
{
+ return 0;
+
#ifdef HAVE_READLINK
struct stat buf;
char orig_wd[MAXPGPATH],

View File

@@ -0,0 +1,11 @@
--- a/src/include/pg_config_manual.h
+++ b/src/include/pg_config_manual.h
@@ -201,7 +201,7 @@
* support them yet.
*/
#ifndef WIN32
-#define DEFAULT_PGSOCKET_DIR "/tmp"
+#define DEFAULT_PGSOCKET_DIR "/run/postgresql"
#else
#define DEFAULT_PGSOCKET_DIR ""
#endif

View File

@@ -0,0 +1,14 @@
# Everything that pg_config normally returns is put into pg_config.env, so
# that we can read it from our own pg_config script later on.
pg_config.env: $(top_builddir)/src/port/pg_config_paths.h | $(top_builddir)/src/include/pg_config.h
echo "CC=\"$(CC)\"" >$@
echo "CPPFLAGS=\"$(STD_CPPFLAGS)\"" >>$@
echo "CFLAGS=\"$(CFLAGS)\"" >>$@
echo "CFLAGS_SL=\"$(CFLAGS_SL)\"" >>$@
echo "LDFLAGS=\"$(STD_LDFLAGS)\"" >>$@
echo "LDFLAGS_EX=\"$(LDFLAGS_EX)\"" >>$@
echo "LDFLAGS_SL=\"$(LDFLAGS_SL)\"" >>$@
echo "LIBS=\"$(LIBS)\"" >>$@
echo "PGXS=\"$(dev)/lib/pgxs/src/makefiles/pgxs.mk\"" >>$@
cat $(top_builddir)/src/port/pg_config_paths.h $(top_builddir)/src/include/pg_config.h \
| sed -nE 's/^#define ([^ ]+) ("?)(.*)\2$$/\1="\3"/p' >>$@

View File

@@ -0,0 +1,35 @@
{
diffutils,
lib,
replaceVarsWith,
runtimeShell,
stdenv,
# PostgreSQL package
finalPackage,
# PostgreSQL package's outputs
outputs,
}:
replaceVarsWith {
name = "pg_config";
src = ./pg_config.sh;
dir = "bin";
isExecutable = true;
replacements = {
inherit runtimeShell;
"pg_config.env" = replaceVarsWith {
name = "pg_config.env";
src = "${lib.getDev finalPackage}/nix-support/pg_config.env";
replacements = outputs;
};
};
nativeCheckInputs = [
diffutils
];
# The expected output only matches when outputs have *not* been altered by postgresql.withPackages.
postCheck = lib.optionalString (outputs.out == lib.getOutput "out" finalPackage) ''
if [ -e ${lib.getDev finalPackage}/nix-support/pg_config.expected ]; then
diff ${lib.getDev finalPackage}/nix-support/pg_config.expected <($out/bin/pg_config)
fi
'';
}

View File

@@ -0,0 +1,122 @@
#!@runtimeShell@
set -euo pipefail
# This replacement script for the pg_config binary is based on the original pg_config
# shell script, which was removed from PostgreSQL's codebase in 2004:
# https://github.com/postgres/postgres/commit/cc07f8cfe73f56fce1ddda4ea25d7b0b6c4f0ae9
#
# The main reason for removal was the ability to relocate an existing installation, which
# is exactly the one feature that we are trying to work around in nixpkgs.
# Going back to a shell script is much better for cross compiling.
#
# This file is a combination of the following two files:
# https://github.com/postgres/postgres/blob/7510ac6203bc8e3c56eae95466feaeebfc1b4f31/src/bin/pg_config/pg_config.sh
# https://github.com/postgres/postgres/blob/master/src/bin/pg_config/pg_config.c
source @pg_config.env@
help="
pg_config provides information about the installed version of PostgreSQL.
Usage:
pg_config [OPTION]...
Options:
--bindir show location of user executables
--docdir show location of documentation files
--htmldir show location of HTML documentation files
--includedir show location of C header files of the client
interfaces
--pkgincludedir show location of other C header files
--includedir-server show location of C header files for the server
--libdir show location of object code libraries
--pkglibdir show location of dynamically loadable modules
--localedir show location of locale support files
--mandir show location of manual pages
--sharedir show location of architecture-independent support files
--sysconfdir show location of system-wide configuration files
--pgxs show location of extension makefile
--configure show options given to \"configure\" script when
PostgreSQL was built
--cc show CC value used when PostgreSQL was built
--cppflags show CPPFLAGS value used when PostgreSQL was built
--cflags show CFLAGS value used when PostgreSQL was built
--cflags_sl show CFLAGS_SL value used when PostgreSQL was built
--ldflags show LDFLAGS value used when PostgreSQL was built
--ldflags_ex show LDFLAGS_EX value used when PostgreSQL was built
--ldflags_sl show LDFLAGS_SL value used when PostgreSQL was built
--libs show LIBS value used when PostgreSQL was built
--version show the PostgreSQL version
-?, --help show this help, then exit
With no arguments, all known items are shown.
Report bugs to <${PACKAGE_BUGREPORT}>.
${PACKAGE_NAME} home page: <${PACKAGE_URL}>"
show=()
for opt; do
case "$opt" in
--bindir) show+=("$PGBINDIR") ;;
--docdir) show+=("$DOCDIR") ;;
--htmldir) show+=("$HTMLDIR") ;;
--includedir) show+=("$INCLUDEDIR") ;;
--pkgincludedir) show+=("$PKGINCLUDEDIR") ;;
--includedir-server) show+=("$INCLUDEDIRSERVER") ;;
--libdir) show+=("$LIBDIR") ;;
--pkglibdir) show+=("$PKGLIBDIR") ;;
--localedir) show+=("$LOCALEDIR") ;;
--mandir) show+=("$MANDIR") ;;
--sharedir) show+=("$PGSHAREDIR") ;;
--sysconfdir) show+=("$SYSCONFDIR") ;;
--pgxs) show+=("$PGXS") ;;
--configure) show+=("$CONFIGURE_ARGS") ;;
--cc) show+=("$CC") ;;
--cppflags) show+=("$CPPFLAGS") ;;
--cflags) show+=("$CFLAGS") ;;
--cflags_sl) show+=("$CFLAGS_SL") ;;
--ldflags) show+=("$LDFLAGS") ;;
--ldflags_ex) show+=("$LDFLAGS_EX") ;;
--ldflags_sl) show+=("$LDFLAGS_SL") ;;
--libs) show+=("$LIBS") ;;
--version) show+=("PostgreSQL $PG_VERSION") ;;
--help|-\?) echo "$help"
exit 0 ;;
*) >&2 echo "pg_config: invalid argument: $opt"
>&2 echo "Try \"pg_config --help\" for more information."
exit 1 ;;
esac
done
if [ ${#show[@]} -gt 0 ]; then
printf '%s\n' "${show[@]}"
exit 0
fi
# no arguments -> print everything
cat <<EOF
BINDIR = $PGBINDIR
DOCDIR = $DOCDIR
HTMLDIR = $HTMLDIR
INCLUDEDIR = $INCLUDEDIR
PKGINCLUDEDIR = $PKGINCLUDEDIR
INCLUDEDIR-SERVER = $INCLUDEDIRSERVER
LIBDIR = $LIBDIR
PKGLIBDIR = $PKGLIBDIR
LOCALEDIR = $LOCALEDIR
MANDIR = $MANDIR
SHAREDIR = $PGSHAREDIR
SYSCONFDIR = $SYSCONFDIR
PGXS = $PGXS
CONFIGURE = $CONFIGURE_ARGS
CC = $CC
CPPFLAGS = $CPPFLAGS
CFLAGS = $CFLAGS
CFLAGS_SL = $CFLAGS_SL
LDFLAGS = $LDFLAGS
LDFLAGS_EX = $LDFLAGS_EX
LDFLAGS_SL = $LDFLAGS_SL
LIBS = $LIBS
VERSION = PostgreSQL $PG_VERSION
EOF

View File

@@ -0,0 +1,152 @@
# PostgreSQL's build system for extensions (PGXS) makes the following assumptions:
# - All extensions will be installed in the same prefix as PostgreSQL itself.
# - pg_config is able to return the correct paths for bindir/libdir/datadir etc.
#
# Both of those assumptions break with nix. Since each extension is a separate
# derivation, we need to put all its files into a different folder. At the same
# time, pg_config only points to the PostgreSQL derivation's paths.
#
# When building extensions, the paths provided by pg_config are used for two
# purposes:
# - To find postgres libs and headers and reference those paths via -L and -I flags.
# - To determine the correct install directory.
#
# The PGXS Makefiles also support an environment variable DESTDIR, which is added as
# a prefix to all install locations. This is primarily used for temporary installs
# while running the test suite. Since pg_config returns absolute paths to /nix/store
# for us, using DESTDIR will result in install locations of the form:
# $DESTIDR/nix/store/<postgresql-output>/...
#
# In multiple iterations, the following approaches have been tried to work around all
# of this:
# 1. For a long time, all extensions in nixpkgs just overwrote the installPhase
# and moved the respective files to the correct location manually. This approach
# is not maintainable, because whenever upstream adds a new file, we'd have to
# make sure the file is correctly installed as well. Additionally, it makes adding
# a new extension harder than it should be.
#
# 2. A wrapper around pg_config could just replace the returned paths with paths to
# $out of currently building derivation, i.e. the extension. This works for install-
# ation, but breaks for any of the libs and headers the extension needs from postgres
# itself.
#
# 3. A variation of 2., but make the pg_config wrapper only return the changed paths
# during the installPahse. During configure and build, it would return the regular
# paths to the PostgreSQL derivation. This works better, but not for every case.
# Some extensions try to be smarter and search for the "postgres" binary to deduce
# the necessary paths from that. Those would still need special handling.
#
# 4. Use the fact that DESTDIR is prepended to every installation directory - and only
# there, to run a replacement of all Makefiles in postgres' lib/pgxs/ folder and
# all Makefiles in the extension's source. "$DESTDIR/$bindir" can be replaced with
# "$out/bin" etc. - thus mapping the installPhase directly into the right output.
# This works beautifully - for the majority of cases. But it doesn't work for
# some extensions that use CMake. And it doesn't work for some extensions that use
# custom variables instead of the default "bindir" and friends.
#
# 5. Just set DESTDIR to the extensions's output and then clean up afterward. This will
# result in paths like this:
# /nix/store/<extension-output>/nix/store/<postgresql-output>/...
# Directly after the installPhase, we'll move the files in the right folder.
# This seems to work consistently across all extensions we have in nixpkgs right now.
# Of course, it would break down for any extension that doesn't support DESTDIR -
# but that just means PGXS is not used either, so that's OK.
#
# This last approach is the one we're taking in this file. To make sure the removal of the
# nested nix/store happens immediately after the installPhase, before any other postInstall
# hooks run, this needs to be run in an override of `mkDerivation` and not in a setup hook.
{
lib,
stdenv,
postgresql,
nix-update-script,
}:
lib.extendMkDerivation {
constructDrv = stdenv.mkDerivation;
excludeDrvArgNames = [
"enableUpdateScript"
];
extendDrvArgs =
finalAttrs:
{
enableUpdateScript ? true,
...
}@prevAttrs:
{
passthru =
prevAttrs.passthru or { }
// lib.optionalAttrs enableUpdateScript {
updateScript =
prevAttrs.passthru.updateScript or (nix-update-script (
lib.optionalAttrs (lib.hasInfix "unstable" prevAttrs.version) {
extraArgs = [ "--version=branch" ];
}
));
};
strictDeps = true;
buildInputs = [ postgresql ] ++ prevAttrs.buildInputs or [ ];
nativeBuildInputs = [ postgresql.pg_config ] ++ prevAttrs.nativeBuildInputs or [ ];
installFlags = [
"DESTDIR=${placeholder "out"}"
]
++ prevAttrs.installFlags or [ ];
postInstall = ''
# DESTDIR + pg_config install the files into
# /nix/store/<extension>/nix/store/<postgresql>/...
# We'll now remove the /nix/store/<postgresql> part:
if [[ -d "$out${postgresql}" ]]; then
cp -alt "$out" "$out${postgresql}"/*
rm -r "$out${postgresql}"
fi
if [[ -d "$out${postgresql.dev}" ]]; then
mkdir -p "''${dev:-$out}"
cp -alt "''${dev:-$out}" "$out${postgresql.dev}"/*
rm -r "$out${postgresql.dev}"
fi
if [[ -d "$out${postgresql.lib}" ]]; then
mkdir -p "''${lib:-$out}"
cp -alt "''${lib:-$out}" "$out${postgresql.lib}"/*
rm -r "$out${postgresql.lib}"
fi
if [[ -d "$out${postgresql.doc}" ]]; then
mkdir -p "''${doc:-$out}"
cp -alt "''${doc:-$out}" "$out${postgresql.doc}"/*
rm -r "$out${postgresql.doc}"
fi
if [[ -d "$out${postgresql.man}" ]]; then
mkdir -p "''${man:-$out}"
cp -alt "''${man:-$out}" "$out${postgresql.man}"/*
rm -r "$out${postgresql.man}"
fi
# In some cases (postgis) parts of the install script
# actually work "OK", before we add DESTDIR, so some
# files end up in
# /nix/store/<extension>/nix/store/<extension>/...
if [[ -d "$out$out" ]]; then
cp -alt "$out" "$out$out"/*
rm -r "$out$out"
fi
if [[ -d "$out/nix/store" ]]; then
if ! rmdir "$out/nix/store" "$out/nix"; then
find "$out/nix"
nixErrorLog 'Found left-overs in $out/nix/store, make sure to move them into $out properly.'
exit 1
fi
fi
''
+ prevAttrs.postInstall or "";
};
}

View File

@@ -0,0 +1,53 @@
{
lib,
postgresql,
postgresqlTestHook,
stdenvNoCC,
}:
{
asserts ? [ ],
finalPackage,
sql,
withPackages ? [ ],
...
}@extraArgs:
stdenvNoCC.mkDerivation (
{
name = "${finalPackage.name}-test-extension";
dontUnpack = true;
doCheck = true;
nativeCheckInputs = [
postgresqlTestHook
(postgresql.withPackages (ps: [ finalPackage ] ++ (map (p: ps."${p}") withPackages)))
];
postgresqlTestUserOptions = "LOGIN SUPERUSER";
passAsFile = [ "sql" ];
sql =
sql
+ lib.concatMapStrings (
{
query,
expected,
description,
}:
''
DO $$ BEGIN
ASSERT (${query}) = (${expected}), '${lib.replaceStrings [ "'" ] [ "''" ] description}';
END $$;
''
) asserts;
checkPhase = ''
runHook preCheck
psql -a -v ON_ERROR_STOP=1 -f "$sqlPath"
runHook postCheck
'';
installPhase = "touch $out";
}
// lib.removeAttrs extraArgs [
"asserts"
"finalPackage"
"sql"
"withPackages"
]
)