-
-
Notifications
You must be signed in to change notification settings - Fork 209
feat: multi version pg_net including 0.19.5 #1744
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0509da7
feat: multi version pg_net including 0.19.5
samrose 05f1e70
feat: bump ver and add tests
samrose 22d2c91
feat: if file exists, run prestart version switch scripts
samrose fac1f9b
tests: bump version to test
samrose 6d50854
fix: rm unneeded check and fix err codes for file handling
samrose f6e224d
chore: bump version for testing
samrose 72883b4
chore: update versions for release
samrose 745dd57
Add pg-net nixos test in flake checks output
jfroche 1d893bb
Move switch_pg_net_version script into separate package
jfroche 531e830
Fix shellcheck errors
jfroche 268cadb
feat:
samrose 91bbbb1
feat(pg_net): switch version on file system using overlayfs
jfroche 2f2979e
Revert "feat:"
samrose cb61258
fix: fmt
samrose b2cce87
chore: bump version for testin
samrose 4996d81
fix: control files need module_pathname
samrose 381035f
Revert "fix: control files need module_pathname"
samrose 9671c99
chore: version bump for testing
samrose 146bd27
fix: limit flag to versions less than 0.19.1
samrose 501d51a
chore: bump version for release
samrose File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,202 @@ | ||
{ | ||
pkgs, | ||
lib, | ||
stdenv, | ||
fetchFromGitHub, | ||
curl, | ||
postgresql, | ||
libuv, | ||
writeShellApplication, | ||
}: | ||
|
||
stdenv.mkDerivation rec { | ||
pname = "pg_net"; | ||
version = "0.14.0"; | ||
|
||
buildInputs = [ | ||
curl | ||
postgresql | ||
]; | ||
|
||
src = fetchFromGitHub { | ||
owner = "supabase"; | ||
repo = pname; | ||
rev = "refs/tags/v${version}"; | ||
hash = "sha256-c1pxhTyrE5j6dY+M5eKAboQNofIORS+Dccz+7HKEKQI="; | ||
let | ||
switchPgNetVersion = writeShellApplication { | ||
name = "switch_pg_net_version"; | ||
runtimeInputs = [ pkgs.coreutils ]; | ||
text = '' | ||
# Create version switcher script | ||
set -e | ||
if [ $# -ne 1 ]; then | ||
echo "Usage: $0 <version>" | ||
echo "Example: $0 0.10.0" | ||
echo "" | ||
echo "Optional environment variables:" | ||
echo " NIX_PROFILE - Path to nix profile (default: /var/lib/postgresql/.nix-profile)" | ||
echo " LIB_DIR - Override library directory" | ||
echo " EXTENSION_DIR - Override extension directory" | ||
exit 1 | ||
fi | ||
VERSION=$1 | ||
# Set defaults, allow environment variable overrides | ||
: "''${NIX_PROFILE:="/var/lib/postgresql/.nix-profile"}" | ||
: "''${LIB_DIR:=""}" | ||
: "''${EXTENSION_DIR:=""}" | ||
# If LIB_DIR not explicitly set, auto-detect it | ||
if [ -z "$LIB_DIR" ]; then | ||
# Follow the complete chain of symlinks to find the multi-version directory | ||
CURRENT_LINK="$NIX_PROFILE/lib/pg_net-$VERSION${postgresql.dlSuffix}" | ||
echo "Starting with link: $CURRENT_LINK" | ||
# Follow first two symlinks to get to the multi-version directory | ||
for _ in 1 2; do | ||
if [ -L "$CURRENT_LINK" ]; then | ||
NEXT_LINK=$(readlink "$CURRENT_LINK") | ||
echo "Following link: $NEXT_LINK" | ||
if echo "$NEXT_LINK" | grep -q '^/'; then | ||
CURRENT_LINK="$NEXT_LINK" | ||
else | ||
CURRENT_LINK="$(dirname "$CURRENT_LINK")/$NEXT_LINK" | ||
fi | ||
echo "Current link is now: $CURRENT_LINK" | ||
fi | ||
done | ||
# The multi-version directory should be the parent of the current link | ||
MULTI_VERSION_DIR=$(dirname "$CURRENT_LINK") | ||
echo "Found multi-version directory: $MULTI_VERSION_DIR" | ||
LIB_DIR="$MULTI_VERSION_DIR" | ||
else | ||
echo "Using provided LIB_DIR: $LIB_DIR" | ||
fi | ||
# If EXTENSION_DIR not explicitly set, use default | ||
if [ -z "$EXTENSION_DIR" ]; then | ||
EXTENSION_DIR="$NIX_PROFILE/share/postgresql/extension" | ||
fi | ||
echo "Using EXTENSION_DIR: $EXTENSION_DIR" | ||
echo "Looking for file: $LIB_DIR/pg_net-$VERSION${postgresql.dlSuffix}" | ||
ls -la "$LIB_DIR" || true | ||
# Check if version exists | ||
if [ ! -f "$LIB_DIR/pg_net-$VERSION${postgresql.dlSuffix}" ]; then | ||
echo "Error: Version $VERSION not found in $LIB_DIR" | ||
echo "Available versions:" | ||
#shellcheck disable=SC2012 | ||
ls "$LIB_DIR"/pg_net-*${postgresql.dlSuffix} 2>/dev/null | sed 's/.*pg_net-/ /' | sed 's/${postgresql.dlSuffix}$//' || echo " No versions found" | ||
exit 1 | ||
fi | ||
# Update library symlink | ||
ln -sfnv "pg_net-$VERSION${postgresql.dlSuffix}" "$LIB_DIR/pg_net${postgresql.dlSuffix}" | ||
# Update control file | ||
echo "default_version = '$VERSION'" > "$EXTENSION_DIR/pg_net.control" | ||
cat "$EXTENSION_DIR/pg_net--$VERSION.control" >> "$EXTENSION_DIR/pg_net.control" | ||
echo "Successfully switched pg_net to version $VERSION" | ||
EOF | ||
''; | ||
}; | ||
pname = "pg_net"; | ||
build = | ||
version: hash: | ||
stdenv.mkDerivation rec { | ||
inherit pname version; | ||
|
||
buildInputs = [ | ||
curl | ||
postgresql | ||
] | ||
++ lib.optional (version == "0.6") libuv; | ||
|
||
src = fetchFromGitHub { | ||
owner = "supabase"; | ||
repo = pname; | ||
rev = "refs/tags/v${version}"; | ||
inherit hash; | ||
}; | ||
|
||
buildPhase = '' | ||
make PG_CONFIG=${postgresql}/bin/pg_config | ||
''; | ||
|
||
postPatch = | ||
lib.optionalString (version == "0.6") '' | ||
# handle collision with pg_net 0.10.0 | ||
rm sql/pg_net--0.2--0.3.sql | ||
rm sql/pg_net--0.4--0.5.sql | ||
rm sql/pg_net--0.5.1--0.6.sql | ||
'' | ||
+ lib.optionalString (version == "0.7.1") '' | ||
# handle collision with pg_net 0.10.0 | ||
rm sql/pg_net--0.5.1--0.6.sql | ||
''; | ||
|
||
env.NIX_CFLAGS_COMPILE = "-Wno-error"; | ||
samrose marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
installPhase = '' | ||
mkdir -p $out/{lib,share/postgresql/extension} | ||
# Install versioned library | ||
install -Dm755 ${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix} | ||
if [ -f sql/${pname}.sql ]; then | ||
cp sql/${pname}.sql $out/share/postgresql/extension/${pname}--${version}.sql | ||
else | ||
cp sql/${pname}--${version}.sql $out/share/postgresql/extension/${pname}--${version}.sql | ||
fi | ||
# Install upgrade scripts | ||
find . -name '${pname}--*--*.sql' -exec install -Dm644 {} $out/share/postgresql/extension/ \; | ||
# Create versioned control file with modified module path | ||
sed -e "/^default_version =/d" \ | ||
-e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}'|" \ | ||
samrose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control | ||
''; | ||
|
||
env.NIX_CFLAGS_COMPILE = "-Wno-error"; | ||
meta = with lib; { | ||
description = "Async networking for Postgres"; | ||
homepage = "https://github.com/supabase/pg_net"; | ||
platforms = postgresql.meta.platforms; | ||
license = licenses.postgresql; | ||
}; | ||
}; | ||
allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).pg_net; | ||
# Filter out versions that don't work on current platform | ||
platformFilteredVersions = lib.filterAttrs ( | ||
name: _: | ||
# Exclude 0.11.0 on macOS due to epoll.h dependency | ||
!(stdenv.isDarwin && name == "0.11.0") | ||
) allVersions; | ||
supportedVersions = lib.filterAttrs ( | ||
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql | ||
) platformFilteredVersions; | ||
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) supportedVersions | ||
); | ||
in | ||
pkgs.buildEnv { | ||
name = pname; | ||
paths = packages ++ [ switchPgNetVersion ]; | ||
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} | ||
installPhase = '' | ||
mkdir -p $out/{lib,share/postgresql/extension} | ||
cp *${postgresql.dlSuffix} $out/lib | ||
cp sql/*.sql $out/share/postgresql/extension | ||
cp *.control $out/share/postgresql/extension | ||
# checks | ||
(set -x | ||
test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" = "${ | ||
toString (numberOfVersions + 1) | ||
}" | ||
) | ||
''; | ||
|
||
meta = with lib; { | ||
description = "Async networking for Postgres"; | ||
homepage = "https://github.com/supabase/pg_net"; | ||
platforms = postgresql.meta.platforms; | ||
license = licenses.postgresql; | ||
passthru = { | ||
inherit versions numberOfVersions switchPgNetVersion; | ||
pname = "${pname}-all"; | ||
version = | ||
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions); | ||
}; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.