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 # GNOME will launch ibus using systemd
27 NotShowIn=GNOME;
28 '';
29 };
30in
31{
32 imports = [
33 (mkRenamedOptionModule [ "programs" "ibus" "plugins" ] [ "i18n" "inputMethod" "ibus" "engines" ])
34 ];
35
36 options = {
37 i18n.inputMethod.ibus = {
38 engines = mkOption {
39 type = with types; listOf ibusEngine;
40 default = [];
41 example = literalExpression "with pkgs.ibus-engines; [ mozc hangul ]";
42 description =
43 let
44 enginesDrv = filterAttrs (const isDerivation) pkgs.ibus-engines;
45 engines = concatStringsSep ", "
46 (map (name: "`${name}`") (attrNames enginesDrv));
47 in
48 lib.mdDoc "Enabled IBus engines. Available engines are: ${engines}.";
49 };
50 panel = mkOption {
51 type = with types; nullOr path;
52 default = null;
53 example = literalExpression ''"''${pkgs.plasma5Packages.plasma-desktop}/lib/libexec/kimpanel-ibus-panel"'';
54 description = lib.mdDoc "Replace the IBus panel with another panel.";
55 };
56 };
57 };
58
59 config = mkIf (config.i18n.inputMethod.enabled == "ibus") {
60 i18n.inputMethod.package = ibusPackage;
61
62 environment.systemPackages = [
63 ibusAutostart
64 ];
65
66 # Without dconf enabled it is impossible to use IBus
67 programs.dconf.enable = true;
68
69 programs.dconf.packages = [ ibusPackage ];
70
71 services.dbus.packages = [
72 ibusPackage
73 ];
74
75 environment.variables = {
76 GTK_IM_MODULE = "ibus";
77 QT_IM_MODULE = "ibus";
78 XMODIFIERS = "@im=ibus";
79 };
80
81 xdg.portal.extraPortals = mkIf config.xdg.portal.enable [
82 ibusPackage
83 ];
84 };
85
86 # uses attributes of the linked package
87 meta.buildDocsInSandbox = false;
88}