Skip to content

Commit 4844021

Browse files
committed
fix: additional fixes to the build/install process in ami
groonga plugins dir must be set as env var for TokenMecab to work
1 parent 7d3dc18 commit 4844021

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

ansible/tasks/stage2-setup-postgres.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
- name: Install pg_prove from nix binary cache
1414
become: yes
1515
shell: |
16-
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/sam/2-stage-ami-nix#pg_prove"
16+
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#pg_prove"
17+
when: stage2_nix
18+
19+
- name: Install supabase-groonga from nix binary cache
20+
become: yes
21+
shell: |
22+
sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#supabase-groonga"
1723
when: stage2_nix
1824

1925
- name: Set ownership and permissions for /etc/ssl/private
@@ -220,3 +226,9 @@
220226
# script is expected to be placed by finalization tasks for different target platforms
221227
line: pgsodium.getkey_script= '{{ pg_bindir }}/pgsodium_getkey.sh'
222228
when: stage2_nix
229+
230+
- name: Append GRN_PLUGINS_DIR to /etc/environment.d/postgresql.env
231+
ansible.builtin.lineinfile:
232+
path: /etc/environment.d/postgresql.env
233+
line: 'GRN_PLUGINS_DIR=/var/lib/postgresql/.nix-profile/lib/groonga/plugins'
234+
become: yes

flake.nix

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@
275275
pg_regress = pg_regress;
276276
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
277277
mecab_naist_jdic = mecab-naist-jdic;
278+
supabase_groonga = supabase-groonga;
278279
# Start a version of the server.
279280
start-server =
280281
let
@@ -288,7 +289,8 @@
288289
--subst-var-by 'PGSQL_SUPERUSER' '${pgsqlSuperuser}' \
289290
--subst-var-by 'PSQL15_BINDIR' '${basePackages.psql_15.bin}' \
290291
--subst-var-by 'PSQL_CONF_FILE' '${configFile}' \
291-
--subst-var-by 'PGSODIUM_GETKEY' '${getkeyScript}'
292+
--subst-var-by 'PGSODIUM_GETKEY' '${getkeyScript}' \
293+
--subst-var-by 'GROONGA_DIR' '${supabase-groonga}' \
292294
293295
chmod +x $out/bin/start-postgres-server
294296
'';
@@ -369,10 +371,11 @@
369371
let
370372
sqlTests = ./nix/tests/smoke;
371373
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
374+
supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
372375
in
373376
pkgs.runCommand "postgres-${pgpkg.version}-check-harness"
374377
{
375-
nativeBuildInputs = with pkgs; [ coreutils bash pgpkg pg_prove pg_regress procps ];
378+
nativeBuildInputs = with pkgs; [ coreutils bash pgpkg pg_prove pg_regress procps supabase-groonga ];
376379
} ''
377380
TMPDIR=$(mktemp -d)
378381
if [ $? -ne 0 ]; then
@@ -390,7 +393,7 @@
390393
mkdir -p $TMPDIR/logfile
391394
# Generate a random key and store it in an environment variable
392395
export PGSODIUM_KEY=$(head -c 32 /dev/urandom | od -A n -t x1 | tr -d ' \n')
393-
396+
export GRN_PLUGINS_DIR=${supabase-groonga}/lib/groonga/plugins
394397
# Create a simple script to echo the key
395398
echo '#!/bin/sh' > $TMPDIR/getkey.sh
396399
echo 'echo $PGSODIUM_KEY' >> $TMPDIR/getkey.sh

nix/ext/pgroonga.nix

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ stdenv.mkDerivation rec {
1111
};
1212
nativeBuildInputs = [ pkg-config makeWrapper ];
1313
buildInputs = [ postgresql msgpack-c supabase-groonga mecab ];
14-
14+
propagatedBuildInputs = [ supabase-groonga ];
1515
configureFlags = [
1616
"--with-mecab=${mecab}"
1717
"--enable-mecab"
@@ -40,19 +40,6 @@ stdenv.mkDerivation rec {
4040
install -D pgroonga_database.control -t $out/share/postgresql/extension
4141
install -D data/pgroonga_database-*.sql -t $out/share/postgresql/extension
4242
43-
# Modify the main PGroonga SQL file to include MeCab plugin registration
44-
for sql_file in $out/share/postgresql/extension/pgroonga-*.sql; do
45-
echo "SELECT pgroonga_command('plugin_register ${supabase-groonga}/lib/groonga/plugins/tokenizers/mecab.so');" >> $sql_file
46-
done
47-
48-
cat << EOF > $out/share/postgresql/extension/pgroonga_set_paths.sql
49-
DO \$\$
50-
BEGIN
51-
SET pgroonga.log_path TO current_setting('data_directory') || '/groonga.log';
52-
END \$\$;
53-
EOF
54-
chmod +x $out/share/postgresql/extension/pgroonga_set_paths.sql
55-
5643
makeWrapper ${postgresql}/bin/postgres $out/bin/pgroonga-postgres \
5744
--set LD_LIBRARY_PATH "${lib.makeLibraryPath buildInputs}:${supabase-groonga}/lib:$out/lib"
5845

nix/supabase-groonga.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ in stdenv.mkDerivation (finalAttrs: {
3737
echo "CMake cache contents related to MeCab:"
3838
grep -i mecab CMakeCache.txt
3939
'';
40+
41+
# installPhase = ''
42+
# mkdir -p $out/bin $out/lib/groonga/plugins
43+
# cp -r lib/groonga/plugins/* $out/lib/groonga/plugins
44+
# cp -r bin/* $out/bin
45+
# echo "Installed Groonga plugins:"
46+
# ls -l $out/lib/groonga/plugins
47+
# '';
48+
4049
postInstall = ''
4150
echo "Searching for MeCab-related files:"
4251
find $out -name "*mecab*"

nix/tools/run-server.sh.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ PSQL_CONF_FILE=@PSQL_CONF_FILE@
2828
PGSODIUM_GETKEY_SCRIPT=@PGSODIUM_GETKEY@
2929
PORTNO="${2:-@PGSQL_DEFAULT_PORT@}"
3030
PLJAVA_LIBJVM_LOCATION=@LIBJVM_LOCATION@
31+
GROONGA=@GROONGA_DIR@
3132
DATDIR=$(mktemp -d)
3233
mkdir -p "$DATDIR"
3334

@@ -43,5 +44,5 @@ echo "pljava libjvm location: $PLJAVA_LIBJVM_LOCATION"
4344
sed -e "s#@PGSODIUM_GETKEY_SCRIPT@#$PGSODIUM_GETKEY_SCRIPT#g" \
4445
-e "s#@PLJAVA_LIBJVM_LOCATION@#$PLJAVA_LIBJVM_LOCATION#g" \
4546
$PSQL_CONF_FILE > "$DATDIR/postgresql.conf"
46-
47+
export GRN_PLUGINS_DIR=$GROONGA/lib/groonga/plugins
4748
exec postgres -p "$PORTNO" -D "$DATDIR" -k /tmp

0 commit comments

Comments
 (0)