about summary refs log tree commit diff
path: root/pkgs/by-name/ma/maa-assistant-arknights/package.nix
blob: 32d43f3d05b140ba42f57f5717a2ea2c7c13dffc (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{
  lib,
  config,
  callPackage,
  stdenv,
  overrideSDK,
  fetchFromGitHub,
  asio,
  cmake,
  libcpr,
  onnxruntime,
  opencv,
  isBeta ? false,
  cudaSupport ? config.cudaSupport,
  cudaPackages ? { },
}:

let
  fastdeploy = callPackage ./fastdeploy-ppocr.nix { };
  sources = lib.importJSON ./pin.json;
in
# https://github.com/NixOS/nixpkgs/issues/314160
(if stdenv.hostPlatform.isDarwin then overrideSDK stdenv "11.0" else stdenv).mkDerivation
  (finalAttr: {
    pname = "maa-assistant-arknights" + lib.optionalString isBeta "-beta";
    version = if isBeta then sources.beta.version else sources.stable.version;

    src = fetchFromGitHub {
      owner = "MaaAssistantArknights";
      repo = "MaaAssistantArknights";
      rev = "v${finalAttr.version}";
      hash = if isBeta then sources.beta.hash else sources.stable.hash;
    };

    nativeBuildInputs = [
      asio
      cmake
      fastdeploy.cmake
    ] ++ lib.optionals cudaSupport [ cudaPackages.cuda_nvcc ];

    buildInputs =
      [
        fastdeploy
        libcpr
        onnxruntime
        opencv
      ]
      ++ lib.optionals cudaSupport (
        with cudaPackages;
        [
          cuda_cccl # cub/cub.cuh
          libcublas # cublas_v2.h
          libcurand # curand.h
          libcusparse # cusparse.h
          libcufft # cufft.h
          cudnn # cudnn.h
          cuda_cudart
        ]
      );

    cmakeBuildType = "None";

    cmakeFlags = [
      (lib.cmakeBool "BUILD_SHARED_LIBS" true)
      (lib.cmakeBool "INSTALL_FLATTEN" false)
      (lib.cmakeBool "INSTALL_PYTHON" true)
      (lib.cmakeBool "INSTALL_RESOURCE" true)
      (lib.cmakeBool "USE_MAADEPS" false)
      (lib.cmakeFeature "MAA_VERSION" "v${finalAttr.version}")
    ];

    passthru.updateScript = ./update.sh;

    postPatch = ''
      cp -v ${fastdeploy.cmake}/Findonnxruntime.cmake cmake/
    '';

    postInstall = ''
      mkdir -p $out/share/${finalAttr.pname}
      mv $out/{Python,resource} $out/share/${finalAttr.pname}
    '';

    meta = with lib; {
      description = "Arknights assistant";
      homepage = "https://github.com/MaaAssistantArknights/MaaAssistantArknights";
      license = licenses.agpl3Only;
      maintainers = with maintainers; [ Cryolitia ];
      platforms = platforms.linux ++ platforms.darwin;
    };
  })