|
| 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 | +} |
0 commit comments