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