Skip to content

feat: multiple versions for the timescaledb-apache extension #1641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,32 @@ on:

permissions:
id-token: write
# required by testinfra-ami-build dependent workflows
# required by dependent workflows
contents: write
packages: write

jobs:
nix-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
- id: set-matrix
name: Generate Nix Matrix
run: |
set -Eeu
matrix="$(nix eval --json '.#githubActions.matrix')"
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"

build-run-image:
name: ${{ matrix.name }} (${{ matrix.system }})
needs: nix-matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- runner: large-linux-x86
arch: amd64
- runner: large-linux-arm
arch: arm64
- runner: macos-latest-xlarge
arch: arm64
runs-on: ${{ matrix.runner }}
matrix: ${{fromJSON(needs.nix-matrix.outputs.matrix)}}
timeout-minutes: 180
steps:
- name: Checkout Repo
Expand Down Expand Up @@ -104,23 +113,12 @@ jobs:
sudo rm -rf /tmp/* 2>/dev/null || true
echo "=== AFTER CLEANUP ==="
df -h
- name: Build psql bundle
run: >
nix run "github:Mic92/nix-fast-build?rev=b1dae483ab7d4139a6297e02b6de9e5d30e43d48"
-- --skip-cached --no-nom ${{ matrix.runner == 'macos-latest-xlarge' && '--max-jobs 1' || '' }}
--flake ".#checks.$(nix eval --raw --impure --expr 'builtins.currentSystem')"
- run: nix build -L '.#${{ matrix.attr }}'
env:
AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}
AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }}

run-testinfra:
needs: build-run-image
if: ${{ success() }}
uses: ./.github/workflows/testinfra-ami-build.yml
secrets:
DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }}

run-tests:
needs: build-run-image
if: ${{ success() }}
Expand Down
21 changes: 21 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
git-hooks.url = "github:cachix/git-hooks.nix";
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
nixpkgs-go124.url = "github:Nixos/nixpkgs/d2ac4dfa61fba987a84a0a81555da57ae0b9a2b0";
nix-github-actions.url = "github:nix-community/nix-github-actions";
nix-github-actions.inputs.nixpkgs.follows = "nixpkgs";
};

outputs =
Expand All @@ -36,6 +38,7 @@
nix/nixpkgs.nix
nix/packages
nix/overlays
nix/github-actions.nix
];
});
}
65 changes: 0 additions & 65 deletions nix/ext/timescaledb-2.9.1.nix

This file was deleted.

138 changes: 96 additions & 42 deletions nix/ext/timescaledb.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
pkgs,
lib,
stdenv,
fetchFromGitHub,
Expand All @@ -8,51 +9,104 @@
libkrb5,
}:

stdenv.mkDerivation rec {
pname = "timescaledb-apache";
version = "2.16.1";
let
pname = "timescaledb";
build =
version: hash: _revision:
stdenv.mkDerivation rec {
inherit pname version;

nativeBuildInputs = [ cmake ];
buildInputs = [
postgresql
openssl
libkrb5
];
nativeBuildInputs = [ cmake ];
buildInputs = [
postgresql
openssl
libkrb5
];

src = fetchFromGitHub {
owner = "timescale";
repo = "timescaledb";
rev = version;
hash = "sha256-sLxWdBmih9mgiO51zLLxn9uwJVYc5JVHJjSWoADoJ+w=";
};
src = fetchFromGitHub {
owner = "timescale";
repo = "timescaledb";
rev = version;
inherit hash;
};

cmakeFlags = [
"-DSEND_TELEMETRY_DEFAULT=OFF"
"-DREGRESS_CHECKS=OFF"
"-DTAP_CHECKS=OFF"
"-DAPACHE_ONLY=1"
] ++ lib.optionals stdenv.isDarwin [ "-DLINTER=OFF" ];

# Fix the install phase which tries to install into the pgsql extension dir,
# and cannot be manually overridden. This is rather fragile but works OK.
postPatch = ''
for x in CMakeLists.txt sql/CMakeLists.txt; do
substituteInPlace "$x" \
--replace 'DESTINATION "''${PG_SHAREDIR}/extension"' "DESTINATION \"$out/share/postgresql/extension\""
done

for x in src/CMakeLists.txt src/loader/CMakeLists.txt tsl/src/CMakeLists.txt; do
substituteInPlace "$x" \
--replace 'DESTINATION ''${PG_PKGLIBDIR}' "DESTINATION \"$out/lib\""
done
'';
cmakeFlags = [
"-DSEND_TELEMETRY_DEFAULT=OFF"
"-DREGRESS_CHECKS=OFF"
"-DTAP_CHECKS=OFF"
"-DAPACHE_ONLY=1"
] ++ lib.optionals stdenv.isDarwin [ "-DLINTER=OFF" ];

postPatch = ''
for x in CMakeLists.txt sql/CMakeLists.txt; do
if [ -f "$x" ]; then
substituteInPlace "$x" \
--replace 'DESTINATION "''${PG_SHAREDIR}/extension"' "DESTINATION \"$out/share/postgresql/extension\""
fi
done

for x in src/CMakeLists.txt src/loader/CMakeLists.txt tsl/src/CMakeLists.txt; do
if [ -f "$x" ]; then
substituteInPlace "$x" \
--replace 'DESTINATION ''${PG_PKGLIBDIR}' "DESTINATION \"$out/lib\""
fi
done
'';

meta = with lib; {
description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space";
homepage = "https://www.timescale.com/";
changelog = "https://github.com/timescale/timescaledb/blob/${version}/CHANGELOG.md";
platforms = postgresql.meta.platforms;
license = licenses.asl20;
broken = versionOlder postgresql.version "13";
postInstall = ''
if [ -f $out/lib/timescaledb.so ]; then
mv $out/lib/timescaledb.so $out/lib/timescaledb-${version}.so
fi
if [ -f $out/share/postgresql/extension/timescaledb.control ]; then
mv $out/share/postgresql/extension/timescaledb.control $out/share/postgresql/extension/timescaledb--${version}.control
fi
'';

meta = with lib; {
description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space";
homepage = "https://www.timescale.com/";
changelog = "https://github.com/timescale/timescaledb/blob/${version}/CHANGELOG.md";
license = licenses.postgresql;
inherit (postgresql.meta) platforms;
};
};

allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).timescaledb;
supportedVersions = lib.filterAttrs (
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
) allVersions;
versions = lib.naturalSort (lib.attrNames supportedVersions);
latestVersion = lib.last versions;
numberOfVersions = builtins.length versions;
packages = builtins.attrValues (
lib.mapAttrs (name: value: build name value.hash (value.revision or name)) supportedVersions
);
in
pkgs.buildEnv {
name = pname;
paths = packages;
postBuild = ''
{
echo "default_version = '${latestVersion}'"
cat $out/share/postgresql/extension/${pname}--${latestVersion}.control
} > $out/share/postgresql/extension/${pname}.control
ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}

# checks
(set -x
test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" = "${
toString (numberOfVersions + 1)
}"
)
'';
pathsToLink = [
"/lib"
"/share/postgresql/extension"
];
passthru = {
inherit versions numberOfVersions;
pname = "${pname}-all";
version =
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
};
}
14 changes: 14 additions & 0 deletions nix/ext/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,19 @@
],
"hash": "sha256-G0eQk2bY5CNPMeokN/nb05g03CuiplRf902YXFVQFbs="
}
},
"timescaledb": {
"2.9.1": {
"postgresql": [
"15"
],
"hash": "sha256-fvVSxDiGZAewyuQ2vZDb0I6tmlDXl6trjZp8+qDBtb8="
},
"2.16.1": {
"postgresql": [
"15"
],
"hash": "sha256-sLxWdBmih9mgiO51zLLxn9uwJVYc5JVHJjSWoADoJ+w="
}
}
}
18 changes: 18 additions & 0 deletions nix/github-actions.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ inputs, ... }:
let
githubPlatforms = {
"x86_64-linux" = "large-linux-x86";
"aarch64-linux" = "large-linux-arm";
"aarch64-darwin" = "macos-latest-xlarge";
};
in
{
flake.githubActions = inputs.nix-github-actions.lib.mkGithubMatrix {
checks = inputs.nixpkgs.lib.getAttrs [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
] inputs.self.checks;
platforms = githubPlatforms;
};
}
1 change: 0 additions & 1 deletion nix/packages/postgres.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
ourExtensions = [
../ext/rum.nix
../ext/timescaledb.nix
../ext/timescaledb-2.9.1.nix
../ext/pgroonga.nix
../ext/index_advisor.nix
../ext/wal2json.nix
Expand Down
Loading
Loading