Skip to content

Commit 7d6cd03

Browse files
committed
feat: multiple versions for the timescaledb-apache extension
1 parent 87829eb commit 7d6cd03

File tree

6 files changed

+306
-103
lines changed

6 files changed

+306
-103
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ result*
2525

2626
db/schema.sql
2727
common-nix.vars.pkr.hcl
28+
29+
.envrc

flake.nix

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@
129129
# go through the upstream release engineering process.
130130
ourExtensions = [
131131
./nix/ext/rum.nix
132-
./nix/ext/timescaledb.nix
133-
./nix/ext/timescaledb-2.9.1.nix
132+
./nix/ext/timescaledb-apache.nix
134133
./nix/ext/pgroonga.nix
135134
./nix/ext/index_advisor.nix
136135
./nix/ext/wal2json.nix
@@ -161,16 +160,13 @@
161160
./nix/ext/plv8.nix
162161
];
163162

164-
#Where we import and build the orioledb extension, we add on our custom extensions
165-
# plus the orioledb option
166-
#we're not using timescaledb or plv8 in the orioledb-17 version or pg 17 of supabase extensions
163+
# Where we import and build the orioledb extension, we add on our
164+
# custom extensions plus the orioledb option. We're not using
165+
# timescaledb or plv8 in the orioledb-17 version or pg 17 of supabase
166+
# extensions
167167
orioleFilteredExtensions = builtins.filter
168-
(
169-
x:
170-
x != ./nix/ext/timescaledb.nix &&
171-
x != ./nix/ext/timescaledb-2.9.1.nix &&
172-
x != ./nix/ext/plv8.nix
173-
) ourExtensions;
168+
(x: x != ./nix/ext/timescaledb-apache.nix && x != ./nix/ext/plv8.nix)
169+
ourExtensions;
174170

175171
orioledbExtensions = orioleFilteredExtensions ++ [ ./nix/ext/orioledb.nix ];
176172
dbExtensions17 = orioleFilteredExtensions;

nix/ext/timescaledb-2.9.1.nix

Lines changed: 0 additions & 50 deletions
This file was deleted.

nix/ext/timescaledb-apache.nix

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{ pkgs, lib, stdenv, fetchFromGitHub, cmake, postgresql, openssl, libkrb5 }:
2+
3+
let
4+
pname = "timescaledb-apache";
5+
build = version: hash: revision:
6+
stdenv.mkDerivation rec {
7+
inherit pname version;
8+
9+
nativeBuildInputs = [ cmake ];
10+
buildInputs = [ postgresql openssl libkrb5 ];
11+
12+
src = fetchFromGitHub {
13+
owner = "timescale";
14+
repo = "timescaledb";
15+
rev = version;
16+
inherit hash;
17+
};
18+
19+
cmakeFlags = [
20+
"-DSEND_TELEMETRY_DEFAULT=OFF"
21+
"-DREGRESS_CHECKS=OFF"
22+
"-DTAP_CHECKS=OFF"
23+
"-DAPACHE_ONLY=1"
24+
] ++ lib.optionals stdenv.isDarwin [ "-DLINTER=OFF" ];
25+
26+
# Fix the install phase which tries to install into the pgsql extension dir,
27+
# and cannot be manually overridden. This is rather fragile but works OK.
28+
postPatch = ''
29+
for x in CMakeLists.txt sql/CMakeLists.txt; do
30+
if [ -f "$x" ]; then
31+
substituteInPlace "$x" \
32+
--replace 'DESTINATION "''${PG_SHAREDIR}/extension"' "DESTINATION \"$out/share/postgresql/extension\""
33+
fi
34+
done
35+
36+
for x in src/CMakeLists.txt src/loader/CMakeLists.txt tsl/src/CMakeLists.txt; do
37+
if [ -f "$x" ]; then
38+
substituteInPlace "$x" \
39+
--replace 'DESTINATION ''${PG_PKGLIBDIR}' "DESTINATION \"$out/lib\""
40+
fi
41+
done
42+
'';
43+
44+
# timescaledb-$VERSION.so already exists in the lib directory
45+
# we have no need for the timescaledb.so or control file
46+
postInstall = ''
47+
rm -f $out/lib/timescaledb.so
48+
rm -f $out/share/postgresql/extension/timescaledb.control
49+
'';
50+
51+
meta = with lib; {
52+
description =
53+
"Scales PostgreSQL for time-series data via automatic partitioning across time and space";
54+
homepage = "https://www.timescale.com/";
55+
changelog =
56+
"https://github.com/timescale/timescaledb/blob/${version}/CHANGELOG.md";
57+
license = licenses.postgresql;
58+
inherit (postgresql.meta) platforms;
59+
};
60+
};
61+
62+
allVersions =
63+
(builtins.fromJSON (builtins.readFile ./versions.json)).timescaledb-apache;
64+
supportedVersions = lib.filterAttrs (_: value:
65+
builtins.elem (lib.versions.major postgresql.version) value.postgresql)
66+
allVersions;
67+
versions = lib.naturalSort (lib.attrNames supportedVersions);
68+
latestVersion = lib.last versions;
69+
numberOfVersions = builtins.length versions;
70+
packages = builtins.attrValues
71+
(lib.mapAttrs (name: value: build name value.hash (value.revision or name))
72+
supportedVersions);
73+
in pkgs.buildEnv {
74+
name = pname;
75+
paths = packages;
76+
pathsToLink = [ "/lib" "/share/postgresql/extension" ];
77+
passthru = {
78+
inherit versions numberOfVersions;
79+
pname = "${pname}-all";
80+
version = "multi-" + lib.concatStringsSep "-"
81+
(map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
82+
};
83+
}

nix/ext/timescaledb.nix

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)