nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 buildPgrxExtension,
3 cargo-pgrx_0_12_0_alpha_1,
4 clang,
5 fetchFromGitHub,
6 lib,
7 nix-update-script,
8 openssl,
9 pkg-config,
10 postgresql,
11 postgresqlTestExtension,
12 replaceVars,
13}:
14
15buildPgrxExtension (finalAttrs: {
16 inherit postgresql;
17 cargo-pgrx = cargo-pgrx_0_12_0_alpha_1;
18
19 pname = "pgvecto-rs";
20 version = "0.3.0";
21
22 buildInputs = [ openssl ];
23 nativeBuildInputs = [ pkg-config ];
24
25 patches = [
26 # Tell the `c` crate to use the flags from the rust bindgen hook
27 (replaceVars ./0001-read-clang-flags-from-environment.diff {
28 clang = lib.getExe clang;
29 })
30 # Rust 1.89 denies implicit autorefs by default, making the compilation fail.
31 # This restores the behaviour of previous rust versions by making the lint throw a warning instead.
32 ./0002-allow-dangerous-implicit-autorefs.diff
33 ];
34
35 src = fetchFromGitHub {
36 owner = "tensorchord";
37 repo = "pgvecto.rs";
38 tag = "v${finalAttrs.version}";
39 hash = "sha256-X7BY2Exv0xQNhsS/GA7GNvj9OeVDqVCd/k3lUkXtfgE=";
40 };
41
42 cargoHash = "sha256-8otJ1uqGrCmlxAqvfAL3OjhBI4I6dAu6EoajstO46Sw=";
43
44 # Set appropriate version on vectors.control, otherwise it won't show up on PostgreSQL
45 postPatch = ''
46 substituteInPlace ./vectors.control --subst-var-by CARGO_VERSION ${finalAttrs.version}
47 '';
48
49 # Include upgrade scripts in the final package
50 # https://github.com/tensorchord/pgvecto.rs/blob/v0.2.0/scripts/ci_package.sh#L6-L8
51 postInstall = ''
52 cp sql/upgrade/* $out/share/postgresql/extension/
53 '';
54
55 env = {
56 # Needed to get openssl-sys to use pkg-config.
57 OPENSSL_NO_VENDOR = 1;
58
59 # Bypass rust nightly features not being available on rust stable
60 RUSTC_BOOTSTRAP = 1;
61 };
62
63 # This crate does not have the "pg_test" feature
64 usePgTestCheckFeature = false;
65
66 passthru = {
67 updateScript = nix-update-script { };
68 tests.extension = postgresqlTestExtension {
69 inherit (finalAttrs) finalPackage;
70 postgresqlExtraSettings = ''
71 shared_preload_libraries='vectors'
72 '';
73 sql = ''
74 CREATE EXTENSION vectors;
75
76 CREATE TABLE items (
77 id bigserial PRIMARY KEY,
78 content text NOT NULL,
79 embedding vectors.vector(3) NOT NULL -- 3 dimensions
80 );
81
82 INSERT INTO items (content, embedding) VALUES
83 ('a fat cat sat on a mat and ate a fat rat', '[1, 2, 3]'),
84 ('a fat dog sat on a mat and ate a fat rat', '[4, 5, 6]'),
85 ('a thin cat sat on a mat and ate a thin rat', '[7, 8, 9]'),
86 ('a thin dog sat on a mat and ate a thin rat', '[10, 11, 12]');
87 '';
88 asserts = [
89 {
90 query = "SELECT default_version FROM pg_available_extensions WHERE name = 'vectors'";
91 expected = "'${finalAttrs.version}'";
92 description = "Extension vectors has correct version.";
93 }
94 {
95 query = "SELECT COUNT(embedding) FROM items WHERE to_tsvector('english', content) @@ 'cat & rat'::tsquery";
96 expected = "2";
97 description = "Stores and returns vectors.";
98 }
99 ];
100 };
101 };
102
103 meta = {
104 # Upstream removed support for PostgreSQL 13 on 0.3.0: https://github.com/tensorchord/pgvecto.rs/issues/343
105 broken =
106 (lib.versionOlder postgresql.version "14")
107 ||
108 # PostgreSQL 17 support issue upstream: https://github.com/tensorchord/pgvecto.rs/issues/607
109 # Check after next package update.
110 lib.versionAtLeast postgresql.version "17" && finalAttrs.version == "0.3.0";
111 description = "Scalable, Low-latency and Hybrid-enabled Vector Search in Postgres";
112 homepage = "https://github.com/tensorchord/pgvecto.rs";
113 license = lib.licenses.asl20;
114 maintainers = with lib.maintainers; [
115 diogotcorreia
116 esclear
117 ];
118 };
119})