|
1 | 1 | { |
2 | | - pkgs, |
3 | 2 | lib, |
4 | 3 | stdenv, |
5 | 4 | fetchFromGitHub, |
6 | 5 | cmake, |
7 | 6 | postgresql, |
8 | 7 | openssl, |
9 | 8 | libkrb5, |
| 9 | + buildEnv, |
| 10 | + makeWrapper, |
| 11 | + switch-ext-version, |
10 | 12 | }: |
11 | 13 |
|
12 | 14 | let |
|
53 | 55 | done |
54 | 56 | ''; |
55 | 57 |
|
56 | | - postInstall = '' |
57 | | - if [ -f $out/lib/timescaledb.so ]; then |
58 | | - mv $out/lib/timescaledb.so $out/lib/timescaledb-${version}.so |
| 58 | + installPhase = '' |
| 59 | + # Run cmake install first |
| 60 | + cmake --install . --prefix=$out |
| 61 | +
|
| 62 | + # TimescaleDB has two libraries: |
| 63 | + # 1. timescaledb.so (loader) |
| 64 | + # 2. timescaledb-VERSION.so (actual extension) |
| 65 | + # Both need to be handled for multi-version support |
| 66 | +
|
| 67 | + # Rename the loader to be version-specific |
| 68 | + if [ -f $out/lib/timescaledb${postgresql.dlSuffix} ]; then |
| 69 | + mv $out/lib/timescaledb${postgresql.dlSuffix} $out/lib/timescaledb-loader-${version}${postgresql.dlSuffix} |
59 | 70 | fi |
| 71 | +
|
| 72 | + # The versioned library (timescaledb-VERSION.so) is already correctly named |
| 73 | +
|
| 74 | + # Create versioned control file with default_version removed and module_pathname pointing to symlink |
60 | 75 | if [ -f $out/share/postgresql/extension/timescaledb.control ]; then |
61 | | - mv $out/share/postgresql/extension/timescaledb.control $out/share/postgresql/extension/timescaledb--${version}.control |
| 76 | + sed -e "/^default_version =/d" \ |
| 77 | + -e "s|^module_pathname = .*|module_pathname = '\$libdir/timescaledb'|" \ |
| 78 | + $out/share/postgresql/extension/timescaledb.control > $out/share/postgresql/extension/timescaledb--${version}.control |
| 79 | + rm $out/share/postgresql/extension/timescaledb.control |
62 | 80 | fi |
63 | 81 | ''; |
64 | 82 |
|
65 | 83 | meta = with lib; { |
66 | 84 | description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space"; |
67 | 85 | homepage = "https://www.timescale.com/"; |
68 | 86 | changelog = "https://github.com/timescale/timescaledb/blob/${version}/CHANGELOG.md"; |
69 | | - license = licenses.postgresql; |
| 87 | + license = licenses.asl20; |
70 | 88 | inherit (postgresql.meta) platforms; |
71 | 89 | }; |
72 | 90 | }; |
|
82 | 100 | lib.mapAttrs (name: value: build name value.hash (value.revision or name)) supportedVersions |
83 | 101 | ); |
84 | 102 | in |
85 | | -pkgs.buildEnv { |
| 103 | +buildEnv { |
86 | 104 | name = pname; |
87 | 105 | paths = packages; |
| 106 | + nativeBuildInputs = [ makeWrapper ]; |
88 | 107 | postBuild = '' |
89 | 108 | { |
90 | 109 | echo "default_version = '${latestVersion}'" |
91 | 110 | cat $out/share/postgresql/extension/${pname}--${latestVersion}.control |
92 | 111 | } > $out/share/postgresql/extension/${pname}.control |
93 | | - ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix} |
94 | 112 |
|
95 | | - # checks |
| 113 | + # Create symlink for the loader |
| 114 | + ln -sfn ${pname}-loader-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix} |
| 115 | +
|
| 116 | + # The versioned library symlink (timescaledb-VERSION.so files are already in place) |
| 117 | +
|
| 118 | + # checks - adjust count since we have both loader and versioned files |
96 | 119 | (set -x |
97 | | - test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" = "${ |
98 | | - toString (numberOfVersions + 1) |
99 | | - }" |
| 120 | + test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" -gt 0 |
100 | 121 | ) |
| 122 | + makeWrapper ${lib.getExe switch-ext-version} $out/bin/switch_timescaledb_version \ |
| 123 | + --prefix EXT_WRAPPER : "$out" --prefix EXT_NAME : "${pname}" |
| 124 | +
|
101 | 125 | ''; |
102 | 126 | pathsToLink = [ |
103 | 127 | "/lib" |
104 | 128 | "/share/postgresql/extension" |
105 | 129 | ]; |
106 | 130 | passthru = { |
107 | | - inherit versions numberOfVersions; |
| 131 | + inherit versions numberOfVersions switch-ext-version; |
108 | 132 | pname = "${pname}-all"; |
| 133 | + hasBackgroundWorker = true; |
| 134 | + defaultSettings = { |
| 135 | + shared_preload_libraries = [ "timescaledb" ]; |
| 136 | + }; |
109 | 137 | version = |
110 | 138 | "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions); |
111 | 139 | }; |
|
0 commit comments