1{ lib, stdenv, rustPlatform, rustc, cargo, fetchFromGitHub, pkg-config, cmake, extra-cmake-modules
2, withWayland ? true
3, withIndicator ? true, dbus, libdbusmenu
4, withXim ? true, xorg, cairo
5, withGtk3 ? true, gtk3
6, withGtk4 ? true, gtk4
7, withQt5 ? true, qt5
8, withQt6 ? false, qt6
9}:
10
11let
12 cmake_args = lib.optionals withGtk3 ["-DENABLE_GTK3=ON"]
13 ++ lib.optionals withGtk4 ["-DENABLE_GTK4=ON"]
14 ++ lib.optionals withQt5 ["-DENABLE_QT5=ON"]
15 ++ lib.optionals withQt6 ["-DENABLE_QT6=ON"];
16
17 optFlag = w: (if w then "1" else "0");
18in
19stdenv.mkDerivation rec {
20 pname = "kime";
21 version = "3.0.2";
22
23 src = fetchFromGitHub {
24 owner = "Riey";
25 repo = pname;
26 rev = "v${version}";
27 sha256 = "sha256-qLQ6DmV7KHhdXWR5KtO52cmXBm818zKJVj4nxsR14dc=";
28 };
29
30 cargoDeps = rustPlatform.fetchCargoTarball {
31 inherit src;
32 sha256 = "sha256-/o9b7YvrpV+IujkllFWAz6Mg4CbS9BInF8antfZ0Vsw=";
33 };
34
35 # Replace autostart path
36 postPatch = ''
37 substituteInPlace res/kime.desktop --replace "/usr/bin/kime" "$out/bin/kime"
38 '';
39
40 dontUseCmakeConfigure = true;
41 dontWrapQtApps = true;
42 buildPhase = ''
43 runHook preBuild
44 export KIME_BUILD_CHECK=1
45 export KIME_BUILD_INDICATOR=${optFlag withIndicator}
46 export KIME_BUILD_XIM=${optFlag withXim}
47 export KIME_BUILD_WAYLAND=${optFlag withWayland}
48 export KIME_BUILD_KIME=1
49 export KIME_CARGO_ARGS="-j$NIX_BUILD_CORES --frozen"
50 export KIME_MAKE_ARGS="-j$NIX_BUILD_CORES"
51 export KIME_CMAKE_ARGS="${lib.concatStringsSep " " cmake_args}"
52 bash scripts/build.sh -r
53 runHook postBuild
54 '';
55
56 doCheck = true;
57 checkPhase = ''
58 runHook preCheck
59 cargo test --release --frozen
60 runHook postCheck
61 '';
62
63 installPhase = ''
64 runHook preInstall
65 export KIME_BIN_DIR=bin
66 export KIME_INSTALL_HEADER=1
67 export KIME_INSTALL_DOC=1
68 export KIME_INCLUDE_DIR=include
69 export KIME_DOC_DIR=share/doc/kime
70 export KIME_ICON_DIR=share/icons
71 export KIME_LIB_DIR=lib
72 export KIME_QT5_DIR=lib/qt-${qt5.qtbase.version}
73 export KIME_QT6_DIR=lib/qt-${qt6.qtbase.version}
74 bash scripts/install.sh "$out"
75 runHook postInstall
76 '';
77
78 doInstallCheck = true;
79 installCheckPhase = ''
80 runHook preInstallCheck
81 # Don't pipe output to head directly it will cause broken pipe error https://github.com/rust-lang/rust/issues/46016
82 kimeVersion=$(echo "$($out/bin/kime --version)" | head -n1)
83 echo "'kime --version | head -n1' returns: $kimeVersion"
84 [[ "$kimeVersion" == "kime ${version}" ]]
85 runHook postInstallCheck
86 '';
87
88 buildInputs = lib.optionals withIndicator [ dbus libdbusmenu ]
89 ++ lib.optionals withXim [ xorg.libxcb cairo ]
90 ++ lib.optionals withGtk3 [ gtk3 ]
91 ++ lib.optionals withGtk4 [ gtk4 ]
92 ++ lib.optionals withQt5 [ qt5.qtbase ]
93 ++ lib.optionals withQt6 [ qt6.qtbase ];
94
95 nativeBuildInputs = [
96 pkg-config
97 cmake
98 extra-cmake-modules
99 rustPlatform.bindgenHook
100 rustPlatform.cargoSetupHook
101 rustc
102 cargo
103 ];
104
105 RUST_BACKTRACE = 1;
106
107 meta = with lib; {
108 homepage = "https://github.com/Riey/kime";
109 description = "Korean IME";
110 license = licenses.gpl3Plus;
111 maintainers = [ maintainers.riey ];
112 platforms = platforms.linux;
113 };
114}