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 enginesDrv = filterAttrs (const isDerivation) pkgs.fcitx-engines;
24 engines = concatStringsSep ", "
25 (map (name: "<literal>${name}</literal>") (attrNames enginesDrv));
26 in
27 "Enabled Fcitx engines. Available engines are: ${engines}.";
28 };
29 };
30
31 };
32
33 config = mkIf (config.i18n.inputMethod.enabled == "fcitx") {
34 i18n.inputMethod.package = fcitxPackage;
35
36 environment.variables = {
37 GTK_IM_MODULE = "fcitx";
38 QT_IM_MODULE = "fcitx";
39 XMODIFIERS = "@im=fcitx";
40 };
41 services.xserver.displayManager.sessionCommands = "${fcitxPackage}/bin/fcitx";
42 };
43}