|
1 |
| -{ lib, stdenv, fetchFromGitHub, postgresql }: |
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + fetchFromGitHub, |
| 5 | + postgresql, |
| 6 | + runCommand, |
| 7 | +}: |
2 | 8 |
|
3 |
| -stdenv.mkDerivation rec { |
| 9 | +let |
4 | 10 | pname = "pgvector";
|
5 |
| - version = "0.8.0"; |
6 | 11 |
|
7 |
| - buildInputs = [ postgresql ]; |
| 12 | + meta = { |
| 13 | + description = "Open-source vector similarity search for Postgres"; |
| 14 | + homepage = "https://github.com/${pname}/${pname}"; |
| 15 | + maintainers = with lib.maintainers; [ olirice ]; |
| 16 | + inherit (postgresql.meta) platforms; |
| 17 | + license = lib.licenses.postgresql; |
| 18 | + }; |
8 | 19 |
|
9 |
| - src = fetchFromGitHub { |
10 |
| - owner = "pgvector"; |
11 |
| - repo = pname; |
12 |
| - rev = "refs/tags/v${version}"; |
13 |
| - hash = "sha256-JsZV+I4eRMypXTjGmjCtMBXDVpqTIPHQa28ogXncE/Q="; |
| 20 | + versions = { |
| 21 | + "0.8.0" = "sha256-JsZV+I4eRMypXTjGmjCtMBXDVpqTIPHQa28ogXncE/Q="; |
| 22 | + "0.7.4" = "sha256-qwPaguQUdDHV8q6GDneLq5MuhVroPizpbqt7f08gKJI="; |
14 | 23 | };
|
15 | 24 |
|
16 |
| - installPhase = '' |
17 |
| - mkdir -p $out/{lib,share/postgresql/extension} |
| 25 | + mkPackage = |
| 26 | + version: hash: |
| 27 | + stdenv.mkDerivation (finalAttrs: { |
| 28 | + inherit pname version meta; |
18 | 29 |
|
19 |
| - cp *${postgresql.dlSuffix} $out/lib |
20 |
| - cp sql/*.sql $out/share/postgresql/extension |
21 |
| - cp *.control $out/share/postgresql/extension |
22 |
| - ''; |
| 30 | + src = fetchFromGitHub { |
| 31 | + owner = pname; |
| 32 | + repo = pname; |
| 33 | + rev = "refs/tags/v${finalAttrs.version}"; |
| 34 | + inherit hash; |
| 35 | + }; |
23 | 36 |
|
24 |
| - meta = with lib; { |
25 |
| - description = "Open-source vector similarity search for Postgres"; |
26 |
| - homepage = "https://github.com/${src.owner}/${src.repo}"; |
27 |
| - maintainers = with maintainers; [ olirice ]; |
28 |
| - platforms = postgresql.meta.platforms; |
29 |
| - license = licenses.postgresql; |
30 |
| - }; |
31 |
| -} |
| 37 | + buildInputs = [ postgresql ]; |
| 38 | + |
| 39 | + postBuild = '' |
| 40 | + cp sql/vector.sql vector--$version.sql |
| 41 | +
|
| 42 | + sed -e "/^default_version =/d" \ |
| 43 | + -e "s|^module_pathname = .*|module_pathname = '\$libdir/vector'|" \ |
| 44 | + vector.control > vector--$version.control |
| 45 | + ''; |
| 46 | + |
| 47 | + installPhase = '' |
| 48 | + mkdir -p $out/{lib,share/postgresql/extension} |
| 49 | +
|
| 50 | + install -Dm755 vector${postgresql.dlSuffix} $out/lib/vector-$version${postgresql.dlSuffix} |
| 51 | + install -Dm644 vector--$version.sql $out/share/postgresql/extension/ |
| 52 | + install -Dm644 vector--$version.control $out/share/postgresql/extension/ |
| 53 | + ''; |
| 54 | + }); |
| 55 | + |
| 56 | + packages = lib.listToAttrs ( |
| 57 | + lib.attrValues ( |
| 58 | + lib.mapAttrs (version: hash: lib.nameValuePair "v${version}" (mkPackage version hash)) versions |
| 59 | + ) |
| 60 | + ); |
| 61 | +in |
| 62 | +runCommand "${pname}-all" |
| 63 | + { |
| 64 | + inherit pname meta; |
| 65 | + version = "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings ["."] ["-"] v) (lib.attrNames versions)); |
| 66 | + |
| 67 | + buildInputs = lib.attrValues packages; |
| 68 | + |
| 69 | + passthru = { |
| 70 | + inherit packages; |
| 71 | + }; |
| 72 | + } |
| 73 | + '' |
| 74 | + mkdir -p $out/{lib,share/postgresql/extension,bin} |
| 75 | +
|
| 76 | + # Install all versions |
| 77 | + for drv in ''${buildInputs[@]}; do |
| 78 | + ln -sv $drv/lib/* $out/lib/ |
| 79 | + cp -v --no-clobber $drv/share/postgresql/extension/* $out/share/postgresql/extension/ || true |
| 80 | + done |
| 81 | +
|
| 82 | + # Create default symlinks |
| 83 | + latest_control=$(ls -v $out/share/postgresql/extension/vector--*.control | tail -n1) |
| 84 | + latest_version=$(basename "$latest_control" | sed -E 's/vector--([0-9.]+).control/\1/') |
| 85 | + |
| 86 | + # Create main control file with default_version |
| 87 | + echo "default_version = '$latest_version'" > $out/share/postgresql/extension/vector.control |
| 88 | + cat "$latest_control" >> $out/share/postgresql/extension/vector.control |
| 89 | + |
| 90 | + # Library symlink |
| 91 | + ln -sfnv vector$latest_version${postgresql.dlSuffix} $out/lib/vector${postgresql.dlSuffix} |
| 92 | + '' |
0 commit comments