buildPgrxExtension: require pinning cargo-pgrx

Each extension always depends on a specific cargo-pgrx version, so make
pinning a requirement.
This commit is contained in:
Wolfgang Walther
2025-07-07 10:03:22 +02:00
parent 22bb92645c
commit 8ea2c88439
6 changed files with 97 additions and 116 deletions

View File

@@ -29,7 +29,6 @@
{
lib,
cargo-pgrx,
pkg-config,
rustPlatform,
stdenv,
@@ -64,6 +63,8 @@ lib.extendMkDerivation {
buildFeatures ? [ ],
cargoBuildFlags ? [ ],
cargoPgrxFlags ? [ ],
# pinned dependencies
cargo-pgrx,
postgresql,
# cargo-pgrx calls rustfmt on generated bindings, this is not strictly necessary, so we avoid the
# dependency here. Set to false and provide rustfmt in nativeBuildInputs, if you need it, e.g.

View File

@@ -23,112 +23,106 @@ let
};
in
(buildPgrxExtension.override {
# Upstream only works with a fixed version of cargo-pgrx for each release,
# so we're pinning it here to avoid future incompatibility.
# See https://docs.vectorchord.ai/developers/development.html#set-up-development-environment, step 5
(buildPgrxExtension.override { rustPlatform = rustPlatform'; }) (finalAttrs: {
inherit postgresql;
cargo-pgrx = cargo-pgrx_0_12_0_alpha_1;
rustPlatform = rustPlatform';
})
(finalAttrs: {
inherit postgresql;
pname = "pgvecto-rs";
version = "0.3.0";
pname = "pgvecto-rs";
version = "0.3.0";
buildInputs = [ openssl ];
nativeBuildInputs = [ pkg-config ];
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;
})
];
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;
})
];
src = fetchFromGitHub {
owner = "tensorchord";
repo = "pgvecto.rs";
tag = "v${finalAttrs.version}";
hash = "sha256-X7BY2Exv0xQNhsS/GA7GNvj9OeVDqVCd/k3lUkXtfgE=";
};
src = fetchFromGitHub {
owner = "tensorchord";
repo = "pgvecto.rs";
tag = "v${finalAttrs.version}";
hash = "sha256-X7BY2Exv0xQNhsS/GA7GNvj9OeVDqVCd/k3lUkXtfgE=";
};
useFetchCargoVendor = true;
cargoHash = "sha256-8otJ1uqGrCmlxAqvfAL3OjhBI4I6dAu6EoajstO46Sw=";
useFetchCargoVendor = true;
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}
'';
# 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/
'';
# 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;
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;
};
# Bypass rust nightly features not being available on rust stable
RUSTC_BOOTSTRAP = 1;
};
# This crate does not have the "pg_test" feature
usePgTestCheckFeature = false;
# 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;
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
);
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
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

@@ -7,13 +7,7 @@
postgresqlTestExtension,
}:
let
buildPgrxExtension' = buildPgrxExtension.override {
# Upstream only works with a fixed minor version of cargo-pgrx for each release.
cargo-pgrx = cargo-pgrx_0_12_6;
};
in
buildPgrxExtension' (finalAttrs: {
buildPgrxExtension (finalAttrs: {
pname = "pgvectorscale";
version = "0.7.0";
@@ -38,6 +32,7 @@ buildPgrxExtension' (finalAttrs: {
];
inherit postgresql;
cargo-pgrx = cargo-pgrx_0_12_6;
passthru.tests.extension = postgresqlTestExtension {
inherit (finalAttrs) finalPackage;

View File

@@ -7,14 +7,9 @@
postgresql,
util-linux,
}:
let
buildPgrxExtension' = buildPgrxExtension.override {
# Upstream only works with a fixed minor version of cargo-pgrx for each release.
cargo-pgrx = cargo-pgrx_0_12_6;
};
in
buildPgrxExtension' (finalAttrs: {
buildPgrxExtension (finalAttrs: {
inherit postgresql;
cargo-pgrx = cargo-pgrx_0_12_6;
pname = "pgx_ulid";
version = "0.2.0";

View File

@@ -7,8 +7,9 @@
postgresql,
}:
(buildPgrxExtension.override { cargo-pgrx = cargo-pgrx_0_12_6; }) (finalAttrs: {
buildPgrxExtension (finalAttrs: {
inherit postgresql;
cargo-pgrx = cargo-pgrx_0_12_6;
pname = "timescaledb_toolkit";
version = "1.21.0";

View File

@@ -12,12 +12,6 @@
stdenv,
}:
let
buildPgrxExtension' = buildPgrxExtension.override {
# Upstream only works with a fixed version of cargo-pgrx for each release,
# so we're pinning it here to avoid future incompatibility.
cargo-pgrx = cargo-pgrx_0_14_1;
};
# 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
@@ -29,8 +23,9 @@ let
})
);
in
buildPgrxExtension' (finalAttrs: {
buildPgrxExtension (finalAttrs: {
inherit postgresql;
cargo-pgrx = cargo-pgrx_0_14_1;
pname = "vectorchord";
version = "0.4.2";