|
6 | 6 | postgresql,
|
7 | 7 | openssl,
|
8 | 8 | libkrb5,
|
| 9 | + buildEnv, |
| 10 | + makeWrapper, |
| 11 | + switch-ext-version, |
| 12 | + coreutils, |
| 13 | + writeShellApplication, |
9 | 14 | }:
|
10 | 15 |
|
11 |
| -stdenv.mkDerivation rec { |
12 |
| - pname = "timescaledb-apache"; |
13 |
| - version = "2.16.1"; |
| 16 | +let |
| 17 | + pname = "timescaledb"; |
| 18 | + build = |
| 19 | + version: hash: _revision: |
| 20 | + stdenv.mkDerivation rec { |
| 21 | + inherit pname version; |
14 | 22 |
|
15 |
| - nativeBuildInputs = [ cmake ]; |
16 |
| - buildInputs = [ |
17 |
| - postgresql |
18 |
| - openssl |
19 |
| - libkrb5 |
20 |
| - ]; |
| 23 | + nativeBuildInputs = [ cmake ]; |
| 24 | + buildInputs = [ |
| 25 | + postgresql |
| 26 | + openssl |
| 27 | + libkrb5 |
| 28 | + ]; |
| 29 | + |
| 30 | + src = fetchFromGitHub { |
| 31 | + owner = "timescale"; |
| 32 | + repo = "timescaledb"; |
| 33 | + rev = version; |
| 34 | + inherit hash; |
| 35 | + }; |
| 36 | + |
| 37 | + cmakeFlags = [ |
| 38 | + "-DSEND_TELEMETRY_DEFAULT=OFF" |
| 39 | + "-DREGRESS_CHECKS=OFF" |
| 40 | + "-DTAP_CHECKS=OFF" |
| 41 | + "-DAPACHE_ONLY=1" |
| 42 | + ] ++ lib.optionals stdenv.isDarwin [ "-DLINTER=OFF" ]; |
| 43 | + |
| 44 | + postPatch = '' |
| 45 | + for x in CMakeLists.txt sql/CMakeLists.txt; do |
| 46 | + if [ -f "$x" ]; then |
| 47 | + substituteInPlace "$x" \ |
| 48 | + --replace 'DESTINATION "''${PG_SHAREDIR}/extension"' "DESTINATION \"$out/share/postgresql/extension\"" |
| 49 | + fi |
| 50 | + done |
| 51 | +
|
| 52 | + for x in src/CMakeLists.txt src/loader/CMakeLists.txt tsl/src/CMakeLists.txt; do |
| 53 | + if [ -f "$x" ]; then |
| 54 | + substituteInPlace "$x" \ |
| 55 | + --replace 'DESTINATION ''${PG_PKGLIBDIR}' "DESTINATION \"$out/lib\"" |
| 56 | + fi |
| 57 | + done |
| 58 | + ''; |
| 59 | + |
| 60 | + installPhase = '' |
| 61 | + # Run cmake install first |
| 62 | + cmake --install . --prefix=$out |
| 63 | +
|
| 64 | + # TimescaleDB creates two libraries: |
| 65 | + # 1. timescaledb.so (loader) -> rename to timescaledb-<version>-loader.so |
| 66 | + # 2. timescaledb-<version>.so (actual extension) -> keep as is |
| 67 | +
|
| 68 | + # Rename the loader library to be version-specific |
| 69 | + if [ -f $out/lib/timescaledb${postgresql.dlSuffix} ]; then |
| 70 | + mv $out/lib/timescaledb${postgresql.dlSuffix} $out/lib/timescaledb-loader-${version}${postgresql.dlSuffix} |
| 71 | + fi |
21 | 72 |
|
22 |
| - src = fetchFromGitHub { |
23 |
| - owner = "timescale"; |
24 |
| - repo = "timescaledb"; |
25 |
| - rev = version; |
26 |
| - hash = "sha256-sLxWdBmih9mgiO51zLLxn9uwJVYc5JVHJjSWoADoJ+w="; |
| 73 | + # The versioned library (timescaledb-VERSION.so) is already correctly named |
| 74 | +
|
| 75 | + # Create versioned control file with default_version removed and module_pathname pointing to symlink |
| 76 | + if [ -f $out/share/postgresql/extension/timescaledb.control ]; then |
| 77 | + sed -e "/^default_version =/d" \ |
| 78 | + -e "s|^module_pathname = .*|module_pathname = '\$libdir/timescaledb'|" \ |
| 79 | + $out/share/postgresql/extension/timescaledb.control > $out/share/postgresql/extension/timescaledb--${version}.control |
| 80 | + rm $out/share/postgresql/extension/timescaledb.control |
| 81 | + fi |
| 82 | + ''; |
| 83 | + |
| 84 | + meta = with lib; { |
| 85 | + description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space"; |
| 86 | + homepage = "https://www.timescale.com/"; |
| 87 | + changelog = "https://github.com/timescale/timescaledb/blob/${version}/CHANGELOG.md"; |
| 88 | + license = licenses.asl20; |
| 89 | + inherit (postgresql.meta) platforms; |
| 90 | + }; |
| 91 | + }; |
| 92 | + |
| 93 | + allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).timescaledb; |
| 94 | + supportedVersions = lib.filterAttrs ( |
| 95 | + _: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql |
| 96 | + ) allVersions; |
| 97 | + versions = lib.naturalSort (lib.attrNames supportedVersions); |
| 98 | + latestVersion = lib.last versions; |
| 99 | + numberOfVersions = builtins.length versions; |
| 100 | + packages = builtins.attrValues ( |
| 101 | + lib.mapAttrs (name: value: build name value.hash (value.revision or name)) supportedVersions |
| 102 | + ); |
| 103 | + switch-timescaledb-loader = writeShellApplication { |
| 104 | + name = "switch_timescaledb_loader"; |
| 105 | + runtimeInputs = [ coreutils ]; |
| 106 | + text = '' |
| 107 | + EXT_LOADER_TO_USE="$EXT_WRAPPER_LIB/$EXT_NAME-loader-$VERSION${postgresql.dlSuffix}" |
| 108 | + if [ -f "$EXT_LOADER_TO_USE" ]; then |
| 109 | + ln -sfnv "$EXT_LOADER_TO_USE" "$EXT_WRAPPER_LIB/$EXT_NAME${postgresql.dlSuffix}" |
| 110 | + fi |
| 111 | + ''; |
27 | 112 | };
|
| 113 | +in |
| 114 | +buildEnv { |
| 115 | + name = pname; |
| 116 | + paths = packages; |
| 117 | + nativeBuildInputs = [ makeWrapper ]; |
| 118 | + postBuild = '' |
| 119 | + { |
| 120 | + echo "default_version = '${latestVersion}'" |
| 121 | + cat $out/share/postgresql/extension/${pname}--${latestVersion}.control |
| 122 | + } > $out/share/postgresql/extension/${pname}.control |
| 123 | +
|
| 124 | + # Create symlink from the latest versioned loader to timescaledb.so |
| 125 | + ln -sfn ${pname}-loader-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix} |
28 | 126 |
|
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 |
| 127 | + # The versioned extension libraries (timescaledb-VERSION.so) are already in place |
| 128 | +
|
| 129 | + # checks - we should have loader files and versioned extension files |
| 130 | + (set -x |
| 131 | + test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" -gt 0 |
| 132 | + ) |
| 133 | + makeWrapper ${lib.getExe switch-ext-version} $out/bin/switch_timescaledb_version \ |
| 134 | + --prefix EXT_WRAPPER : "$out" --prefix EXT_NAME : "${pname}" --prefix EXTRA_STEPS : ${lib.getExe switch-timescaledb-loader} |
48 | 135 | '';
|
49 | 136 |
|
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"; |
| 137 | + pathsToLink = [ |
| 138 | + "/lib" |
| 139 | + "/share/postgresql/extension" |
| 140 | + ]; |
| 141 | + |
| 142 | + passthru = { |
| 143 | + inherit versions numberOfVersions switch-ext-version; |
| 144 | + pname = "${pname}-all"; |
| 145 | + hasBackgroundWorker = true; |
| 146 | + defaultSettings = { |
| 147 | + shared_preload_libraries = [ "timescaledb" ]; |
| 148 | + }; |
| 149 | + version = |
| 150 | + "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions); |
57 | 151 | };
|
58 | 152 | }
|
0 commit comments