From 7d79717584db8cfa995c3d6a456ff857dde27d3c Mon Sep 17 00:00:00 2001 From: pacien Date: Wed, 23 Aug 2023 23:55:38 +0200 Subject: [PATCH] translatelocally: init at unstable-2023-08-25 Upstream doesn't have proper version tags, so I'm using a commit hash and date here. The CMake files are patched so they don't try using the stripped .git repo data to generate a version string. Github: closes #250867 --- .../misc/translatelocally/default.nix | 62 +++++++++++++++++ .../version_without_git.patch | 66 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 + 3 files changed, 130 insertions(+) create mode 100644 pkgs/applications/misc/translatelocally/default.nix create mode 100644 pkgs/applications/misc/translatelocally/version_without_git.patch diff --git a/pkgs/applications/misc/translatelocally/default.nix b/pkgs/applications/misc/translatelocally/default.nix new file mode 100644 index 000000000000..81aa9ec91bcf --- /dev/null +++ b/pkgs/applications/misc/translatelocally/default.nix @@ -0,0 +1,62 @@ +{ lib, stdenv, fetchFromGitHub +, cmake, qt6, libarchive, pcre2, protobuf, gperftools, blas +}: + +let + rev = "f8a2dba0a63989c6b3a7be36f736ed478cad1dd2"; + +in stdenv.mkDerivation (finalAttrs: { + pname = "translatelocally"; + version = "unstable-2023-08-25"; + + src = fetchFromGitHub { + owner = "XapaJIaMnu"; + repo = "translateLocally"; + inherit rev; + hash = "sha256-uUdDi0CwCR/FQjw5D2s088d/Tp7NQOI0ia30oOhlGoc="; + fetchSubmodules = true; + }; + + patches = [ + ./version_without_git.patch + ]; + + postPatch = '' + echo '#define GIT_REVISION "${rev} ${finalAttrs.version}"' > \ + 3rd_party/bergamot-translator/3rd_party/marian-dev/src/common/git_revision.h + ''; + + nativeBuildInputs = [ + cmake + protobuf + qt6.wrapQtAppsHook + ]; + + buildInputs = [ + qt6.qttools + qt6.qtbase + qt6.qtsvg + libarchive + pcre2 + protobuf + gperftools # provides tcmalloc + blas + ]; + + cmakeFlags = [ + "-DBLAS_LIBRARIES=-lblas" + "-DCBLAS_LIBRARIES=-lcblas" + ]; + + meta = with lib; { + mainProgram = "translateLocally"; + homepage = "https://translatelocally.com/"; + description = "Fast and secure translation on your local machine, powered by marian and Bergamot."; + license = licenses.mit; + maintainers = with maintainers; [ pacien ]; + platforms = platforms.linux; + + # https://github.com/XapaJIaMnu/translateLocally/issues/150 + broken = stdenv.isAarch64; + }; +}) diff --git a/pkgs/applications/misc/translatelocally/version_without_git.patch b/pkgs/applications/misc/translatelocally/version_without_git.patch new file mode 100644 index 000000000000..9d7e618e3e67 --- /dev/null +++ b/pkgs/applications/misc/translatelocally/version_without_git.patch @@ -0,0 +1,66 @@ +Submodule 3rd_party/bergamot-translator contains modified content +Submodule 3rd_party/marian-dev contains modified content +diff --git a/3rd_party/bergamot-translator/3rd_party/marian-dev/cmake/GetVersionFromFile.cmake b/3rd_party/bergamot-translator/3rd_party/marian-dev/cmake/GetVersionFromFile.cmake +index 31352565..d90a366d 100644 +--- a/3rd_party/bergamot-translator/3rd_party/marian-dev/cmake/GetVersionFromFile.cmake ++++ b/3rd_party/bergamot-translator/3rd_party/marian-dev/cmake/GetVersionFromFile.cmake +@@ -22,10 +22,8 @@ else() + endif() + + # Get current commit SHA from git +-execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD +- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +- OUTPUT_VARIABLE PROJECT_VERSION_GIT_SHA +- OUTPUT_STRIP_TRAILING_WHITESPACE) ++# (dummy value for nix package without the .git) ++set(PROJECT_VERSION_GIT_SHA 000000000000) + + # Get partial versions into a list + string(REGEX MATCHALL "-.*$|[0-9]+" PROJECT_PARTIAL_VERSION_LIST +diff --git a/3rd_party/bergamot-translator/3rd_party/marian-dev/src/CMakeLists.txt b/3rd_party/bergamot-translator/3rd_party/marian-dev/src/CMakeLists.txt +index 76aa0e2b..ca982bd3 100644 +--- a/3rd_party/bergamot-translator/3rd_party/marian-dev/src/CMakeLists.txt ++++ b/3rd_party/bergamot-translator/3rd_party/marian-dev/src/CMakeLists.txt +@@ -149,23 +149,8 @@ target_compile_options(marian PRIVATE ${ALL_WARNINGS}) + # + # We set MARIAN_GIT_DIR to the appropriate path, depending on whether + # ${CMAKE_CURRENT_SOURCE_DIR}/../.git is a directory or file. +-set(MARIAN_GIT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../.git) +-if(NOT IS_DIRECTORY ${MARIAN_GIT_DIR}) # i.e., it's a submodule +- file(READ ${MARIAN_GIT_DIR} MARIAN_GIT_DIR) +- string(REGEX REPLACE "gitdir: (.*)\n" "\\1" MARIAN_GIT_DIR ${MARIAN_GIT_DIR}) +- if(NOT IS_ABSOLUTE ${MARIAN_GIT_DIR}) +- get_filename_component(MARIAN_GIT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${MARIAN_GIT_DIR}" ABSOLUTE) +- endif() +-endif(NOT IS_DIRECTORY ${MARIAN_GIT_DIR}) +- +-add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/common/git_revision.h +- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +- COMMAND git log -1 --pretty=format:\#define\ GIT_REVISION\ \"\%h\ \%ai\" > ${CMAKE_CURRENT_SOURCE_DIR}/common/git_revision.h +- DEPENDS ${MARIAN_GIT_DIR}/logs/HEAD +- VERBATIM +-) +-add_custom_target(marian_version DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/common/git_revision.h) +-add_dependencies(marian marian_version) # marian must depend on it so that it gets created first ++# (generated by nix package instead) ++ + # make sure all local dependencies are installed first before this is built + add_dependencies(marian 3rd_party_installs) + +diff --git a/cmake/GetVersionFromFile.cmake b/cmake/GetVersionFromFile.cmake +index 83b7975..71cd861 100644 +--- a/cmake/GetVersionFromFile.cmake ++++ b/cmake/GetVersionFromFile.cmake +@@ -23,10 +23,8 @@ else() + endif() + + # Get current commit SHA from git +-execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD +- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +- OUTPUT_VARIABLE PROJECT_VERSION_GIT_SHA +- OUTPUT_STRIP_TRAILING_WHITESPACE) ++# (dummy value for nix package without the .git) ++set(PROJECT_VERSION_GIT_SHA 000000000000) + + # Get partial versions into a list + string(REGEX MATCHALL "-.*$|[0-9]+" PROJECT_PARTIAL_VERSION_LIST diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index fd646773ca78..d30d1c28c98b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14018,6 +14018,8 @@ with pkgs; transifex-cli = callPackage ../applications/misc/transifex-cli { }; + translatelocally = callPackage ../applications/misc/translatelocally { }; + translate-shell = callPackage ../applications/misc/translate-shell { }; translatepy = with python3.pkgs; toPythonApplication translatepy;