Skip to content

Commit 8f8b9b0

Browse files
committed
feat: wip pkg for mecab deps needed for groonga
1 parent 0d360c5 commit 8f8b9b0

File tree

5 files changed

+347
-70
lines changed

5 files changed

+347
-70
lines changed

flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
sfcgal = pkgs.callPackage ./nix/ext/sfcgal/sfcgal.nix { };
6464
pg_regress = pkgs.callPackage ./nix/ext/pg_regress.nix { };
6565
supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
66+
mecab-naist-jdic = pkgs.callPackage ./nix/ext/mecab-naist-jdic/default.nix { };
6667
# Our list of PostgreSQL extensions which come from upstream Nixpkgs.
6768
# These are maintained upstream and can easily be used here just by
6869
# listing their name. Anytime the version of nixpkgs is upgraded, these
@@ -273,6 +274,7 @@
273274
sfcgal = sfcgal;
274275
pg_regress = pg_regress;
275276
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
277+
mecab_naist_jdic = mecab-naist-jdic;
276278
# Start a version of the server.
277279
start-server =
278280
let

nix/ext/mecab-naist-jdic/default.nix

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{ lib, stdenv, fetchurl, mecab }:
2+
3+
stdenv.mkDerivation rec {
4+
pname = "mecab-naist-jdic";
5+
version = "0.6.3b-20111013";
6+
7+
src = fetchurl {
8+
url = "https://github.com/supabase/mecab-naist-jdic/raw/main/mecab-naist-jdic-${version}.tar.gz";
9+
sha256 = "sha256-yzdwDcmne5U/K/OxW0nP7NZ4SFMKLPirywm1lMpWKMw=";
10+
};
11+
12+
buildInputs = [ mecab ];
13+
14+
configureFlags = [
15+
"--with-charset=utf8"
16+
];
17+
18+
buildPhase = ''
19+
runHook preBuild
20+
make
21+
${mecab}/libexec/mecab/mecab-dict-index -d . -o . -f UTF-8 -t utf-8
22+
runHook postBuild
23+
'';
24+
25+
installPhase = ''
26+
runHook preInstall
27+
28+
mkdir -p $out/lib/mecab/dic/naist-jdic
29+
cp *.dic *.bin *.def $out/lib/mecab/dic/naist-jdic/
30+
31+
runHook postInstall
32+
'';
33+
34+
meta = with lib; {
35+
description = "Naist Japanese Dictionary for MeCab";
36+
homepage = "https://taku910.github.io/mecab/";
37+
license = licenses.gpl2;
38+
platforms = platforms.unix;
39+
maintainers = with maintainers; [ samrose ];
40+
};
41+
}

nix/ext/pgroonga.nix

Lines changed: 261 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,284 @@
1-
{ lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, mecab, callPackage}:
2-
let
3-
supabase-groonga = callPackage ../supabase-groonga.nix { };
4-
in
5-
stdenv.mkDerivation rec {
6-
pname = "pgroonga";
7-
version = "3.0.7";
1+
# { lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, mecab, callPackage
2+
# , patchelf }:
3+
# let
4+
# supabase-groonga = callPackage ../supabase-groonga.nix { };
5+
# mecab-naist-jdic = callPackage ./mecab-naist-jdic { };
6+
# in stdenv.mkDerivation rec {
7+
# pname = "pgroonga";
8+
# version = "3.0.7";
9+
# src = fetchurl {
10+
# url =
11+
# "https://packages.groonga.org/source/${pname}/${pname}-${version}.tar.gz";
12+
# sha256 = "sha256-iF/zh4zDDpAw5fxW1WG8i2bfPt4VYsnYArwOoE/lwgM=";
13+
# };
14+
# nativeBuildInputs = [ pkg-config patchelf ];
15+
# buildInputs =
16+
# [ postgresql msgpack-c supabase-groonga mecab mecab-naist-jdic ];
817

9-
src = fetchurl {
10-
url = "https://packages.groonga.org/source/${pname}/${pname}-${version}.tar.gz";
11-
sha256 = "sha256-iF/zh4zDDpAw5fxW1WG8i2bfPt4VYsnYArwOoE/lwgM=";
12-
};
18+
# configureFlags = [
19+
# "--with-mecab=${mecab}"
20+
# "--enable-mecab"
21+
# "--enable-groonga-tokenizer-mecab"
22+
# "--with-mecab-dict=${mecab-naist-jdic}/lib/mecab/dic/naist-jdic"
23+
# "--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"
26+
# "--with-groonga-plugin-dir=${supabase-groonga}/lib/groonga/plugins"
27+
# "--with-pgconfigdir=${postgresql}/bin"
28+
# "--with-mecab-config=${mecab}/bin/mecab-config"
29+
# ];
1330

14-
nativeBuildInputs = [ pkg-config ];
31+
# makeFlags =
32+
# [ "HAVE_MSGPACK=1" "MSGPACK_PACKAGE_NAME=msgpack-c" "HAVE_MECAB=1" ];
1533

16-
buildInputs = [ postgresql msgpack-c supabase-groonga mecab ];
34+
# buildPhase = ''
35+
# runHook preBuild
36+
# make
37+
# echo "Checking for MeCab-related files:"
38+
# find . -name "*mecab*"
39+
# runHook postBuild
40+
# '';
1741

18-
runtimeDependencies = [ mecab ];
42+
# installPhase = ''
43+
# runHook preInstall
1944

20-
preConfigure = ''
21-
export MECAB_CONFIG=${mecab}/bin/mecab-config
22-
export MECAB_DICDIR=${mecab}/lib/mecab/dic/ipadic
23-
export GRN_PLUGINS_DIR=$out/lib/groonga/plugins
24-
export GROONGA_TOKENIZER_MECAB_DIR=${supabase-groonga}/lib/groonga/plugins/tokenizers
25-
export GROONGA_TOKENIZER_MECAB=$out/lib/groonga/plugins/tokenizer_mecab.so
26-
'';
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/
2751

28-
configureFlags = [
29-
"--with-mecab=${mecab}"
30-
"--enable-tokenizer-mecab"
31-
"--with-groonga=${supabase-groonga}"
32-
"--with-groonga-token-mecab-dir=${supabase-groonga}/lib/groonga/plugins/tokenizers"
33-
"--with-groonga-tokenizer-mecab=${supabase-groonga}/lib/groonga/plugins/tokenizers/mecab.so"
34-
"--with-groonga-plugin-dir=${supabase-groonga}/lib/groonga/plugins"
35-
];
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 = ''
134+
# install -D pgroonga${postgresql.dlSuffix} -t $out/lib/
135+
# install -D pgroonga.control -t $out/share/postgresql/extension
136+
# install -D data/pgroonga-*.sql -t $out/share/postgresql/extension
137+
138+
# install -D pgroonga_database${postgresql.dlSuffix} -t $out/lib/
139+
# install -D pgroonga_database.control -t $out/share/postgresql/extension
140+
# install -D data/pgroonga_database-*.sql -t $out/share/postgresql/extension
141+
# '';
36142

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+
# }
158+
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" ""
193+
# '';
194+
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
202+
# '';
203+
# meta = with lib; {
204+
# description = "A PostgreSQL extension to use Groonga as the index";
205+
# longDescription = ''
206+
# PGroonga is a PostgreSQL extension to use Groonga as the index.
207+
# PostgreSQL supports full text search against languages that use only alphabet and digit.
208+
# It means that PostgreSQL doesn't support full text search against Japanese, Chinese and so on.
209+
# You can use super fast full text search feature against all languages by installing PGroonga into your PostgreSQL.
210+
# '';
211+
# homepage = "https://pgroonga.github.io/";
212+
# changelog = "https://github.com/pgroonga/pgroonga/releases/tag/${version}";
213+
# license = licenses.postgresql;
214+
# platforms = postgresql.meta.platforms;
215+
# maintainers = with maintainers; [ samrose ];
216+
# };
217+
# }
218+
219+
{ lib, stdenv, fetchurl, pkg-config, postgresql, msgpack-c, callPackage
220+
, makeWrapper, mecab }:
221+
222+
let
223+
supabase-groonga = callPackage ../supabase-groonga.nix { };
224+
mecab-naist-jdic = callPackage ./mecab-naist-jdic { };
225+
in stdenv.mkDerivation rec {
226+
pname = "pgroonga";
227+
version = "3.0.7";
228+
src = fetchurl {
229+
url =
230+
"https://packages.groonga.org/source/${pname}/${pname}-${version}.tar.gz";
231+
sha256 = "sha256-iF/zh4zDDpAw5fxW1WG8i2bfPt4VYsnYArwOoE/lwgM=";
232+
};
233+
nativeBuildInputs = [ pkg-config makeWrapper ];
234+
buildInputs = [ postgresql msgpack-c supabase-groonga mecab mecab-naist-jdic ];
37235
makeFlags = [
236+
"USE_PGXS=1"
38237
"HAVE_MSGPACK=1"
39238
"MSGPACK_PACKAGE_NAME=msgpack-c"
40239
"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"
41244
];
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+
'';
253+
254+
buildPhase = ''
255+
runHook preBuild
256+
make $makeFlags
257+
runHook postBuild
258+
'';
42259

43260
installPhase = ''
261+
runHook preInstall
262+
make $makeFlags install DESTDIR=$out
44263
install -D pgroonga${postgresql.dlSuffix} -t $out/lib/
45264
install -D pgroonga.control -t $out/share/postgresql/extension
46265
install -D data/pgroonga-*.sql -t $out/share/postgresql/extension
47-
48266
install -D pgroonga_database${postgresql.dlSuffix} -t $out/lib/
49267
install -D pgroonga_database.control -t $out/share/postgresql/extension
50268
install -D data/pgroonga_database-*.sql -t $out/share/postgresql/extension
51269
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
276+
'';
277+
278+
postFixup = ''
279+
for f in $out/lib/*.so; do
280+
patchelf --set-rpath "${lib.makeLibraryPath buildInputs}:$out/lib" $f
281+
done
52282
'';
53283

54284
meta = with lib; {
@@ -65,4 +295,4 @@ stdenv.mkDerivation rec {
65295
platforms = postgresql.meta.platforms;
66296
maintainers = with maintainers; [ samrose ];
67297
};
68-
}
298+
}

0 commit comments

Comments
 (0)