1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6 cfg = config.i18n.inputMethod.fcitx;
7 fcitxPackage = pkgs.fcitx.override { plugins = cfg.engines; };
8 fcitxEngine = types.package // {
9 name = "fcitx-engine";
10 check = x: (lib.types.package.check x) && (attrByPath ["meta" "isFcitxEngine"] false x);
11 };
12in
13{
14 options = {
15
16 i18n.inputMethod.fcitx = {
17 engines = mkOption {
18 type = with types; listOf fcitxEngine;
19 default = [];
20 example = literalExample "with pkgs.fcitx-engines; [ mozc hangul ]";
21 description =
22 let
23 engines =
24 lib.concatStringsSep ", "
25 (map (name: "<literal>${name}</literal>")
26 (lib.attrNames pkgs.fcitx-engines));
27 in
28 "Enabled Fcitx engines. Available engines are: ${engines}.";
29 };
30 };
31
32 };
33
34 config = mkIf (config.i18n.inputMethod.enabled == "fcitx") {
35 i18n.inputMethod.package = fcitxPackage;
36
37 environment.variables = {
38 GTK_IM_MODULE = "fcitx";
39 QT_IM_MODULE = "fcitx";
40 XMODIFIERS = "@im=fcitx";
41 };
42 services.xserver.displayManager.sessionCommands = "${fcitxPackage}/bin/fcitx";
43 };
44}