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