about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/inputmethods/kime/default.nix
blob: 35ed99b5a426351e87dd37475792b3b937aae15f (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{ lib, stdenv, rustPlatform, rustc, cargo, fetchFromGitHub, pkg-config, cmake, extra-cmake-modules, llvmPackages
, withWayland ? true
, withIndicator ? true, dbus, libdbusmenu
, withXim ? true, xorg, cairo
, withGtk2 ? true, gtk2
, withGtk3 ? true, gtk3
, withQt5 ? true, qt5
}:

let
  cmake_args = lib.optionals withGtk2 ["-DENABLE_GTK2=ON"]
  ++ lib.optionals withGtk3 ["-DENABLE_GTK3=ON"]
  ++ lib.optionals withQt5 ["-DENABLE_QT5=ON"];

  optFlag = w: (if w then "1" else "0");
in
stdenv.mkDerivation rec {
  pname = "kime";
  version = "2.5.2";

  src = fetchFromGitHub {
    owner = "Riey";
    repo = pname;
    rev = "v${version}";
    sha256 = "10zd4yrqxzxf4nj3b5bsblcmlbqssxqq9pac0misa1g61jdbszj8";
  };

  cargoDeps = rustPlatform.fetchCargoTarball {
    inherit src;
    sha256 = "1bimi7020m7v287bh7via7zm9m7y13d13kqpd772xmpdbwrj8nrl";
  };

  # Replace autostart path
  postPatch = ''
    substituteInPlace res/kime.desktop --replace "/usr/bin/kime" "$out/bin/kime"
  '';

  dontUseCmakeConfigure = true;
  dontWrapQtApps = true;
  buildPhase = ''
    runHook preBuild
    export KIME_BUILD_CHECK=1
    export KIME_BUILD_INDICATOR=${optFlag withIndicator}
    export KIME_BUILD_XIM=${optFlag withXim}
    export KIME_BUILD_WAYLAND=${optFlag withWayland}
    export KIME_BUILD_KIME=1
    export KIME_CARGO_ARGS="-j$NIX_BUILD_CORES --frozen"
    export KIME_MAKE_ARGS="-j$NIX_BUILD_CORES"
    export KIME_CMAKE_ARGS="${lib.concatStringsSep " " cmake_args}"
    bash scripts/build.sh -r
    runHook postBuild
  '';

  doCheck = true;
  checkPhase = ''
    runHook preCheck
    cargo test --release --frozen
    runHook postCheck
  '';

  installPhase = ''
    runHook preInstall
    export KIME_BIN_DIR=bin
    export KIME_INSTALL_HEADER=1
    export KIME_INSTALL_DOC=1
    export KIME_INCLUDE_DIR=include
    export KIME_DOC_DIR=share/doc/kime
    export KIME_ICON_DIR=share/icons
    export KIME_LIB_DIR=lib
    export KIME_QT5_DIR=lib/qt-${qt5.qtbase.version}
    bash scripts/install.sh "$out"
    runHook postInstall
  '';

  doInstallCheck = true;
  installCheckPhase = ''
    runHook preInstallCheck
    # Don't pipe output to head directly it will cause broken pipe error https://github.com/rust-lang/rust/issues/46016
    kimeVersion=$(echo "$($out/bin/kime --version)" | head -n1)
    echo "'kime --version | head -n1' returns: $kimeVersion"
    [[ "$kimeVersion" == "kime ${version}" ]]
    runHook postInstallCheck
  '';

  buildInputs = lib.optionals withIndicator [ dbus libdbusmenu ]
  ++ lib.optionals withXim [ xorg.libxcb cairo ]
  ++ lib.optionals withGtk2 [ gtk2 ]
  ++ lib.optionals withGtk3 [ gtk3 ]
  ++ lib.optionals withQt5 [ qt5.qtbase ];

  nativeBuildInputs = [
    pkg-config
    llvmPackages.clang
    llvmPackages.libclang
    llvmPackages.bintools
    cmake
    extra-cmake-modules
    rustPlatform.cargoSetupHook
    rustc
    cargo
  ];

  RUST_BACKTRACE = 1;
  LIBCLANG_PATH = "${llvmPackages.libclang}/lib";

  meta = with lib; {
    homepage = "https://github.com/Riey/kime";
    description = "Korean IME";
    license = licenses.gpl3Plus;
    maintainers = [ maintainers.riey ];
    platforms = platforms.linux;
  };
}