diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 4d5cb720bfdc..4a3f4a331ca8 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -849,6 +849,7 @@ in { trezord = handleTest ./trezord.nix {}; trickster = handleTest ./trickster.nix {}; trilium-server = handleTestOn ["x86_64-linux"] ./trilium-server.nix {}; + tsja = handleTest ./tsja.nix {}; tsm-client-gui = handleTest ./tsm-client-gui.nix {}; txredisapi = handleTest ./txredisapi.nix {}; tuptime = handleTest ./tuptime.nix {}; diff --git a/nixos/tests/tsja.nix b/nixos/tests/tsja.nix new file mode 100644 index 000000000000..176783088d8d --- /dev/null +++ b/nixos/tests/tsja.nix @@ -0,0 +1,32 @@ +import ./make-test-python.nix ({ pkgs, lib, ...} : { + name = "tsja"; + meta = { + maintainers = with lib.maintainers; [ chayleaf ]; + }; + + nodes = { + master = + { config, ... }: + + { + services.postgresql = { + enable = true; + extraPlugins = with config.services.postgresql.package.pkgs; [ + tsja + ]; + }; + }; + }; + + testScript = '' + start_all() + master.wait_for_unit("postgresql") + master.succeed("sudo -u postgres psql -f /run/current-system/sw/share/postgresql/extension/libtsja_dbinit.sql") + # make sure "日本語" is parsed as a separate lexeme + master.succeed(""" + sudo -u postgres \\ + psql -c "SELECT * FROM ts_debug('japanese', 'PostgreSQLで日本語のテキスト検索ができます。')" \\ + | grep "{日本語}" + """) + ''; +}) diff --git a/pkgs/servers/sql/postgresql/ext/tsja.nix b/pkgs/servers/sql/postgresql/ext/tsja.nix new file mode 100644 index 000000000000..f62eae5b6a3e --- /dev/null +++ b/pkgs/servers/sql/postgresql/ext/tsja.nix @@ -0,0 +1,45 @@ +{ lib +, fetchzip +, nixosTests +, stdenv + +, mecab +, postgresql +}: + +stdenv.mkDerivation rec { + pname = "tsja"; + version = "0.5.0"; + + src = fetchzip { + url = "https://www.amris.jp/tsja/tsja-${version}.tar.xz"; + hash = "sha256-h59UhUG/7biN8NaDiGK6kXDqfhR9uMzt8CpwbJ+PpEM="; + }; + + postPatch = '' + substituteInPlace Makefile \ + --replace /usr/local/pgsql ${postgresql} \ + --replace -L/usr/local/lib "" \ + --replace -I/usr/local/include "" + substituteInPlace tsja.c --replace /usr/local/lib/mecab ${mecab}/lib/mecab + ''; + + buildInputs = [ mecab postgresql ]; + + installPhase = '' + mkdir -p $out/lib $out/share/postgresql/extension + mv libtsja.so $out/lib + mv dbinit_libtsja.txt $out/share/postgresql/extension/libtsja_dbinit.sql + ''; + + passthru.tests.tsja = nixosTests.tsja; + + meta = with lib; { + description = "PostgreSQL extension implementing Japanese text search"; + homepage = "https://www.amris.jp/tsja/index.html"; + maintainers = with maintainers; [ chayleaf ]; + # GNU-specific linker options are used + platforms = platforms.gnu; + license = licenses.gpl2Only; + }; +} diff --git a/pkgs/servers/sql/postgresql/packages.nix b/pkgs/servers/sql/postgresql/packages.nix index 69309d0c4824..d9d9ce8b09d9 100644 --- a/pkgs/servers/sql/postgresql/packages.nix +++ b/pkgs/servers/sql/postgresql/packages.nix @@ -87,5 +87,7 @@ self: super: { rum = super.callPackage ./ext/rum.nix { }; + tsja = super.callPackage ./ext/tsja.nix { }; + wal2json = super.callPackage ./ext/wal2json.nix { }; } diff --git a/pkgs/tools/text/mecab/default.nix b/pkgs/tools/text/mecab/default.nix index 3cca6776d3a9..8d11343515d0 100644 --- a/pkgs/tools/text/mecab/default.nix +++ b/pkgs/tools/text/mecab/default.nix @@ -7,7 +7,8 @@ stdenv.mkDerivation (finalAttrs: ((mecab-base finalAttrs) // { pname = "mecab"; postInstall = '' - sed -i 's|^dicdir = .*$|dicdir = ${mecab-ipadic}|' "$out/etc/mecabrc" + mkdir -p $out/lib/mecab/dic + ln -s ${mecab-ipadic} $out/lib/mecab/dic/ipadic ''; meta = with lib; {