|
1 | 1 | {
|
| 2 | + pkgs, |
2 | 3 | lib,
|
3 | 4 | stdenv,
|
4 | 5 | fetchFromGitHub,
|
|
8 | 9 | libkrb5,
|
9 | 10 | }:
|
10 | 11 |
|
11 |
| -stdenv.mkDerivation rec { |
12 |
| - pname = "timescaledb-apache"; |
13 |
| - version = "2.16.1"; |
| 12 | +let |
| 13 | + pname = "timescaledb"; |
| 14 | + build = |
| 15 | + version: hash: _revision: |
| 16 | + stdenv.mkDerivation rec { |
| 17 | + inherit pname version; |
14 | 18 |
|
15 |
| - nativeBuildInputs = [ cmake ]; |
16 |
| - buildInputs = [ |
17 |
| - postgresql |
18 |
| - openssl |
19 |
| - libkrb5 |
20 |
| - ]; |
| 19 | + nativeBuildInputs = [ cmake ]; |
| 20 | + buildInputs = [ |
| 21 | + postgresql |
| 22 | + openssl |
| 23 | + libkrb5 |
| 24 | + ]; |
21 | 25 |
|
22 |
| - src = fetchFromGitHub { |
23 |
| - owner = "timescale"; |
24 |
| - repo = "timescaledb"; |
25 |
| - rev = version; |
26 |
| - hash = "sha256-sLxWdBmih9mgiO51zLLxn9uwJVYc5JVHJjSWoADoJ+w="; |
27 |
| - }; |
| 26 | + src = fetchFromGitHub { |
| 27 | + owner = "timescale"; |
| 28 | + repo = "timescaledb"; |
| 29 | + rev = version; |
| 30 | + inherit hash; |
| 31 | + }; |
28 | 32 |
|
29 |
| - cmakeFlags = [ |
30 |
| - "-DSEND_TELEMETRY_DEFAULT=OFF" |
31 |
| - "-DREGRESS_CHECKS=OFF" |
32 |
| - "-DTAP_CHECKS=OFF" |
33 |
| - "-DAPACHE_ONLY=1" |
34 |
| - ] ++ lib.optionals stdenv.isDarwin [ "-DLINTER=OFF" ]; |
35 |
| - |
36 |
| - # Fix the install phase which tries to install into the pgsql extension dir, |
37 |
| - # and cannot be manually overridden. This is rather fragile but works OK. |
38 |
| - postPatch = '' |
39 |
| - for x in CMakeLists.txt sql/CMakeLists.txt; do |
40 |
| - substituteInPlace "$x" \ |
41 |
| - --replace 'DESTINATION "''${PG_SHAREDIR}/extension"' "DESTINATION \"$out/share/postgresql/extension\"" |
42 |
| - done |
43 |
| -
|
44 |
| - for x in src/CMakeLists.txt src/loader/CMakeLists.txt tsl/src/CMakeLists.txt; do |
45 |
| - substituteInPlace "$x" \ |
46 |
| - --replace 'DESTINATION ''${PG_PKGLIBDIR}' "DESTINATION \"$out/lib\"" |
47 |
| - done |
48 |
| - ''; |
| 33 | + cmakeFlags = [ |
| 34 | + "-DSEND_TELEMETRY_DEFAULT=OFF" |
| 35 | + "-DREGRESS_CHECKS=OFF" |
| 36 | + "-DTAP_CHECKS=OFF" |
| 37 | + "-DAPACHE_ONLY=1" |
| 38 | + ] ++ lib.optionals stdenv.isDarwin [ "-DLINTER=OFF" ]; |
| 39 | + |
| 40 | + postPatch = '' |
| 41 | + for x in CMakeLists.txt sql/CMakeLists.txt; do |
| 42 | + if [ -f "$x" ]; then |
| 43 | + substituteInPlace "$x" \ |
| 44 | + --replace 'DESTINATION "''${PG_SHAREDIR}/extension"' "DESTINATION \"$out/share/postgresql/extension\"" |
| 45 | + fi |
| 46 | + done |
| 47 | +
|
| 48 | + for x in src/CMakeLists.txt src/loader/CMakeLists.txt tsl/src/CMakeLists.txt; do |
| 49 | + if [ -f "$x" ]; then |
| 50 | + substituteInPlace "$x" \ |
| 51 | + --replace 'DESTINATION ''${PG_PKGLIBDIR}' "DESTINATION \"$out/lib\"" |
| 52 | + fi |
| 53 | + done |
| 54 | + ''; |
49 | 55 |
|
50 |
| - meta = with lib; { |
51 |
| - description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space"; |
52 |
| - homepage = "https://www.timescale.com/"; |
53 |
| - changelog = "https://github.com/timescale/timescaledb/blob/${version}/CHANGELOG.md"; |
54 |
| - platforms = postgresql.meta.platforms; |
55 |
| - license = licenses.asl20; |
56 |
| - broken = versionOlder postgresql.version "13"; |
| 56 | + postInstall = '' |
| 57 | + if [ -f $out/lib/timescaledb.so ]; then |
| 58 | + mv $out/lib/timescaledb.so $out/lib/timescaledb-${version}.so |
| 59 | + fi |
| 60 | + if [ -f $out/share/postgresql/extension/timescaledb.control ]; then |
| 61 | + mv $out/share/postgresql/extension/timescaledb.control $out/share/postgresql/extension/timescaledb--${version}.control |
| 62 | + fi |
| 63 | + ''; |
| 64 | + |
| 65 | + meta = with lib; { |
| 66 | + description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space"; |
| 67 | + homepage = "https://www.timescale.com/"; |
| 68 | + changelog = "https://github.com/timescale/timescaledb/blob/${version}/CHANGELOG.md"; |
| 69 | + license = licenses.postgresql; |
| 70 | + inherit (postgresql.meta) platforms; |
| 71 | + }; |
| 72 | + }; |
| 73 | + |
| 74 | + allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).timescaledb; |
| 75 | + supportedVersions = lib.filterAttrs ( |
| 76 | + _: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql |
| 77 | + ) allVersions; |
| 78 | + versions = lib.naturalSort (lib.attrNames supportedVersions); |
| 79 | + latestVersion = lib.last versions; |
| 80 | + numberOfVersions = builtins.length versions; |
| 81 | + packages = builtins.attrValues ( |
| 82 | + lib.mapAttrs (name: value: build name value.hash (value.revision or name)) supportedVersions |
| 83 | + ); |
| 84 | +in |
| 85 | +pkgs.buildEnv { |
| 86 | + name = pname; |
| 87 | + paths = packages; |
| 88 | + postBuild = '' |
| 89 | + { |
| 90 | + echo "default_version = '${latestVersion}'" |
| 91 | + cat $out/share/postgresql/extension/${pname}--${latestVersion}.control |
| 92 | + } > $out/share/postgresql/extension/${pname}.control |
| 93 | + ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix} |
| 94 | +
|
| 95 | + # checks |
| 96 | + (set -x |
| 97 | + test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" = "${ |
| 98 | + toString (numberOfVersions + 1) |
| 99 | + }" |
| 100 | + ) |
| 101 | + ''; |
| 102 | + pathsToLink = [ |
| 103 | + "/lib" |
| 104 | + "/share/postgresql/extension" |
| 105 | + ]; |
| 106 | + passthru = { |
| 107 | + inherit versions numberOfVersions; |
| 108 | + pname = "${pname}-all"; |
| 109 | + version = |
| 110 | + "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions); |
57 | 111 | };
|
58 | 112 | }
|
0 commit comments