nixpkgs/nixos/modules/i18n/input-method/fcitx5.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

130 lines
4.1 KiB
Nix
Raw Normal View History

2020-12-13 04:29:58 +01:00
{ config, pkgs, lib, ... }:
with lib;
let
im = config.i18n.inputMethod;
cfg = im.fcitx5;
fcitx5Package = pkgs.fcitx5-with-addons.override { inherit (cfg) addons; };
2023-07-23 08:24:08 +02:00
settingsFormat = pkgs.formats.ini { };
in
{
2021-06-02 01:50:11 +02:00
options = {
i18n.inputMethod.fcitx5 = {
addons = mkOption {
type = with types; listOf package;
2023-07-28 16:26:53 +02:00
default = [ ];
example = literalExpression "with pkgs; [ fcitx5-rime ]";
2021-06-02 01:50:11 +02:00
description = lib.mdDoc ''
Enabled Fcitx5 addons.
'';
2020-12-13 04:29:58 +01:00
};
2023-07-28 16:26:53 +02:00
quickPhrase = mkOption {
type = with types; attrsOf str;
2023-07-28 16:26:53 +02:00
default = { };
example = literalExpression ''
{
smile = "";
angry = "()";
}
'';
description = lib.mdDoc "Quick phrases.";
};
quickPhraseFiles = mkOption {
type = with types; attrsOf path;
default = { };
example = literalExpression ''
{
words = ./words.mb;
numbers = ./numbers.mb;
}
'';
description = lib.mdDoc "Quick phrase files.";
};
2023-07-23 08:24:08 +02:00
settings = {
globalOptions = lib.mkOption {
type = lib.types.submodule {
freeformType = settingsFormat.type;
};
default = { };
description = lib.mdDoc ''
The global options in `config` file in ini format.
'';
};
inputMethod = lib.mkOption {
type = lib.types.submodule {
freeformType = settingsFormat.type;
};
default = { };
description = lib.mdDoc ''
The input method configure in `profile` file in ini format.
'';
};
addons = lib.mkOption {
type = with lib.types; (attrsOf anything);
default = { };
description = lib.mdDoc ''
The addon configures in `conf` folder in ini format with global sections.
Each item is written to the corresponding file.
'';
example = literalExpression "{ pinyin.globalSection.EmojiEnabled = \"True\"; }";
};
};
ignoreUserConfig = lib.mkOption {
type = lib.types.bool;
default = false;
description = lib.mdDoc ''
Ignore the user configures. **Warning**: When this is enabled, the
user config files are totally ignored and the user dict can't be saved
and loaded.
'';
};
2020-12-13 04:29:58 +01:00
};
2021-06-02 01:50:11 +02:00
};
2020-12-13 04:29:58 +01:00
imports = [
(mkRemovedOptionModule [ "i18n" "inputMethod" "fcitx5" "enableRimeData" ] ''
RIME data is now included in `fcitx5-rime` by default, and can be customized using `fcitx5-rime.override { rimeDataPkgs = ...; }`
'')
];
2021-06-02 01:50:11 +02:00
config = mkIf (im.enabled == "fcitx5") {
i18n.inputMethod.package = fcitx5Package;
2020-12-13 04:29:58 +01:00
2023-07-28 16:26:53 +02:00
i18n.inputMethod.fcitx5.addons = lib.optionals (cfg.quickPhrase != { }) [
(pkgs.writeTextDir "share/fcitx5/data/QuickPhrase.mb"
(lib.concatStringsSep "\n"
(lib.mapAttrsToList (name: value: "${name} ${value}") cfg.quickPhrase)))
] ++ lib.optionals (cfg.quickPhraseFiles != { }) [
(pkgs.linkFarm "quickPhraseFiles" (lib.mapAttrs'
(name: value: lib.nameValuePair ("share/fcitx5/data/quickphrase.d/${name}.mb") value)
cfg.quickPhraseFiles))
];
2023-07-23 08:24:08 +02:00
environment.etc =
let
optionalFile = p: f: v: lib.optionalAttrs (v != { }) {
"xdg/fcitx5/${p}".text = f v;
};
in
lib.attrsets.mergeAttrsList [
2023-08-15 02:14:08 +02:00
(optionalFile "config" (lib.generators.toINI { }) cfg.settings.globalOptions)
(optionalFile "profile" (lib.generators.toINI { }) cfg.settings.inputMethod)
2023-07-23 08:24:08 +02:00
(lib.concatMapAttrs
(name: value: optionalFile
"conf/${name}.conf"
(lib.generators.toINIWithGlobalSection { })
value)
2023-08-15 02:14:08 +02:00
cfg.settings.addons)
2023-07-23 08:24:08 +02:00
];
2023-07-28 16:26:53 +02:00
environment.variables = {
GTK_IM_MODULE = "fcitx";
QT_IM_MODULE = "fcitx";
XMODIFIERS = "@im=fcitx";
QT_PLUGIN_PATH = [ "${fcitx5Package}/${pkgs.qt6.qtbase.qtPluginPrefix}" ];
2023-07-23 08:24:08 +02:00
} // lib.optionalAttrs cfg.ignoreUserConfig {
SKIP_FCITX_USER_PATH = "1";
};
2021-06-02 01:50:11 +02:00
};
}