Skip to content

Commit 1bdb4b1

Browse files
committed
feat: nearly working
1 parent 8f8b9b0 commit 1bdb4b1

File tree

2 files changed

+101
-205
lines changed

2 files changed

+101
-205
lines changed

flake.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@
288288
--subst-var-by 'PGSQL_SUPERUSER' '${pgsqlSuperuser}' \
289289
--subst-var-by 'PSQL15_BINDIR' '${basePackages.psql_15.bin}' \
290290
--subst-var-by 'PSQL_CONF_FILE' '${configFile}' \
291-
--subst-var-by 'PGSODIUM_GETKEY' '${getkeyScript}'\
292-
--subst-var-by 'MECAB_LIB' '${basePackages.psql_15.exts.pgroonga}/lib/groonga/plugins/tokenizers/tokenizer_mecab.so'
291+
--subst-var-by 'PGSODIUM_GETKEY' '${getkeyScript}'
293292
294293
chmod +x $out/bin/start-postgres-server
295294
'';

nix/ext/pgroonga.nix

Lines changed: 100 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# { lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, mecab, callPackage
2-
# , patchelf }:
1+
# { lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, callPackage
2+
# , makeWrapper, mecab }:
3+
34
# let
45
# supabase-groonga = callPackage ../supabase-groonga.nix { };
56
# mecab-naist-jdic = callPackage ./mecab-naist-jdic { };
@@ -11,195 +12,92 @@
1112
# "https://packages.groonga.org/source/${pname}/${pname}-${version}.tar.gz";
1213
# sha256 = "sha256-iF/zh4zDDpAw5fxW1WG8i2bfPt4VYsnYArwOoE/lwgM=";
1314
# };
14-
# nativeBuildInputs = [ pkg-config patchelf ];
15-
# buildInputs =
16-
# [ postgresql msgpack-c supabase-groonga mecab mecab-naist-jdic ];
17-
15+
# nativeBuildInputs = [ pkg-config makeWrapper ];
16+
# buildInputs = [ postgresql msgpack-c supabase-groonga mecab mecab-naist-jdic ];
17+
18+
# makeFlags = [
19+
# "USE_PGXS=1"
20+
# "HAVE_MSGPACK=1"
21+
# "MSGPACK_PACKAGE_NAME=msgpack-c"
22+
# "HAVE_MECAB=1"
23+
# "POSTGRES_INCLUDEDIR=${postgresql}/include"
24+
# "POSTGRES_LIBDIR=${postgresql.lib}/lib"
25+
# "PG_CONFIG=${postgresql}/bin/pg_config"
26+
# "MECAB_CONFIG=${mecab}/bin/mecab-config"
27+
# "MECAB_LIBRARIES=-L${mecab}/lib -lmecab"
28+
# "GROONGA_INCLUDES=-I${supabase-groonga}/include"
29+
# "GROONGA_LIBS=-L${supabase-groonga}/lib -lgroonga"
30+
# "GROONGA_PLUGIN_LIBS=-L${supabase-groonga}/lib/groonga/plugins"
31+
# ];
32+
1833
# configureFlags = [
1934
# "--with-mecab=${mecab}"
2035
# "--enable-mecab"
21-
# "--enable-groonga-tokenizer-mecab"
36+
# "--with-mecab-config=${mecab}/bin/mecab-config"
2237
# "--with-mecab-dict=${mecab-naist-jdic}/lib/mecab/dic/naist-jdic"
2338
# "--with-groonga=${supabase-groonga}"
24-
# "--with-groonga-token-mecab-dir=${supabase-groonga}/lib/groonga/plugins/tokenizers"
25-
# "--with-groonga-tokenizer-mecab=${supabase-groonga}/lib/groonga/plugins/tokenizers/mecab.so"
2639
# "--with-groonga-plugin-dir=${supabase-groonga}/lib/groonga/plugins"
27-
# "--with-pgconfigdir=${postgresql}/bin"
28-
# "--with-mecab-config=${mecab}/bin/mecab-config"
2940
# ];
3041

31-
# makeFlags =
32-
# [ "HAVE_MSGPACK=1" "MSGPACK_PACKAGE_NAME=msgpack-c" "HAVE_MECAB=1" ];
33-
34-
# buildPhase = ''
35-
# runHook preBuild
36-
# make
37-
# echo "Checking for MeCab-related files:"
38-
# find . -name "*mecab*"
39-
# runHook postBuild
42+
# preConfigure = ''
43+
# export MECAB_DICDIR=${mecab-naist-jdic}/lib/mecab/dic/naist-jdic
44+
# export GROONGA_INCLUDE_PATH=${supabase-groonga}/include
45+
# export GROONGA_LIB_PATH=${supabase-groonga}/lib
46+
# export MECAB_INCLUDE_PATH=${mecab}/include
47+
# export MECAB_LIB_PATH=${mecab}/lib
48+
# export PKG_CONFIG_PATH="${supabase-groonga}/lib/pkgconfig:$PKG_CONFIG_PATH"
49+
# export GRN_PLUGINS_PATH=${supabase-groonga}/lib/groonga/plugins
50+
51+
# # Ensure MeCab is enabled
52+
# sed -i 's|#define HAVE_MECAB 0|#define HAVE_MECAB 1|' src/pgroonga.h
4053
# '';
4154

4255
# installPhase = ''
4356
# runHook preInstall
44-
45-
# install -D pgroonga${postgresql.dlSuffix} -t $out/lib/
46-
# install -D pgroonga.control -t $out/share/postgresql/extension/
47-
# install -D data/pgroonga-*.sql -t $out/share/postgresql/extension/
48-
# install -D pgroonga_database${postgresql.dlSuffix} -t $out/lib/
49-
# install -D pgroonga_database.control -t $out/share/postgresql/extension/
50-
# install -D data/pgroonga_database-*.sql -t $out/share/postgresql/extension/
51-
52-
# # Ensure MeCab tokenizer is available
53-
# if [ -f ${supabase-groonga}/lib/groonga/plugins/tokenizers/mecab.so ]; then
54-
# mkdir -p $out/lib/postgresql/plugins/
55-
# cp ${supabase-groonga}/lib/groonga/plugins/tokenizers/mecab.so $out/lib/postgresql/plugins/
56-
# else
57-
# echo "MeCab tokenizer plugin not found in Groonga installation"
58-
# exit 1
59-
# fi
60-
61-
# runHook postInstall
62-
# '';
63-
64-
# postInstall = ''
65-
# echo "Checking installed files:"
66-
# find $out -type f
67-
68-
# echo "Checking for MeCab-related files in the output:"
69-
# find $out -name "*mecab*"
70-
# '';
71-
72-
# postFixup = ''
73-
# patchelf --set-rpath "${
74-
# lib.makeLibraryPath [
75-
# mecab
76-
# mecab-naist-jdic
77-
# supabase-groonga
78-
# postgresql
79-
# stdenv.cc.cc.lib
80-
# msgpack-c
81-
# ]
82-
# }" $out/lib/pgroonga${postgresql.dlSuffix}
83-
# patchelf --set-rpath "${
84-
# lib.makeLibraryPath [
85-
# mecab
86-
# mecab-naist-jdic
87-
# supabase-groonga
88-
# postgresql
89-
# stdenv.cc.cc.lib
90-
# msgpack-c
91-
# ]
92-
# }" $out/lib/pgroonga_database${postgresql.dlSuffix}
93-
# '';
94-
95-
# meta = with lib; {
96-
# description = "A PostgreSQL extension to use Groonga as the index";
97-
# longDescription = ''
98-
# PGroonga is a PostgreSQL extension to use Groonga as the index.
99-
# PostgreSQL supports full text search against languages that use only alphabet and digit.
100-
# It means that PostgreSQL doesn't support full text search against Japanese, Chinese and so on.
101-
# You can use super fast full text search feature against all languages by installing PGroonga into your PostgreSQL.
102-
# '';
103-
# homepage = "https://pgroonga.github.io/";
104-
# changelog = "https://github.com/pgroonga/pgroonga/releases/tag/${version}";
105-
# license = licenses.postgresql;
106-
# platforms = postgresql.meta.platforms;
107-
# maintainers = with maintainers; [ samrose ];
108-
# };
109-
# }
110-
111-
# { lib, stdenv, fetchurl, pkg-config, postgresql, cmake, msgpack-c, mecab, callPackage }:
112-
# let
113-
# supabase-groonga = callPackage ../supabase-groonga.nix { };
114-
# mecab-naist-jdic = callPackage ./mecab-naist-jdic { };
115-
# in
116-
# stdenv.mkDerivation rec {
117-
# pname = "pgroonga";
118-
# version = "3.0.7";
119-
120-
# src = fetchurl {
121-
# url = "https://packages.groonga.org/source/${pname}/${pname}-${version}.tar.gz";
122-
# sha256 = "sha256-iF/zh4zDDpAw5fxW1WG8i2bfPt4VYsnYArwOoE/lwgM=";
123-
# };
124-
125-
# nativeBuildInputs = [ cmake pkg-config ];
126-
# buildInputs = [ postgresql msgpack-c supabase-groonga mecab mecab-naist-jdic ];
127-
128-
# makeFlags = [
129-
# "HAVE_MSGPACK=1"
130-
# "MSGPACK_PACKAGE_NAME=msgpack-c"
131-
# ];
132-
133-
# installPhase = ''
57+
# make $makeFlags install DESTDIR=$out
13458
# install -D pgroonga${postgresql.dlSuffix} -t $out/lib/
13559
# install -D pgroonga.control -t $out/share/postgresql/extension
13660
# install -D data/pgroonga-*.sql -t $out/share/postgresql/extension
137-
13861
# install -D pgroonga_database${postgresql.dlSuffix} -t $out/lib/
13962
# install -D pgroonga_database.control -t $out/share/postgresql/extension
14063
# install -D data/pgroonga_database-*.sql -t $out/share/postgresql/extension
141-
# '';
14264

143-
# meta = with lib; {
144-
# description = "A PostgreSQL extension to use Groonga as the index";
145-
# longDescription = ''
146-
# PGroonga is a PostgreSQL extension to use Groonga as the index.
147-
# PostgreSQL supports full text search against languages that use only alphabet and digit.
148-
# It means that PostgreSQL doesn't support full text search against Japanese, Chinese and so on.
149-
# You can use super fast full text search feature against all languages by installing PGroonga into your PostgreSQL.
150-
# '';
151-
# homepage = "https://pgroonga.github.io/";
152-
# changelog = "https://github.com/pgroonga/pgroonga/releases/tag/${version}";
153-
# license = licenses.postgresql;
154-
# platforms = postgresql.meta.platforms;
155-
# maintainers = with maintainers; [ samrose ];
156-
# };
157-
# }
65+
# for component in pgroonga_check pgroonga_wal_applier pgroonga_crash_safer pgroonga_standby_maintainer; do
66+
# if [ -f "$component${postgresql.dlSuffix}" ]; then
67+
# install -D "$component${postgresql.dlSuffix}" -t $out/lib/
68+
# fi
69+
# done
70+
71+
# # Ensure Groonga plugins are accessible
72+
# mkdir -p $out/lib/groonga/plugins
73+
# cp -r ${supabase-groonga}/lib/groonga/plugins/* $out/lib/groonga/plugins/
74+
75+
# # Create a wrapper script for pgroonga
76+
# mkdir -p $out/bin
77+
# makeWrapper ${postgresql}/bin/postgres $out/bin/pgroonga-postgres \
78+
# --set GRN_PLUGINS_PATH ${supabase-groonga}/lib/groonga/plugins \
79+
# --set LD_LIBRARY_PATH ${lib.makeLibraryPath buildInputs}:${supabase-groonga}/lib:$out/lib:$out/lib/groonga/plugins
80+
81+
# # Create SQL scripts to apply the necessary settings
82+
# cat << EOF > $out/share/postgresql/extension/pgroonga_set_paths.sql
83+
# DO \$\$
84+
# BEGIN
85+
# SET pgroonga.log_path TO current_setting('data_directory') || '/groonga.log';
86+
# SET pgroonga.libgroonga_path TO '${supabase-groonga}/lib/libgroonga${stdenv.hostPlatform.extensions.sharedLibrary}';
87+
# SET pgroonga.groonga_plugin_path TO '${supabase-groonga}/lib/groonga/plugins';
88+
# END \$\$;
89+
# EOF
90+
# chmod +x $out/share/postgresql/extension/pgroonga_set_paths.sql
15891

159-
# { lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, callPackage, cmake, mecab }:
160-
# let
161-
# supabase-groonga = callPackage ../supabase-groonga.nix { };
162-
# mecab-naist-jdic = callPackage ./mecab-naist-jdic { };
163-
# in
164-
# stdenv.mkDerivation rec {
165-
# pname = "pgroonga";
166-
# version = "3.0.7";
167-
# src = fetchurl {
168-
# url = "https://packages.groonga.org/source/${pname}/${pname}-${version}.tar.gz";
169-
# sha256 = "sha256-iF/zh4zDDpAw5fxW1WG8i2bfPt4VYsnYArwOoE/lwgM=";
170-
# };
171-
# patches = [ ./use-system-groonga.patch ];
172-
# nativeBuildInputs = [ pkg-config cmake ];
173-
# buildInputs = [ postgresql msgpack-c supabase-groonga mecab mecab-naist-jdic ];
174-
# cmakeFlags = [
175-
# "-DCMAKE_PREFIX_PATH=${supabase-groonga}"
176-
# "-DMECAB_CONFIG=${mecab}/bin/mecab-config"
177-
# "-DMECAB_DICT_INDEX=${mecab}/libexec/mecab/mecab-dict-index"
178-
# "-DMECAB_DIC_DIR=${mecab-naist-jdic}/lib/mecab/dic/naist-jdic"
179-
# "-DCMAKE_BUILD_TYPE=Release"
180-
# "-DBUILD_TESTING=OFF"
181-
# ];
182-
# preConfigure = ''
183-
# export CFLAGS="-I${supabase-groonga}/include -I${postgresql}/include/server -I${supabase-groonga}/include/groonga"
184-
# export CPPFLAGS="$CFLAGS"
185-
# export LDFLAGS="-L${supabase-groonga}/lib -L${postgresql}/lib"
186-
187-
# # Remove the problematic /EHsc flag
188-
# export CFLAGS="$(echo $CFLAGS | sed 's/-EHsc//g')"
189-
# export CXXFLAGS="$(echo $CXXFLAGS | sed 's/-EHsc//g')"
190-
191-
# # Ensure CMake doesn't add it back
192-
# substituteInPlace CMakeLists.txt --replace "-EHsc" ""
92+
# runHook postInstall
19393
# '';
19494

195-
# installPhase = ''
196-
# install -D pgroonga${postgresql.dlSuffix} -t $out/lib/
197-
# install -D pgroonga.control -t $out/share/postgresql/extension
198-
# install -D data/pgroonga-*.sql -t $out/share/postgresql/extension
199-
# install -D pgroonga_database${postgresql.dlSuffix} -t $out/lib/
200-
# install -D pgroonga_database.control -t $out/share/postgresql/extension
201-
# install -D data/pgroonga_database-*.sql -t $out/share/postgresql/extension
95+
# postFixup = ''
96+
# for f in $out/lib/*.so; do
97+
# patchelf --set-rpath "${lib.makeLibraryPath buildInputs}:${supabase-groonga}/lib:$out/lib:$out/lib/groonga/plugins" $f
98+
# done
20299
# '';
100+
203101
# meta = with lib; {
204102
# description = "A PostgreSQL extension to use Groonga as the index";
205103
# longDescription = ''
@@ -216,68 +114,67 @@
216114
# };
217115
# }
218116

219-
{ lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, callPackage
220-
, makeWrapper, mecab }:
221-
117+
{ lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, callPackage, mecab, makeWrapper }:
222118
let
223119
supabase-groonga = callPackage ../supabase-groonga.nix { };
224-
mecab-naist-jdic = callPackage ./mecab-naist-jdic { };
225-
in stdenv.mkDerivation rec {
120+
in
121+
stdenv.mkDerivation rec {
226122
pname = "pgroonga";
227123
version = "3.0.7";
228124
src = fetchurl {
229-
url =
230-
"https://packages.groonga.org/source/${pname}/${pname}-${version}.tar.gz";
125+
url = "https://packages.groonga.org/source/${pname}/${pname}-${version}.tar.gz";
231126
sha256 = "sha256-iF/zh4zDDpAw5fxW1WG8i2bfPt4VYsnYArwOoE/lwgM=";
232127
};
233128
nativeBuildInputs = [ pkg-config makeWrapper ];
234-
buildInputs = [ postgresql msgpack-c supabase-groonga mecab mecab-naist-jdic ];
129+
buildInputs = [ postgresql msgpack-c supabase-groonga mecab ];
130+
131+
configureFlags = [
132+
"--with-mecab=${mecab}"
133+
"--enable-mecab"
134+
"--with-groonga=${supabase-groonga}"
135+
"--with-groonga-plugin-dir=${supabase-groonga}/lib/groonga/plugins"
136+
];
137+
235138
makeFlags = [
236-
"USE_PGXS=1"
237139
"HAVE_MSGPACK=1"
238140
"MSGPACK_PACKAGE_NAME=msgpack-c"
239141
"HAVE_MECAB=1"
240-
"POSTGRES_INCLUDEDIR=${postgresql}/include"
241-
"POSTGRES_LIBDIR=${postgresql.lib}/lib"
242-
"PG_CONFIG=${postgresql}/bin/pg_config"
243-
"MECAB_CONFIG=${mecab}/bin/mecab-config"
244142
];
245-
246-
preConfigure = ''
247-
export MECAB_DICDIR=${mecab-naist-jdic}/lib/mecab/dic/naist-jdic
248-
export GROONGA_INCLUDE_PATH=${supabase-groonga}/include
249-
export GROONGA_LIB_PATH=${supabase-groonga}/lib
250-
export MECAB_INCLUDE_PATH=${mecab}/include
251-
export MECAB_LIB_PATH=${mecab}/lib
252-
'';
253143

254-
buildPhase = ''
255-
runHook preBuild
256-
make $makeFlags
257-
runHook postBuild
144+
preConfigure = ''
145+
export GROONGA_LIBS="-L${supabase-groonga}/lib -lgroonga"
146+
export GROONGA_CFLAGS="-I${supabase-groonga}/include"
147+
export MECAB_CONFIG="${mecab}/bin/mecab-config"
258148
'';
259149

260150
installPhase = ''
261-
runHook preInstall
262-
make $makeFlags install DESTDIR=$out
151+
mkdir -p $out/lib $out/share/postgresql/extension $out/bin
263152
install -D pgroonga${postgresql.dlSuffix} -t $out/lib/
264153
install -D pgroonga.control -t $out/share/postgresql/extension
265154
install -D data/pgroonga-*.sql -t $out/share/postgresql/extension
266155
install -D pgroonga_database${postgresql.dlSuffix} -t $out/lib/
267156
install -D pgroonga_database.control -t $out/share/postgresql/extension
268157
install -D data/pgroonga_database-*.sql -t $out/share/postgresql/extension
269-
270-
for component in pgroonga_check pgroonga_wal_applier pgroonga_crash_safer pgroonga_standby_maintainer; do
271-
if [ -f "$component${postgresql.dlSuffix}" ]; then
272-
install -D "$component${postgresql.dlSuffix}" -t $out/lib/
273-
fi
274-
done
275-
runHook postInstall
158+
159+
cat << EOF > $out/share/postgresql/extension/pgroonga_set_paths.sql
160+
DO \$\$
161+
BEGIN
162+
SET pgroonga.log_path TO current_setting('data_directory') || '/groonga.log';
163+
PERFORM pgroonga_command('plugin_register ${supabase-groonga}/lib/groonga/plugins/tokenizers/mecab.so');
164+
END \$\$;
165+
EOF
166+
chmod +x $out/share/postgresql/extension/pgroonga_set_paths.sql
167+
168+
makeWrapper ${postgresql}/bin/postgres $out/bin/pgroonga-postgres \
169+
--set LD_LIBRARY_PATH "${lib.makeLibraryPath buildInputs}:${supabase-groonga}/lib:$out/lib"
170+
171+
echo "Debug: Groonga plugins directory contents:"
172+
ls -l ${supabase-groonga}/lib/groonga/plugins/tokenizers/
276173
'';
277174

278175
postFixup = ''
279176
for f in $out/lib/*.so; do
280-
patchelf --set-rpath "${lib.makeLibraryPath buildInputs}:$out/lib" $f
177+
patchelf --set-rpath "${lib.makeLibraryPath buildInputs}:${supabase-groonga}/lib:$out/lib:${supabase-groonga}/lib/groonga/plugins/tokenizers" $f
281178
done
282179
'';
283180

0 commit comments

Comments
 (0)