1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6 cfg = config.i18n.inputMethod.ibus;
7 ibusPackage = pkgs.ibus-with-plugins.override { plugins = cfg.engines; };
8 ibusEngine = types.package // {
9 name = "ibus-engine";
10 check = x: (lib.types.package.check x) && (attrByPath ["meta" "isIbusEngine"] false x);
11 };
12
13 impanel =
14 if cfg.panel != null
15 then "--panel=${cfg.panel}"
16 else "";
17
18 ibusAutostart = pkgs.writeTextFile {
19 name = "autostart-ibus-daemon";
20 destination = "/etc/xdg/autostart/ibus-daemon.desktop";
21 text = ''
22 [Desktop Entry]
23 Name=IBus
24 Type=Application
25 Exec=${ibusPackage}/bin/ibus-daemon --daemonize --xim ${impanel}
26 '';
27 };
28in
29{
30 options = {
31 i18n.inputMethod.ibus = {
32 engines = mkOption {
33 type = with types; listOf ibusEngine;
34 default = [];
35 example = literalExample "with pkgs.ibus-engines; [ mozc hangul ]";
36 description =
37 let
38 enginesDrv = filterAttrs (const isDerivation) pkgs.ibus-engines;
39 engines = concatStringsSep ", "
40 (map (name: "<literal>${name}</literal>") (attrNames enginesDrv));
41 in
42 "Enabled IBus engines. Available engines are: ${engines}.";
43 };
44 panel = mkOption {
45 type = with types; nullOr path;
46 default = null;
47 example = literalExample "''${pkgs.plasma5.plasma-desktop}/lib/libexec/kimpanel-ibus-panel";
48 description = "Replace the IBus panel with another panel.";
49 };
50 };
51 };
52
53 config = mkIf (config.i18n.inputMethod.enabled == "ibus") {
54 i18n.inputMethod.package = ibusPackage;
55
56 # Without dconf enabled it is impossible to use IBus
57 environment.systemPackages = with pkgs; [
58 ibus-qt gnome3.dconf ibusAutostart
59 ];
60
61 environment.variables = {
62 GTK_IM_MODULE = "ibus";
63 QT_IM_MODULE = "ibus";
64 XMODIFIERS = "@im=ibus";
65 };
66 };
67}