Skip to content

Commit dec38be

Browse files
committed
feat: WIP fix to pgroonga
1 parent 47d598f commit dec38be

File tree

5 files changed

+159
-5
lines changed

5 files changed

+159
-5
lines changed

flake.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
sfcgal = pkgs.callPackage ./nix/ext/sfcgal/sfcgal.nix { };
6464
pg_regress = pkgs.callPackage ./nix/ext/pg_regress.nix { };
65-
65+
supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
6666
# Our list of PostgreSQL extensions which come from upstream Nixpkgs.
6767
# These are maintained upstream and can easily be used here just by
6868
# listing their name. Anytime the version of nixpkgs is upgraded, these
@@ -265,6 +265,7 @@
265265
# name in 'nix flake show' in order to make sure exactly what name you
266266
# want.
267267
basePackages = {
268+
supabase-groonga = supabase-groonga;
268269
# PostgreSQL versions.
269270
psql_15 = makePostgres "15";
270271
#psql_16 = makePostgres "16";
@@ -285,7 +286,8 @@
285286
--subst-var-by 'PGSQL_SUPERUSER' '${pgsqlSuperuser}' \
286287
--subst-var-by 'PSQL15_BINDIR' '${basePackages.psql_15.bin}' \
287288
--subst-var-by 'PSQL_CONF_FILE' '${configFile}' \
288-
--subst-var-by 'PGSODIUM_GETKEY' '${getkeyScript}'
289+
--subst-var-by 'PGSODIUM_GETKEY' '${getkeyScript}'\
290+
--subst-var-by 'MECAB_LIB' '${basePackages.psql_15.exts.pgroonga}/lib/groonga/plugins/tokenizers/tokenizer_mecab.so'
289291
290292
chmod +x $out/bin/start-postgres-server
291293
'';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Do not use vendored libraries
2+
3+
--- a/vendor/CMakeLists.txt
4+
+++ b/vendor/CMakeLists.txt
5+
@@ -14,10 +14,7 @@
6+
# License along with this library; if not, write to the Free Software
7+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
8+
9+
add_subdirectory(onigmo)
10+
-add_subdirectory(mruby)
11+
-add_subdirectory(mecab)
12+
-add_subdirectory(message_pack)
13+
if(GRN_WITH_MRUBY)
14+
add_subdirectory(groonga-log)
15+
endif()

nix/ext/pgroonga.nix

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
{ lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, groonga }:
2-
1+
{ lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, mecab, callPackage}:
2+
let
3+
supabase-groonga = callPackage ../supabase-groonga.nix { };
4+
in
35
stdenv.mkDerivation rec {
46
pname = "pgroonga";
57
version = "3.0.7";
@@ -10,11 +12,26 @@ stdenv.mkDerivation rec {
1012
};
1113

1214
nativeBuildInputs = [ pkg-config ];
13-
buildInputs = [ postgresql msgpack-c groonga ];
15+
buildInputs = [ postgresql msgpack-c supabase-groonga mecab ];
16+
17+
preConfigure = ''
18+
export MECAB_CONFIG=${mecab}/bin/mecab-config
19+
export MECAB_DICDIR=${mecab}/lib/mecab/dic/ipadic
20+
export GRN_PLUGINS_DIR=$out/lib/groonga/plugins
21+
export GROONGA_TOKENIZER_MECAB_DIR=${supabase-groonga}/lib/groonga/plugins/tokenizers
22+
'';
23+
24+
configureFlags = [
25+
"--with-mecab=${mecab}"
26+
"--enable-tokenizer-mecab"
27+
"--with-groonga-tokenizer-mecab=$out/lib/groonga/plugins/tokenizer_mecab.so"
28+
"--with-groonga-plugin-dir=${supabase-groonga}/lib/groonga/plugins"
29+
];
1430

1531
makeFlags = [
1632
"HAVE_MSGPACK=1"
1733
"MSGPACK_PACKAGE_NAME=msgpack-c"
34+
"HAVE_MECAB=1"
1835
];
1936

2037
installPhase = ''
@@ -25,6 +42,11 @@ stdenv.mkDerivation rec {
2542
install -D pgroonga_database${postgresql.dlSuffix} -t $out/lib/
2643
install -D pgroonga_database.control -t $out/share/postgresql/extension
2744
install -D data/pgroonga_database-*.sql -t $out/share/postgresql/extension
45+
46+
mkdir -p $out/lib/groonga/plugins
47+
48+
# Create symbolic link for MeCab tokenizer
49+
cp ${supabase-groonga}/lib/groonga/plugins/tokenizers/mecab.so $out/lib/groonga/plugins/tokenizer_mecab.so
2850
'';
2951

3052
meta = with lib; {

nix/fix-cmake-install-path.patch

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Fix CMake install path
2+
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -1141,11 +1141,11 @@
6+
7+
set(prefix "${CMAKE_INSTALL_PREFIX}")
8+
set(exec_prefix "\${prefix}")
9+
-set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
10+
-set(sbindir "\${exec_prefix}/${CMAKE_INSTALL_SBINDIR}")
11+
-set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
12+
-set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
13+
-set(datarootdir "\${prefix}/${CMAKE_INSTALL_DATAROOTDIR}")
14+
+set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
15+
+set(sbindir "${CMAKE_INSTALL_FULL_SBINDIR}")
16+
+set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
17+
+set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
18+
+set(datarootdir "${CMAKE_INSTALL_FULL_DATAROOTDIR}")
19+
set(datadir "\${datarootdir}")
20+
set(expanded_pluginsdir "${GRN_PLUGINS_DIR}")
21+
set(GRN_EXPANDED_DEFAULT_DOCUMENT_ROOT "${GRN_DEFAULT_DOCUMENT_ROOT}")

nix/supabase-groonga.nix

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{ lib, stdenv, cmake, fetchurl, kytea, msgpack-c, mecab, pkg-config, rapidjson, testers, xxHash, zstd, postgresqlPackages, makeWrapper
2+
, suggestSupport ? false, zeromq, libevent, openssl
3+
, lz4Support ? false, lz4
4+
, zlibSupport ? true, zlib
5+
, writeShellScriptBin
6+
}:
7+
stdenv.mkDerivation (finalAttrs: {
8+
pname = "supabase-groonga";
9+
version = "14.0.5";
10+
src = fetchurl {
11+
url = "https://packages.groonga.org/source/groonga/groonga-${finalAttrs.version}.tar.gz";
12+
hash = "sha256-y4UGnv8kK0z+br8wXpPf57NMXkdEJHcLCuTvYiubnIc=";
13+
};
14+
patches = [
15+
./fix-cmake-install-path.patch
16+
./do-not-use-vendored-libraries.patch
17+
];
18+
nativeBuildInputs = [
19+
cmake
20+
pkg-config
21+
makeWrapper
22+
];
23+
buildInputs = [
24+
rapidjson
25+
xxHash
26+
zstd
27+
mecab
28+
kytea
29+
msgpack-c
30+
] ++ lib.optionals lz4Support [
31+
lz4
32+
] ++ lib.optional zlibSupport [
33+
zlib
34+
] ++ lib.optionals suggestSupport [
35+
zeromq
36+
libevent
37+
];
38+
cmakeFlags = [
39+
"-DWITH_MECAB=ON"
40+
"-DMECAB_DICDIR=${mecab}/lib/mecab/dic/ipadic"
41+
"-DMECAB_CONFIG=${mecab}/bin/mecab-config"
42+
"-DENABLE_MECAB_TOKENIZER=ON"
43+
"-DMECAB_INCLUDE_DIR=${mecab}/include"
44+
"-DMECAB_LIBRARY=${mecab}/lib/libmecab.so"
45+
"-DGROONGA_ENABLE_TOKENIZER_MECAB=YES"
46+
"-DGRN_WITH_MECAB=YES"
47+
];
48+
preConfigure = ''
49+
export MECAB_DICDIR=${mecab}/lib/mecab/dic/ipadic
50+
echo "MeCab dictionary directory: $MECAB_DICDIR"
51+
'';
52+
buildPhase = ''
53+
cmake --build . -- VERBOSE=1
54+
grep -i mecab CMakeCache.txt || (echo "MeCab not detected in CMake cache" && exit 1)
55+
echo "CMake cache contents related to MeCab:"
56+
grep -i mecab CMakeCache.txt
57+
'';
58+
postInstall = ''
59+
echo "Searching for MeCab-related files:"
60+
find $out -name "*mecab*"
61+
62+
echo "Checking Groonga plugins directory:"
63+
ls -l $out/lib/groonga/plugins
64+
65+
echo "Wrapping Groonga binary:"
66+
wrapProgram $out/bin/groonga \
67+
--set GRN_PLUGINS_DIR $out/lib/groonga/plugins
68+
69+
'';
70+
env.NIX_CFLAGS_COMPILE = lib.optionalString zlibSupport "-I${zlib.dev}/include";
71+
passthru = {
72+
tests = {
73+
inherit (postgresqlPackages) pgroonga;
74+
version = testers.testVersion {
75+
package = finalAttrs.finalPackage;
76+
};
77+
pkg-config = testers.hasPkgConfigModules {
78+
package = finalAttrs.finalPackage;
79+
moduleNames = [ "groonga" ];
80+
};
81+
};
82+
};
83+
meta = with lib; {
84+
homepage = "https://groonga.org/";
85+
description = "Open-source fulltext search engine and column store";
86+
license = licenses.lgpl21;
87+
maintainers = [ maintainers.ericsagnes ];
88+
platforms = platforms.all;
89+
longDescription = ''
90+
Groonga is an open-source fulltext search engine and column store.
91+
It lets you write high-performance applications that requires fulltext search.
92+
'';
93+
};
94+
})

0 commit comments

Comments
 (0)