Skip to content
Open
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
19 changes: 19 additions & 0 deletions nix/cargo-pgrx/versions.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
{
"0.5.6": {
"hash": "sha256-CbQWgt/M/QVKpuOzY04OEZNX4DauYPMz2404WQlAvTw=",
"rust": {
"1.83.0": {
"cargoHash": "sha256-sqAOhSZXzqxOVkEbqpd+9MoXqEFlkFufQ8O1zAXPnLQ="
}
}
},
"0.6.1": {
"hash": "sha256-O4eHVbJBudybsPab+zr2eXnfheREMqLAHAKm2GDbfrs=",
"rust": {
"1.82.0": {
"cargoHash": "sha256-MucGrA3qXgJOcT2LMNmoNOhQi8QA3LuqgZEHKycLCCo="
},
"1.83.0": {
"cargoHash": "sha256-MucGrA3qXgJOcT2LMNmoNOhQi8QA3LuqgZEHKycLCCo="
}
}
},
Expand All @@ -15,6 +26,14 @@
}
}
},
"0.8.3": {
"hash": "sha256-1SdGPhyT/m65De3QTpEYAGvzbB6eLH1yUZ8XoN9LaVc=",
"rust": {
"1.70.0": {
"cargoHash": "sha256-uFSv2mwn0dmIo6AG5Wz3THOwdE9B2PQQF10kiG/3qLU="
}
}
},
"0.9.5": {
"hash": "sha256-GpXQUOBuojAqPXyRR+k8AVW2XzBbn6V0+2dhP4w4Vs8=",
"rust": {
Expand Down
19 changes: 18 additions & 1 deletion nix/docs/update-extension.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Update an existing nix extension

## Overview
Expand Down Expand Up @@ -224,3 +223,21 @@ The `nix flake check -L` command is your primary local testing tool:
```bash
nix flake check -L 2>&1 | tee build.log
```

---

### Automating updates with `nix/ext/scripts/update_versions_json.py`

A helper script is at `nix/ext/scripts/update_versions_json.py`. It updates `nix/ext/versions.json` for a given extension by fetching all git tags from the provided repository, keeping only tags that parse as valid version numbers, and computing SRI hashes for each version (the part this mainly aims to automate).

Example usage, Step 1: add tags as ignored placeholders (fast, no hash computation):
```bash
./nix/ext/scripts/update_versions_json.py pg_graphql https://github.com/supabase/pg_graphql --ignore
```

Step 2: remove the versions of interest from the generated list, then re-run the script without `--ignore` to this time compute hashes (this indeed requires `nix`, network access, and may take some time):
```bash
./nix/ext/scripts/update_versions_json.py pg_graphql https://github.com/supabase/pg_graphql
```

After running the script, run the usual verification steps (e.g., `nix build .#psql_15/exts/<extension>-all` and `nix flake check -L`) to validate the new versions.
90 changes: 90 additions & 0 deletions nix/ext/scripts/update_versions_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3 git nix-prefetch-git python3Packages.packaging

import subprocess
import json
import argparse
from pathlib import Path
from typing import Dict, List, Union
from packaging.version import parse as parse_version, InvalidVersion

Schema = Dict[str, Dict[str, Dict[str, Union[List[str], str, bool]]]]

POSTGRES_VERSIONS: List[str] = ["15", "17"]
VERSIONS_JSON_PATH = "versions.json"


def run(cmd: List[str]) -> str:
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
return result.stdout.strip()


def get_tags(url: str) -> Dict[str, str]:
output = run(["git", "ls-remote", "--tags", url])
tags: Dict[str, str] = {}
for line in output.splitlines():
if "^{}" not in line:
parts = line.split("\t")
if len(parts) == 2:
commit_hash, ref = parts
if ref.startswith("refs/tags/"):
tag = ref.removeprefix("refs/tags/")
try:
parse_version(tag)
except InvalidVersion:
continue
tags[tag] = commit_hash
return tags


def get_sri_hash(url: str, commit_hash: str) -> str:
output = run(["nix-prefetch-git", "--quiet", "--url", url, "--rev", commit_hash])
nix_hash = json.loads(output)["sha256"]
return "sha256-" + run(["nix", "hash", "to-base64", "--type", "sha256", nix_hash])


def load() -> Schema:
if not Path(VERSIONS_JSON_PATH).exists():
return {}
with open(VERSIONS_JSON_PATH, "r", encoding="utf-8") as f:
return json.load(f)


def build(name: str, url: str, data: Schema, ignore: bool = False) -> Schema:
tags = get_tags(url)
versions = data.get(name, {})
for tag, commit_hash in tags.items():
if tag in versions:
continue
if ignore:
versions[tag] = {"ignore": True}
else:
sri_hash = get_sri_hash(url, commit_hash)
versions[tag] = {"postgresql": POSTGRES_VERSIONS, "hash": sri_hash}
data[name] = versions
return data


def save(data: Schema) -> None:
sorted_data = {}
for name, versions in data.items():
sorted_data[name] = dict(
sorted(versions.items(), key=lambda item: parse_version(item[0]))
)
with open(VERSIONS_JSON_PATH, "w", encoding="utf-8") as f:
json.dump(sorted_data, f, indent=2)
f.write("\n")


def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("extension_name")
parser.add_argument("git_repo_url")
parser.add_argument("--ignore", action="store_true")
args = parser.parse_args()

save(build(args.extension_name, args.git_repo_url, load(), ignore=args.ignore))


if __name__ == "__main__":
main()
123 changes: 122 additions & 1 deletion nix/ext/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@
"hash": "sha256-QC77AnPGpPQGEWi6JtJdiNsB2su5+aV2pKg5ImR2B0k="
}
},

"pgsodium": {
"3.0.4": {
"postgresql": [
Expand Down Expand Up @@ -572,6 +571,110 @@
}
},
"wrappers": {
"0.1.7": {
"postgresql": [
"15"
],
"hash": "sha256-aGq46W12XTxGH1KKxk2re0ul+9h0n/OIrFLsylS+Y3U=",
"pgrx": "0.6.1",
"rust": "1.82.0"
},
"0.1.8": {
"postgresql": [
"15"
],
"hash": "sha256-9h5T10mD4W7hEDdbtxkyxiY/pACX1Io33UGetGOlCZA=",
"pgrx": "0.6.1",
"rust": "1.82.0"
},
"0.1.9": {
"postgresql": [
"15"
],
"hash": "sha256-VZxbvPXwOGMbyLHMXFwAMbtzdapDA73qN+2obUdLR5Q=",
"pgrx": "0.6.1",
"rust": "1.82.0"
},
"0.1.10": {
"postgresql": [
"15"
],
"hash": "sha256-472lVh91iqaMNHJk21LUvPIrhm3yIzrvDbNHyUW8aBs=",
"pgrx": "0.6.1",
"rust": "1.82.0"
},
"0.1.11": {
"postgresql": [
"15"
],
"hash": "sha256-3zN8uWeQwVQCQ37+PyLC4wX9oiji6s2L3aIpWYcD28g=",
"pgrx": "0.6.1",
"rust": "1.82.0"
},
"0.1.12": {
"postgresql": [
"15"
],
"hash": "sha256-TScNbX+PBWUYgrBEnFXOaeXXfiOIa488H1oyIAw6v7I=",
"pgrx": "0.8.3",
"rust": "1.70.0"
},
"0.1.14": {
"postgresql": [
"15"
],
"hash": "sha256-w6rijRFUlWmwv4XE0G99ip2GkBF4nGTaX94kQvNRmJs=",
"pgrx": "0.8.3",
"rust": "1.70.0"
},
"0.1.15": {
"postgresql": [
"15"
],
"hash": "sha256-R5MvaCx3BwX8NVDqJPJfCOppC2XtKIshh58Hkbw6VHg=",
"pgrx": "0.9.7",
"rust": "1.70.0"
},
"0.1.16": {
"postgresql": [
"15"
],
"hash": "sha256-pfbTGC/cBgv+YuwJ1qMQpb4jZm6n5uvCFLZLS/ZWcfs=",
"pgrx": "0.9.7",
"rust": "1.70.0"
},
"0.1.17": {
"postgresql": [
"15"
],
"hash": "sha256-Wm4O98ms0/J9z/m4s4eYyxiRwTZhSqd9KpxvY42xyNE=",
"pgrx": "0.10.2",
"rust": "1.76.0"
},
"0.1.18": {
"postgresql": [
"15"
],
"hash": "sha256-E4ql7D/lkb/J3Rr1kMEo37KxbFnqYPCdhuAIpVFLgB8=",
"pgrx": "0.10.2",
"rust": "1.76.0"
},
"0.1.19": {
"postgresql": [
"15"
],
"hash": "sha256-wvsAqDk+1am6mSBCF5uzDArnbBIpLqTylLzF4VZ/p08=",
"pgrx": "0.10.2",
"rust": "1.76.0"
},
"0.2.0": {
"postgresql": [
"15"
],
"hash": "sha256-F+S5uyubL3Tb3RTJ08Zf9gN8oLE/WkCWFA8RcKkDqes=",
"pgrx": "0.11.3",
"rust": "1.76.0"
},
"0.3.0": {
"postgresql": [
"15"
Expand Down Expand Up @@ -640,6 +743,24 @@
"pgrx": "0.12.9",
"rust": "1.84.0"
},
"0.5.1": {
"postgresql": [
"15",
"17"
],
"hash": "sha256-3GfN3vZMFWf4FV/fSOe9ZN6KETmjoNw3Paz+JRzaH3c=",
"pgrx": "0.12.9",
"rust": "1.87.0"
},
"0.5.2": {
"postgresql": [
"15",
"17"
],
"hash": "sha256-9VqQHduoAWnY8gtfRZLDOKiibfwuSTzyVFbH0uhsfCU=",
"pgrx": "0.14.3",
"rust": "1.87.0"
},
"0.5.3": {
"postgresql": [
"15",
Expand Down
59 changes: 29 additions & 30 deletions nix/ext/wrappers/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,22 @@ let
CARGO_BUILD_JOBS = "2";
CARGO = "${cargo}/bin/cargo";

# this workaround the fact that "${src}/Cargo.lock" mismatch a patched Cargo.lock
postPatch =
if builtins.pathExists ./v${version}/Cargo.lock then
"cp ${./v${version}/Cargo.lock} ./Cargo.lock"
else
"";

cargoLock = {
lockFile = "${src}/Cargo.lock";
lockFile =
if builtins.pathExists ./v${version} then ./v${version}/Cargo.lock else "${src}/Cargo.lock";
outputHashes =
if builtins.compareVersions "0.4.2" version >= 0 then
if builtins.compareVersions "0.1.11" version >= 0 then
{ "clickhouse-rs-1.0.0-alpha.1" = "sha256-EDMgIpDdkyW3ZG+8LSC4pis8DbHnPIabHRxuc23DPJU="; }
else if builtins.compareVersions "0.3.0" version >= 0 then
{ "clickhouse-rs-1.0.0-alpha.1" = "sha256-0zmoUo/GLyCKDLkpBsnLAyGs1xz6cubJhn+eVqMEMaw="; }
else if builtins.compareVersions "0.4.2" version >= 0 then
{ "clickhouse-rs-1.0.0-alpha.1" = "sha256-0zmoUo/GLyCKDLkpBsnLAyGs1xz6cubJhn+eVqMEMaw="; }
else if builtins.compareVersions "0.5.0" version >= 0 then
{ "clickhouse-rs-1.1.0-alpha.1" = "sha256-G+v4lNP5eK2U45D1fL90Dq24pUSlpIysNCxuZ17eac0="; }
Expand Down Expand Up @@ -105,6 +117,8 @@ let
};
};

pgrxBinaryName = if builtins.compareVersions "0.7.4" pgrxVersion >= 0 then "pgx" else "pgrx";

preConfigure = ''
cd wrappers

Expand All @@ -130,7 +144,7 @@ let
{ print }
' Cargo.toml

# Verify the file is still valid TOML, break build with this erroru
# Verify the file is still valid TOML, break build with this error
# if it is not
if ! cargo verify-project 2>/dev/null; then
echo "Failed to maintain valid TOML syntax"
Expand Down Expand Up @@ -165,45 +179,30 @@ let
inherit (postgresql.meta) platforms;
};
}
// lib.optionalAttrs (version == "0.3.0") {
patches = [ ./0001-bump-pgrx-to-0.11.3.patch ];

cargoLock = {
lockFile = ./Cargo.lock-0.3.0;
outputHashes = {
"clickhouse-rs-1.0.0-alpha.1" = "sha256-0zmoUo/GLyCKDLkpBsnLAyGs1xz6cubJhn+eVqMEMaw=";
};
};
# TODO: there is an inference error on crate `time` caused by an API change in Rust 1.80.0;
# so we should patch `Cargo.toml` with `time >= 0.3.35`, to use a more recent Rust version!
// lib.optionalAttrs (version == "0.3.0") { patches = [ ./v0.3.0/0001-bump-pgrx-to-0.11.3.patch ]; }
// lib.optionalAttrs (version == "0.2.0") { patches = [ ./v0.2.0/0001-bump-pgrx-to-0.11.3.patch ]; }
// lib.optionalAttrs (version == "0.1.10") {
patches = [ ./v0.1.10/0001-bump-aws-config-to-0.55.3.patch ];
}
);
# All versions that were previously packaged (historical list)
allPreviouslyPackagedVersions = [
"0.4.3"
"0.4.2"
"0.4.1"
"0.3.0"
"0.2.0"
"0.1.19"
"0.1.18"
"0.1.17"
"0.1.16"
"0.1.15"
"0.1.14"
"0.1.12"
"0.1.11"
"0.1.10"
"0.1.9"
"0.1.8"
"0.1.7"
"0.1.6"
"0.1.5"
# Versions of wrapper extension prior to 0.1.5 are using pgx 0.5.6 that doesn't support PostgreSQL 14+
# Bumping to pgx 0.6.1 requires signicant code changes, described e.g. in the patch:
# nix/ext/wrappers/v0.1.4/0002-bump-pgrx-to-0.6.1.patch
"0.1.4"
"0.1.1"
"0.1.0"
];
allVersions = (builtins.fromJSON (builtins.readFile ../versions.json)).wrappers;
supportedVersions = lib.filterAttrs (
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
_: value:
(!value ? ignore || value.ignore != true)
&& builtins.elem (lib.versions.major postgresql.version) value.postgresql
) allVersions;
versions = lib.naturalSort (lib.attrNames supportedVersions);
latestVersion = lib.last versions;
Expand Down
Loading
Loading