at master 2.5 kB view raw
1{ 2 config, 3 pkgs, 4 lib, 5 ... 6}: 7let 8 imcfg = config.i18n.inputMethod; 9 cfg = imcfg.ibus; 10 ibusPackage = pkgs.ibus-with-plugins.override { plugins = cfg.engines; }; 11 ibusEngine = lib.types.mkOptionType { 12 name = "ibus-engine"; 13 inherit (lib.types.package) descriptionClass merge; 14 check = x: (lib.types.package.check x) && (lib.attrByPath [ "meta" "isIbusEngine" ] false x); 15 }; 16 17 impanel = lib.optionalString (cfg.panel != null) "--panel=${cfg.panel}"; 18 19 ibusAutostart = pkgs.writeTextFile { 20 name = "autostart-ibus-daemon"; 21 destination = "/etc/xdg/autostart/ibus-daemon.desktop"; 22 text = '' 23 [Desktop Entry] 24 Name=IBus 25 Type=Application 26 Exec=${ibusPackage}/bin/ibus-daemon --daemonize --xim ${impanel} 27 # GNOME will launch ibus using systemd 28 NotShowIn=GNOME; 29 ''; 30 }; 31in 32{ 33 imports = [ 34 (lib.mkRenamedOptionModule 35 [ "programs" "ibus" "plugins" ] 36 [ "i18n" "inputMethod" "ibus" "engines" ] 37 ) 38 ]; 39 40 options = { 41 i18n.inputMethod.ibus = { 42 engines = lib.mkOption { 43 type = with lib.types; listOf ibusEngine; 44 default = [ ]; 45 example = lib.literalExpression "with pkgs.ibus-engines; [ mozc hangul ]"; 46 description = 47 let 48 enginesDrv = lib.filterAttrs (lib.const lib.isDerivation) pkgs.ibus-engines; 49 engines = lib.concatStringsSep ", " (map (name: "`${name}`") (lib.attrNames enginesDrv)); 50 in 51 "Enabled IBus engines. Available engines are: ${engines}."; 52 }; 53 panel = lib.mkOption { 54 type = with lib.types; nullOr path; 55 default = null; 56 example = lib.literalExpression ''"''${pkgs.kdePackages.plasma-desktop}/libexec/kimpanel-ibus-panel"''; 57 description = "Replace the IBus panel with another panel."; 58 }; 59 }; 60 }; 61 62 config = lib.mkIf (imcfg.enable && imcfg.type == "ibus") { 63 i18n.inputMethod.package = ibusPackage; 64 65 environment.systemPackages = [ 66 ibusAutostart 67 ]; 68 69 # Without dconf enabled it is impossible to use IBus 70 programs.dconf.enable = true; 71 72 programs.dconf.packages = [ ibusPackage ]; 73 74 services.dbus.packages = [ 75 ibusPackage 76 ]; 77 78 environment.variables = { 79 GTK_IM_MODULE = "ibus"; 80 QT_IM_MODULE = "ibus"; 81 XMODIFIERS = "@im=ibus"; 82 }; 83 84 xdg.portal.extraPortals = lib.mkIf config.xdg.portal.enable [ 85 ibusPackage 86 ]; 87 }; 88 89 # uses attributes of the linked package 90 meta.buildDocsInSandbox = false; 91}