Skip to content

Commit 1aa6904

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 9313875 commit 1aa6904

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-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
@@ -318,6 +318,7 @@
318318
};
319319
};
320320
mecab_naist_jdic = mecab-naist-jdic;
321+
supabase_groonga = supabase-groonga;
321322
# Start a version of the server.
322323
start-server =
323324
let
@@ -381,7 +382,8 @@
381382
--subst-var-by 'PG_IDENT' "$out/etc/postgresql/pg_ident.conf" \
382383
--subst-var-by 'LOCALES' '${localeArchive}' \
383384
--subst-var-by 'EXTENSION_CUSTOM_SCRIPTS_DIR' "$out/extension-custom-scripts" \
384-
--subst-var-by 'MECAB_LIB' '${basePackages.psql_15.exts.pgroonga}/lib/groonga/plugins/tokenizers/tokenizer_mecab.so'
385+
--subst-var-by 'MECAB_LIB' '${basePackages.psql_15.exts.pgroonga}/lib/groonga/plugins/tokenizers/tokenizer_mecab.so' \
386+
--subst-var-by 'GROONGA_DIR' '${supabase-groonga}'
385387
386388
chmod +x $out/bin/start-postgres-server
387389
'';
@@ -452,10 +454,11 @@
452454
let
453455
sqlTests = ./nix/tests/smoke;
454456
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
457+
supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
455458
in
456459
pkgs.runCommand "postgres-${pgpkg.version}-check-harness"
457460
{
458-
nativeBuildInputs = with pkgs; [ coreutils bash pgpkg pg_prove pg_regress procps ];
461+
nativeBuildInputs = with pkgs; [ coreutils bash pgpkg pg_prove pg_regress procps supabase-groonga ];
459462
} ''
460463
TMPDIR=$(mktemp -d)
461464
if [ $? -ne 0 ]; then
@@ -473,7 +476,7 @@
473476
mkdir -p $TMPDIR/logfile
474477
# Generate a random key and store it in an environment variable
475478
export PGSODIUM_KEY=$(head -c 32 /dev/urandom | od -A n -t x1 | tr -d ' \n')
476-
479+
export GRN_PLUGINS_DIR=${supabase-groonga}/lib/groonga/plugins
477480
# Create a simple script to echo the key
478481
echo '#!/bin/sh' > $TMPDIR/getkey.sh
479482
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ READREPL_CONFIG_FILE=@READREPL_CONF_FILE@
2929
PG_HBA_FILE=@PG_HBA@
3030
PG_IDENT_FILE=@PG_IDENT@
3131
EXTENSION_CUSTOM_SCRIPTS=@EXTENSION_CUSTOM_SCRIPTS_DIR@
32+
GROONGA=@GROONGA_DIR@
3233
DATDIR=$(mktemp -d)
3334
LOCALE_ARCHIVE=@LOCALES@
3435
export LOCALE_ARCHIVE
@@ -60,4 +61,5 @@ pgsodium.getkey_script = '$PGSODIUM_GETKEY_SCRIPT'" \
6061
-e "\$a\\
6162
session_preload_libraries = 'supautils'" \
6263
"$PSQL_CONF_FILE" > "$DATDIR/postgresql.conf"
63-
postgres --config-file="$DATDIR/postgresql.conf" -p "$PORTNO" -D "$DATDIR" -k /tmp
64+
export GRN_PLUGINS_DIR=$GROONGA/lib/groonga/plugins
65+
postgres --config-file="$DATDIR/postgresql.conf" -p "$PORTNO" -D "$DATDIR" -k /tmp

0 commit comments

Comments
 (0)