about summary refs log tree commit diff
path: root/nixpkgs/pkgs/misc/translatelocally-models/default.nix
blob: 3c71247d1d9a9e8cdf4b2ae7a96034a45ea30a2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{ lib, stdenvNoCC, fetchurl }:

let
  modelSpecs = (builtins.fromJSON (builtins.readFile ./models.json));
  withCodeAsKey = f: { code, ... }@attrs: lib.nameValuePair code (f attrs);
  mkModelPackage = { name, code, version, url, checksum }:
    stdenvNoCC.mkDerivation {
      pname = "translatelocally-model-${code}";
      version = toString version;

      src = fetchurl {
        inherit url;
        sha256 = checksum;
      };
      dontUnpack = true;

      installPhase = ''
        TARGET="$out/share/translateLocally/models"
        mkdir -p "$TARGET"
        tar -xzf "$src" -C "$TARGET"

        # avoid patching shebangs in inconsistently executable extra files
        find "$out" -type f -exec chmod -x {} +
      '';

      meta = {
        description = "translateLocally model - ${name}";
        homepage = "https://translatelocally.com/";
        # https://github.com/browsermt/students/blob/master/LICENSE.md
        license = lib.licenses.cc-by-sa-40;
      };
    };
  allModelPkgs =
    lib.listToAttrs (map (withCodeAsKey mkModelPackage) modelSpecs);

in allModelPkgs // {
  is-en-tiny = allModelPkgs.is-en-tiny.overrideAttrs (super: {
    # missing model https://github.com/XapaJIaMnu/translateLocally/issues/147
    meta = super.meta // { broken = true; };
  });
} // {
  passthru.updateScript = ./update.sh;
}