nixpkgs/pkgs/applications/misc/translatelocally/default.nix
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00

80 lines
1.9 KiB
Nix

{ lib, stdenv, fetchFromGitHub
, cmake, qt6, libarchive, pcre2, protobuf, gperftools, blas
, runCommand, translatelocally, translatelocally-models
}:
let
rev = "27771d884d3607cf6331da16b15e27aba819573d";
in stdenv.mkDerivation (finalAttrs: {
pname = "translatelocally";
version = "0-unstable-2024-05-12";
src = fetchFromGitHub {
owner = "XapaJIaMnu";
repo = "translateLocally";
inherit rev;
hash = "sha256-oPtiyONqkZ5xOIhDezk8mkmi9O8gNYwHo0gcqSa89qI=";
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
'';
# https://github.com/XapaJIaMnu/translateLocally/blob/81ed8b9/.github/workflows/build.yml#L330
postConfigure = lib.optionalString stdenv.hostPlatform.isAarch64 ''
bash ../cmake/fix_ruy_build.sh .. .
'';
nativeBuildInputs = [
cmake
protobuf
qt6.wrapQtAppsHook
];
buildInputs = [
qt6.qttools
qt6.qtbase
qt6.qtsvg
qt6.qtwayland
libarchive
pcre2
protobuf
gperftools # provides tcmalloc
blas
];
cmakeFlags = [
"-DBLAS_LIBRARIES=-lblas"
"-DCBLAS_LIBRARIES=-lcblas"
];
passthru.tests = {
cli-translate = runCommand "${finalAttrs.pname}-test-cli-translate" {
nativeBuildInputs = [
translatelocally
translatelocally-models.fr-en-tiny
];
} ''
export LC_ALL="C.UTF-8"
echo "Bonjour" | translateLocally -m fr-en-tiny > $out
diff "$out" <(echo "Hello")
'';
};
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;
};
})