1{ lib, stdenv, fetchFromGitHub, cmake, postgresql, openssl, libkrb5, enableUnfree ? true }:
2
3# # To enable on NixOS:
4# config.services.postgresql = let
5# # The postgresql pkgs has to be taken from the
6# # postgresql package used, so the extensions
7# # are built for the correct postgresql version.
8# postgresqlPackages = config.services.postgresql.package.pkgs;
9# in {
10# extraPlugins = with postgresqlPackages; [ timescaledb ];
11# settings.shared_preload_libraries = "timescaledb";
12# }
13
14stdenv.mkDerivation rec {
15 pname = "timescaledb${lib.optionalString (!enableUnfree) "-apache"}";
16 version = "2.11.2";
17
18 nativeBuildInputs = [ cmake ];
19 buildInputs = [ postgresql openssl libkrb5 ];
20
21 src = fetchFromGitHub {
22 owner = "timescale";
23 repo = "timescaledb";
24 rev = version;
25 sha256 = "sha256-c2fztGtl2cLThT0JhHCM0UaYkiWTp5T6TUZ3Au7CG7c=";
26 };
27
28 cmakeFlags = [ "-DSEND_TELEMETRY_DEFAULT=OFF" "-DREGRESS_CHECKS=OFF" "-DTAP_CHECKS=OFF" ]
29 ++ lib.optionals (!enableUnfree) [ "-DAPACHE_ONLY=ON" ]
30 ++ lib.optionals stdenv.isDarwin [ "-DLINTER=OFF" ];
31
32 # Fix the install phase which tries to install into the pgsql extension dir,
33 # and cannot be manually overridden. This is rather fragile but works OK.
34 postPatch = ''
35 for x in CMakeLists.txt sql/CMakeLists.txt; do
36 substituteInPlace "$x" \
37 --replace 'DESTINATION "''${PG_SHAREDIR}/extension"' "DESTINATION \"$out/share/postgresql/extension\""
38 done
39
40 for x in src/CMakeLists.txt src/loader/CMakeLists.txt tsl/src/CMakeLists.txt; do
41 substituteInPlace "$x" \
42 --replace 'DESTINATION ''${PG_PKGLIBDIR}' "DESTINATION \"$out/lib\""
43 done
44 '';
45
46 meta = with lib; {
47 description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space";
48 homepage = "https://www.timescale.com/";
49 changelog = "https://github.com/timescale/timescaledb/raw/${version}/CHANGELOG.md";
50 maintainers = with maintainers; [ marsam ];
51 platforms = postgresql.meta.platforms;
52 license = with licenses; if enableUnfree then tsl else asl20;
53 broken = versionOlder postgresql.version "12";
54 };
55}