2020-04-24 23:36:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2024-07-27 06:49:29 +00:00
|
|
|
imcfg = config.i18n.inputMethod;
|
|
|
|
cfg = imcfg.ibus;
|
2020-04-24 23:36:52 +00:00
|
|
|
ibusPackage = pkgs.ibus-with-plugins.override { plugins = cfg.engines; };
|
2024-07-27 06:49:29 +00:00
|
|
|
ibusEngine = lib.types.mkOptionType {
|
2020-04-24 23:36:52 +00:00
|
|
|
name = "ibus-engine";
|
2024-07-27 06:49:29 +00:00
|
|
|
inherit (lib.types.package) descriptionClass merge;
|
2020-04-24 23:36:52 +00:00
|
|
|
check = x: (lib.types.package.check x) && (attrByPath ["meta" "isIbusEngine"] false x);
|
|
|
|
};
|
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
impanel = optionalString (cfg.panel != null) "--panel=${cfg.panel}";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
ibusAutostart = pkgs.writeTextFile {
|
|
|
|
name = "autostart-ibus-daemon";
|
|
|
|
destination = "/etc/xdg/autostart/ibus-daemon.desktop";
|
|
|
|
text = ''
|
|
|
|
[Desktop Entry]
|
|
|
|
Name=IBus
|
|
|
|
Type=Application
|
|
|
|
Exec=${ibusPackage}/bin/ibus-daemon --daemonize --xim ${impanel}
|
2022-06-16 17:23:12 +00:00
|
|
|
# GNOME will launch ibus using systemd
|
|
|
|
NotShowIn=GNOME;
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "programs" "ibus" "plugins" ] [ "i18n" "inputMethod" "ibus" "engines" ])
|
|
|
|
];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
i18n.inputMethod.ibus = {
|
|
|
|
engines = mkOption {
|
|
|
|
type = with types; listOf ibusEngine;
|
|
|
|
default = [];
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression "with pkgs.ibus-engines; [ mozc hangul ]";
|
2020-04-24 23:36:52 +00:00
|
|
|
description =
|
|
|
|
let
|
|
|
|
enginesDrv = filterAttrs (const isDerivation) pkgs.ibus-engines;
|
|
|
|
engines = concatStringsSep ", "
|
2022-08-12 12:06:08 +00:00
|
|
|
(map (name: "`${name}`") (attrNames enginesDrv));
|
2024-04-21 15:54:59 +00:00
|
|
|
in "Enabled IBus engines. Available engines are: ${engines}.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
panel = mkOption {
|
|
|
|
type = with types; nullOr path;
|
|
|
|
default = null;
|
2024-01-02 11:29:13 +00:00
|
|
|
example = literalExpression ''"''${pkgs.plasma5Packages.plasma-desktop}/libexec/kimpanel-ibus-panel"'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Replace the IBus panel with another panel.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-07-27 06:49:29 +00:00
|
|
|
config = mkIf (imcfg.enable && imcfg.type == "ibus") {
|
2020-04-24 23:36:52 +00:00
|
|
|
i18n.inputMethod.package = ibusPackage;
|
|
|
|
|
|
|
|
environment.systemPackages = [
|
|
|
|
ibusAutostart
|
|
|
|
];
|
|
|
|
|
|
|
|
# Without dconf enabled it is impossible to use IBus
|
|
|
|
programs.dconf.enable = true;
|
|
|
|
|
2020-07-18 16:06:22 +00:00
|
|
|
programs.dconf.packages = [ ibusPackage ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
services.dbus.packages = [
|
2022-06-16 17:23:12 +00:00
|
|
|
ibusPackage
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
environment.variables = {
|
|
|
|
GTK_IM_MODULE = "ibus";
|
|
|
|
QT_IM_MODULE = "ibus";
|
|
|
|
XMODIFIERS = "@im=ibus";
|
|
|
|
};
|
|
|
|
|
|
|
|
xdg.portal.extraPortals = mkIf config.xdg.portal.enable [
|
|
|
|
ibusPackage
|
|
|
|
];
|
|
|
|
};
|
2022-01-07 04:07:37 +00:00
|
|
|
|
|
|
|
# uses attributes of the linked package
|
|
|
|
meta.buildDocsInSandbox = false;
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|