Skip to content

Commit 921c2d8

Browse files
jfrochesamrose
authored andcommitted
fix: plv8 3.1 requires older v8
We cannot use nodejs.libv8 as it is too new for plv8 3.1. We will be able to use it with plv8 3.2.
1 parent a1d5ea4 commit 921c2d8

File tree

2 files changed

+162
-13
lines changed

2 files changed

+162
-13
lines changed

nix/ext/pgrouting.nix

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
}:
1111
let
1212
pname = "pgrouting";
13-
<<<<<<< HEAD
14-
=======
15-
version = "3.8.0";
16-
>>>>>>> 054e04ac (chore: bump `pgrouting` version to 3.8.0)
1713

1814
# Load version configuration from external file
1915
allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname};
@@ -126,19 +122,10 @@ buildEnv {
126122
"/share/postgresql/extension"
127123
];
128124

129-
<<<<<<< HEAD
130125
postBuild = ''
131126
#Verify all expected library files are present
132127
expectedFiles=${toString (numberOfVersions + 1)}
133128
actualFiles=$(ls -l $out/lib/lib${pname}*${postgresql.dlSuffix} | wc -l)
134-
=======
135-
src = fetchFromGitHub {
136-
owner = "pgRouting";
137-
repo = pname;
138-
rev = "v${version}";
139-
hash = "sha256-Lvf7TQ3GywbzZmcd9wi3s8I5sCXIQAPeXNTRk/J46to=";
140-
};
141-
>>>>>>> 054e04ac (chore: bump `pgrouting` version to 3.8.0)
142129
143130
if [[ "$actualFiles" != "$expectedFiles" ]]; then
144131
echo "Error: Expected $expectedFiles library files, found $actualFiles"

nix/ext/plv8.nix

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
{
2+
stdenv,
3+
lib,
4+
fetchFromGitHub,
5+
perl,
6+
postgresql,
7+
# For passthru test on various systems, and local development on macos
8+
# not we are not currently using passthru tests but retaining for possible contrib
9+
# to nixpkgs
10+
clang,
11+
xcbuild,
12+
darwin,
13+
patchelf,
14+
}:
15+
let
16+
# plv8 3.1 requires an older version of v8 (we cannot use nodejs.libv8)
17+
node_pkgs = import (fetchTarball {
18+
url = "https://github.com/nixos/nixpkgs/archive/a76c4553d7e741e17f289224eda135423de0491d.tar.gz";
19+
sha256 = "0rwdzp942b8ay625lqgra83qrp64b3wqm6w9a0i4z593df8x822v";
20+
}) { system = stdenv.system; };
21+
inherit (node_pkgs) v8;
22+
in
23+
stdenv.mkDerivation (finalAttrs: {
24+
pname = "plv8";
25+
version = "3.1.10";
26+
27+
src = fetchFromGitHub {
28+
owner = "plv8";
29+
repo = "plv8";
30+
rev = "v${finalAttrs.version}";
31+
hash = "sha256-g1A/XPC0dX2360Gzvmo9/FSQnM6Wt2K4eR0pH0p9fz4=";
32+
};
33+
34+
patches = [
35+
# Allow building with system v8.
36+
# https://github.com/plv8/plv8/pull/505 (rejected)
37+
./0001-build-Allow-using-V8-from-system.patch
38+
];
39+
40+
nativeBuildInputs =
41+
[ perl ]
42+
++ lib.optionals stdenv.isDarwin [
43+
clang
44+
xcbuild
45+
];
46+
47+
buildInputs =
48+
[
49+
v8
50+
postgresql
51+
]
52+
++ lib.optionals stdenv.isDarwin [
53+
darwin.apple_sdk.frameworks.CoreFoundation
54+
darwin.apple_sdk.frameworks.Kerberos
55+
];
56+
57+
buildFlags = [ "all" ];
58+
59+
makeFlags =
60+
[
61+
# Nixpkgs build a v8 monolith instead of separate v8_libplatform.
62+
"USE_SYSTEM_V8=1"
63+
"V8_OUTDIR=${v8}/lib"
64+
"PG_CONFIG=${postgresql}/bin/pg_config"
65+
]
66+
++ lib.optionals stdenv.isDarwin [
67+
"CC=${clang}/bin/clang"
68+
"CXX=${clang}/bin/clang++"
69+
"SHLIB_LINK=-L${v8}/lib -lv8_monolith -Wl,-rpath,${v8}/lib"
70+
]
71+
++ lib.optionals (!stdenv.isDarwin) [ "SHLIB_LINK=-lv8" ];
72+
73+
NIX_LDFLAGS = (
74+
lib.optionals stdenv.isDarwin [
75+
"-L${postgresql}/lib"
76+
"-L${v8}/lib"
77+
"-lv8_monolith"
78+
"-lpq"
79+
"-lpgcommon"
80+
"-lpgport"
81+
"-F${darwin.apple_sdk.frameworks.CoreFoundation}/Library/Frameworks"
82+
"-framework"
83+
"CoreFoundation"
84+
"-F${darwin.apple_sdk.frameworks.Kerberos}/Library/Frameworks"
85+
"-framework"
86+
"Kerberos"
87+
"-undefined"
88+
"dynamic_lookup"
89+
"-flat_namespace"
90+
]
91+
);
92+
93+
installFlags = [
94+
# PGXS only supports installing to postgresql prefix so we need to redirect this
95+
"DESTDIR=${placeholder "out"}"
96+
];
97+
98+
# No configure script.
99+
dontConfigure = true;
100+
101+
postPatch = ''
102+
patchShebangs ./generate_upgrade.sh
103+
substituteInPlace generate_upgrade.sh \
104+
--replace " 2.3.10 " " 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.15 "
105+
106+
${lib.optionalString stdenv.isDarwin ''
107+
# Replace g++ with clang++ in Makefile
108+
sed -i 's/g++/clang++/g' Makefile
109+
''}
110+
'';
111+
112+
postInstall = ''
113+
# Move the redirected to proper directory.
114+
# There appear to be no references to the install directories
115+
# so changing them does not cause issues.
116+
mv "$out/nix/store"/*/* "$out"
117+
rmdir "$out/nix/store"/* "$out/nix/store" "$out/nix"
118+
119+
# Handle different PostgreSQL versions
120+
if [ "${lib.versions.major postgresql.version}" = "15" ]; then
121+
mv "$out/lib/plv8-${finalAttrs.version}.so" "$out/lib/plv8.so"
122+
ln -s "$out/lib/plv8.so" "$out/lib/plv8-${finalAttrs.version}.so"
123+
sed -i 's|module_pathname = '"'"'$libdir/plv8-[0-9.]*'"'"'|module_pathname = '"'"'$libdir/plv8'"'"'|' "$out/share/postgresql/extension/plv8.control"
124+
sed -i 's|module_pathname = '"'"'$libdir/plv8-[0-9.]*'"'"'|module_pathname = '"'"'$libdir/plv8'"'"'|' "$out/share/postgresql/extension/plcoffee.control"
125+
sed -i 's|module_pathname = '"'"'$libdir/plv8-[0-9.]*'"'"'|module_pathname = '"'"'$libdir/plv8'"'"'|' "$out/share/postgresql/extension/plls.control"
126+
127+
${lib.optionalString stdenv.isDarwin ''
128+
install_name_tool -add_rpath "${v8}/lib" $out/lib/plv8.so
129+
install_name_tool -add_rpath "${postgresql}/lib" $out/lib/plv8.so
130+
install_name_tool -add_rpath "${stdenv.cc.cc.lib}/lib" $out/lib/plv8.so
131+
install_name_tool -change @rpath/libv8_monolith.dylib ${v8}/lib/libv8_monolith.dylib $out/lib/plv8.so
132+
''}
133+
134+
${lib.optionalString (!stdenv.isDarwin) ''
135+
${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${stdenv.cc.cc.lib}/lib" $out/lib/plv8.so
136+
''}
137+
else
138+
${lib.optionalString stdenv.isDarwin ''
139+
install_name_tool -add_rpath "${v8}/lib" $out/lib/plv8-${finalAttrs.version}${postgresql.dlSuffix}
140+
install_name_tool -add_rpath "${postgresql}/lib" $out/lib/plv8-${finalAttrs.version}${postgresql.dlSuffix}
141+
install_name_tool -add_rpath "${stdenv.cc.cc.lib}/lib" $out/lib/plv8-${finalAttrs.version}${postgresql.dlSuffix}
142+
install_name_tool -change @rpath/libv8_monolith.dylib ${v8}/lib/libv8_monolith.dylib $out/lib/plv8-${finalAttrs.version}${postgresql.dlSuffix}
143+
''}
144+
145+
${lib.optionalString (!stdenv.isDarwin) ''
146+
${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${stdenv.cc.cc.lib}/lib" $out/lib/plv8-${finalAttrs.version}${postgresql.dlSuffix}
147+
''}
148+
fi
149+
'';
150+
151+
meta = with lib; {
152+
description = "V8 Engine Javascript Procedural Language add-on for PostgreSQL";
153+
homepage = "https://plv8.github.io/";
154+
platforms = [
155+
"x86_64-linux"
156+
"aarch64-linux"
157+
"aarch64-darwin"
158+
"x86_64-darwin"
159+
];
160+
license = licenses.postgresql;
161+
};
162+
})

0 commit comments

Comments
 (0)