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