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