-
-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathpg_textsearch.nix
More file actions
91 lines (76 loc) · 2.78 KB
/
pg_textsearch.nix
File metadata and controls
91 lines (76 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{
lib,
stdenv,
fetchFromGitHub,
postgresql,
buildEnv,
}:
let
pname = "pg_textsearch";
# Load version configuration from external file
allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname};
# Filter versions compatible with current PostgreSQL version
supportedVersions = lib.filterAttrs (
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
) allVersions;
# Derived version information
versions = lib.naturalSort (lib.attrNames supportedVersions);
latestVersion = lib.last versions;
numberOfVersions = builtins.length versions;
packages = builtins.attrValues (
lib.mapAttrs (name: value: build name value.hash) supportedVersions
);
# Build function for individual versions
build =
version: hash:
stdenv.mkDerivation {
inherit pname version;
src = fetchFromGitHub {
owner = "timescale";
repo = "pg_textsearch";
rev = "refs/tags/v${version}";
inherit hash;
};
buildInputs = [ postgresql ];
makeFlags = [ "USE_PGXS=1" ];
installPhase = ''
mkdir -p $out/{lib,share/postgresql/extension}
# Install shared library with version suffix
mv ${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix}
# Create version-specific control file
sed -e "/^default_version =/d" \
-e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}-${version}'|" \
${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control
# Copy SQL file to install the specific version
cp sql/${pname}--${version}.sql $out/share/postgresql/extension/${pname}--${version}.sql
# For the latest version, copy sql upgrade scripts, default control file and symlink
if [[ "${version}" == "${latestVersion}" ]]; then
cp sql/*.sql $out/share/postgresql/extension
{
echo "default_version = '${version}'"
cat $out/share/postgresql/extension/${pname}--${version}.control
} > $out/share/postgresql/extension/${pname}.control
ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}
fi
'';
meta = with lib; {
description = "Full-text search with BM25 ranking for PostgreSQL";
homepage = "https://github.com/timescale/pg_textsearch";
license = licenses.postgresql;
inherit (postgresql.meta) platforms;
};
};
in
buildEnv {
name = pname;
paths = packages;
pathsToLink = [
"/lib"
"/share/postgresql/extension"
];
passthru = {
inherit versions numberOfVersions pname;
version =
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
};
}