1 { config, pkgs, lib, ... }:
3 imcfg = config.i18n.inputMethod;
7 then pkgs.qt6Packages.fcitx5-with-addons.override { inherit (cfg) addons; }
8 else pkgs.libsForQt5.fcitx5-with-addons.override { inherit (cfg) addons; };
9 settingsFormat = pkgs.formats.ini { };
13 i18n.inputMethod.fcitx5 = {
14 addons = lib.mkOption {
15 type = with lib.types; listOf package;
17 example = lib.literalExpression "with pkgs; [ fcitx5-rime ]";
19 Enabled Fcitx5 addons.
22 waylandFrontend = lib.mkOption {
23 type = lib.types.bool;
26 Use the Wayland input method frontend.
27 See [Using Fcitx 5 on Wayland](https://fcitx-im.org/wiki/Using_Fcitx_5_on_Wayland).
30 plasma6Support = lib.mkOption {
31 type = lib.types.bool;
32 default = config.services.desktopManager.plasma6.enable;
33 defaultText = lib.literalExpression "config.services.desktopManager.plasma6.enable";
35 Use qt6 versions of fcitx5 packages.
36 Required for configuring fcitx5 in KDE System Settings.
39 quickPhrase = lib.mkOption {
40 type = with lib.types; attrsOf str;
42 example = lib.literalExpression ''
48 description = "Quick phrases.";
50 quickPhraseFiles = lib.mkOption {
51 type = with lib.types; attrsOf path;
53 example = lib.literalExpression ''
56 numbers = ./numbers.mb;
59 description = "Quick phrase files.";
62 globalOptions = lib.mkOption {
63 type = lib.types.submodule {
64 freeformType = settingsFormat.type;
68 The global options in `config` file in ini format.
71 inputMethod = lib.mkOption {
72 type = lib.types.submodule {
73 freeformType = settingsFormat.type;
77 The input method configure in `profile` file in ini format.
80 addons = lib.mkOption {
81 type = with lib.types; (attrsOf anything);
84 The addon configures in `conf` folder in ini format with global sections.
85 Each item is written to the corresponding file.
87 example = lib.literalExpression "{ pinyin.globalSection.EmojiEnabled = \"True\"; }";
90 ignoreUserConfig = lib.mkOption {
91 type = lib.types.bool;
94 Ignore the user configures. **Warning**: When this is enabled, the
95 user config files are totally ignored and the user dict can't be saved
103 (lib.mkRemovedOptionModule [ "i18n" "inputMethod" "fcitx5" "enableRimeData" ] ''
104 RIME data is now included in `fcitx5-rime` by default, and can be customized using `fcitx5-rime.override { rimeDataPkgs = ...; }`
108 config = lib.mkIf (imcfg.enable && imcfg.type == "fcitx5") {
109 i18n.inputMethod.package = fcitx5Package;
111 i18n.inputMethod.fcitx5.addons = lib.optionals (cfg.quickPhrase != { }) [
112 (pkgs.writeTextDir "share/fcitx5/data/QuickPhrase.mb"
113 (lib.concatStringsSep "\n"
114 (lib.mapAttrsToList (name: value: "${name} ${value}") cfg.quickPhrase)))
115 ] ++ lib.optionals (cfg.quickPhraseFiles != { }) [
116 (pkgs.linkFarm "quickPhraseFiles" (lib.mapAttrs'
117 (name: value: lib.nameValuePair ("share/fcitx5/data/quickphrase.d/${name}.mb") value)
118 cfg.quickPhraseFiles))
122 optionalFile = p: f: v: lib.optionalAttrs (v != { }) {
123 "xdg/fcitx5/${p}".text = f v;
126 lib.attrsets.mergeAttrsList [
127 (optionalFile "config" (lib.generators.toINI { }) cfg.settings.globalOptions)
128 (optionalFile "profile" (lib.generators.toINI { }) cfg.settings.inputMethod)
130 (name: value: optionalFile
132 (lib.generators.toINIWithGlobalSection { })
137 environment.variables = {
138 XMODIFIERS = "@im=fcitx";
139 QT_PLUGIN_PATH = [ "${fcitx5Package}/${pkgs.qt6.qtbase.qtPluginPrefix}" ];
140 } // lib.optionalAttrs (!cfg.waylandFrontend) {
141 GTK_IM_MODULE = "fcitx";
142 QT_IM_MODULE = "fcitx";
143 } // lib.optionalAttrs cfg.ignoreUserConfig {
144 SKIP_FCITX_USER_PATH = "1";