0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

nixos/fcitx5: handle multi-line string and escape in quickPhrase (#367332)

This commit is contained in:
Nick Cao 2024-12-25 13:10:29 -05:00 committed by GitHub
commit 3765be9ac6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,11 +1,17 @@
{ config, pkgs, lib, ... }: {
config,
pkgs,
lib,
...
}:
let let
imcfg = config.i18n.inputMethod; imcfg = config.i18n.inputMethod;
cfg = imcfg.fcitx5; cfg = imcfg.fcitx5;
fcitx5Package = fcitx5Package =
if cfg.plasma6Support if cfg.plasma6Support then
then pkgs.qt6Packages.fcitx5-with-addons.override { inherit (cfg) addons; } pkgs.qt6Packages.fcitx5-with-addons.override { inherit (cfg) addons; }
else pkgs.libsForQt5.fcitx5-with-addons.override { inherit (cfg) addons; }; else
pkgs.libsForQt5.fcitx5-with-addons.override { inherit (cfg) addons; };
settingsFormat = pkgs.formats.ini { }; settingsFormat = pkgs.formats.ini { };
in in
{ {
@ -108,40 +114,48 @@ in
config = lib.mkIf (imcfg.enable && imcfg.type == "fcitx5") { config = lib.mkIf (imcfg.enable && imcfg.type == "fcitx5") {
i18n.inputMethod.package = fcitx5Package; i18n.inputMethod.package = fcitx5Package;
i18n.inputMethod.fcitx5.addons = lib.optionals (cfg.quickPhrase != { }) [ i18n.inputMethod.fcitx5.addons =
(pkgs.writeTextDir "share/fcitx5/data/QuickPhrase.mb" lib.optionals (cfg.quickPhrase != { }) [
(lib.concatStringsSep "\n" (pkgs.writeTextDir "share/fcitx5/data/QuickPhrase.mb" (
(lib.mapAttrsToList (name: value: "${name} ${value}") cfg.quickPhrase))) lib.mapAttrsToList (
] ++ lib.optionals (cfg.quickPhraseFiles != { }) [ name: value: "${name} ${builtins.replaceStrings [ "\\" "\n" ] [ "\\\\" "\\n" ] value}"
(pkgs.linkFarm "quickPhraseFiles" (lib.mapAttrs' ) cfg.quickPhrase
(name: value: lib.nameValuePair ("share/fcitx5/data/quickphrase.d/${name}.mb") value) ))
cfg.quickPhraseFiles)) ]
]; ++ lib.optionals (cfg.quickPhraseFiles != { }) [
(pkgs.linkFarm "quickPhraseFiles" (
lib.mapAttrs' (
name: value: lib.nameValuePair ("share/fcitx5/data/quickphrase.d/${name}.mb") value
) cfg.quickPhraseFiles
))
];
environment.etc = environment.etc =
let let
optionalFile = p: f: v: lib.optionalAttrs (v != { }) { optionalFile =
"xdg/fcitx5/${p}".text = f v; p: f: v:
}; lib.optionalAttrs (v != { }) {
"xdg/fcitx5/${p}".text = f v;
};
in in
lib.attrsets.mergeAttrsList [ lib.attrsets.mergeAttrsList [
(optionalFile "config" (lib.generators.toINI { }) cfg.settings.globalOptions) (optionalFile "config" (lib.generators.toINI { }) cfg.settings.globalOptions)
(optionalFile "profile" (lib.generators.toINI { }) cfg.settings.inputMethod) (optionalFile "profile" (lib.generators.toINI { }) cfg.settings.inputMethod)
(lib.concatMapAttrs (lib.concatMapAttrs (
(name: value: optionalFile name: value: optionalFile "conf/${name}.conf" (lib.generators.toINIWithGlobalSection { }) value
"conf/${name}.conf" ) cfg.settings.addons)
(lib.generators.toINIWithGlobalSection { })
value)
cfg.settings.addons)
]; ];
environment.variables = { environment.variables =
XMODIFIERS = "@im=fcitx"; {
QT_PLUGIN_PATH = [ "${fcitx5Package}/${pkgs.qt6.qtbase.qtPluginPrefix}" ]; XMODIFIERS = "@im=fcitx";
} // lib.optionalAttrs (!cfg.waylandFrontend) { QT_PLUGIN_PATH = [ "${fcitx5Package}/${pkgs.qt6.qtbase.qtPluginPrefix}" ];
GTK_IM_MODULE = "fcitx"; }
QT_IM_MODULE = "fcitx"; // lib.optionalAttrs (!cfg.waylandFrontend) {
} // lib.optionalAttrs cfg.ignoreUserConfig { GTK_IM_MODULE = "fcitx";
SKIP_FCITX_USER_PATH = "1"; QT_IM_MODULE = "fcitx";
}; }
// lib.optionalAttrs cfg.ignoreUserConfig {
SKIP_FCITX_USER_PATH = "1";
};
}; };
} }