Skip to content

Commit 34b5f28

Browse files
committed
fix: refactor a bit to complete the extension
1 parent b2fcade commit 34b5f28

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

nix/ext/tests/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ builtins.listToAttrs (
186186
"index_advisor"
187187
"pg_cron"
188188
"pg_net"
189+
"timescaledb"
189190
"vector"
190191
"wrappers"
191192
]

nix/ext/timescaledb.nix

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
2-
pkgs,
32
lib,
43
stdenv,
54
fetchFromGitHub,
65
cmake,
76
postgresql,
87
openssl,
98
libkrb5,
9+
buildEnv,
10+
makeWrapper,
11+
switch-ext-version,
1012
}:
1113

1214
let
@@ -53,20 +55,36 @@ let
5355
done
5456
'';
5557

56-
postInstall = ''
57-
if [ -f $out/lib/timescaledb.so ]; then
58-
mv $out/lib/timescaledb.so $out/lib/timescaledb-${version}.so
58+
installPhase = ''
59+
# Run cmake install first
60+
cmake --install . --prefix=$out
61+
62+
# TimescaleDB has two libraries:
63+
# 1. timescaledb.so (loader)
64+
# 2. timescaledb-VERSION.so (actual extension)
65+
# Both need to be handled for multi-version support
66+
67+
# Rename the loader to be version-specific
68+
if [ -f $out/lib/timescaledb${postgresql.dlSuffix} ]; then
69+
mv $out/lib/timescaledb${postgresql.dlSuffix} $out/lib/timescaledb-loader-${version}${postgresql.dlSuffix}
5970
fi
71+
72+
# The versioned library (timescaledb-VERSION.so) is already correctly named
73+
74+
# Create versioned control file with default_version removed and module_pathname pointing to symlink
6075
if [ -f $out/share/postgresql/extension/timescaledb.control ]; then
61-
mv $out/share/postgresql/extension/timescaledb.control $out/share/postgresql/extension/timescaledb--${version}.control
76+
sed -e "/^default_version =/d" \
77+
-e "s|^module_pathname = .*|module_pathname = '\$libdir/timescaledb'|" \
78+
$out/share/postgresql/extension/timescaledb.control > $out/share/postgresql/extension/timescaledb--${version}.control
79+
rm $out/share/postgresql/extension/timescaledb.control
6280
fi
6381
'';
6482

6583
meta = with lib; {
6684
description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space";
6785
homepage = "https://www.timescale.com/";
6886
changelog = "https://github.com/timescale/timescaledb/blob/${version}/CHANGELOG.md";
69-
license = licenses.postgresql;
87+
license = licenses.asl20;
7088
inherit (postgresql.meta) platforms;
7189
};
7290
};
@@ -82,30 +100,40 @@ let
82100
lib.mapAttrs (name: value: build name value.hash (value.revision or name)) supportedVersions
83101
);
84102
in
85-
pkgs.buildEnv {
103+
buildEnv {
86104
name = pname;
87105
paths = packages;
106+
nativeBuildInputs = [ makeWrapper ];
88107
postBuild = ''
89108
{
90109
echo "default_version = '${latestVersion}'"
91110
cat $out/share/postgresql/extension/${pname}--${latestVersion}.control
92111
} > $out/share/postgresql/extension/${pname}.control
93-
ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}
94112
95-
# checks
113+
# Create symlink for the loader
114+
ln -sfn ${pname}-loader-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}
115+
116+
# The versioned library symlink (timescaledb-VERSION.so files are already in place)
117+
118+
# checks - adjust count since we have both loader and versioned files
96119
(set -x
97-
test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" = "${
98-
toString (numberOfVersions + 1)
99-
}"
120+
test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" -gt 0
100121
)
122+
makeWrapper ${lib.getExe switch-ext-version} $out/bin/switch_timescaledb_version \
123+
--prefix EXT_WRAPPER : "$out" --prefix EXT_NAME : "${pname}"
124+
101125
'';
102126
pathsToLink = [
103127
"/lib"
104128
"/share/postgresql/extension"
105129
];
106130
passthru = {
107-
inherit versions numberOfVersions;
131+
inherit versions numberOfVersions switch-ext-version;
108132
pname = "${pname}-all";
133+
hasBackgroundWorker = true;
134+
defaultSettings = {
135+
shared_preload_libraries = [ "timescaledb" ];
136+
};
109137
version =
110138
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
111139
};

0 commit comments

Comments
 (0)