From 6031ae21f6b69b04701e06fbeadf6585c5e3e0cd Mon Sep 17 00:00:00 2001 From: Vonfry Date: Sat, 2 Apr 2022 18:43:39 +0800 Subject: [PATCH 1/2] fcitx5-rime: add an environment variable for shared data dir passing librime. The original RIME_DATA_DIR is fixed at build time which is set to the package dir under nix store. A such dir is read only for users so if some one want to add a shared data, he has to override fcitx5-rime or librime, which isn't user-friendly. On other distributions, RIME_DATA_DIR may be under /usr/local/share/fcitx5 which is not existed on NixOS. If we set its to /run/current-system/sw/share/..., this will break for non-NixOS user. Therefore, we patch it with a special environment variable to let user to load it dynamically. Co-Authored-by: Lan Tian --- .../fcitx5-rime-with-nix-env-variable.patch | 18 ++++++++++++++++++ pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix | 2 ++ 2 files changed, 20 insertions(+) create mode 100644 pkgs/tools/inputmethods/fcitx5/fcitx5-rime-with-nix-env-variable.patch diff --git a/pkgs/tools/inputmethods/fcitx5/fcitx5-rime-with-nix-env-variable.patch b/pkgs/tools/inputmethods/fcitx5/fcitx5-rime-with-nix-env-variable.patch new file mode 100644 index 000000000000..428a0232dc3b --- /dev/null +++ b/pkgs/tools/inputmethods/fcitx5/fcitx5-rime-with-nix-env-variable.patch @@ -0,0 +1,18 @@ +:100644 100644 fac4f53 aed9617 M src/rimeengine.cpp + +diff --git a/src/rimeengine.cpp b/src/rimeengine.cpp +index fac4f53..aed9617 100644 +--- a/src/rimeengine.cpp ++++ b/src/rimeengine.cpp +@@ -164,7 +164,10 @@ void RimeEngine::rimeStart(bool fullcheck) { + RIME_ERROR() << "Failed to create user directory: " << userDir; + } + } +- const char *sharedDataDir = RIME_DATA_DIR; ++ const char *sharedDataDir = getenv("NIX_RIME_DATA_DIR"); ++ if (!sharedDataDir) { ++ sharedDataDir = RIME_DATA_DIR; ++ } + + RIME_STRUCT(RimeTraits, fcitx_rime_traits); + fcitx_rime_traits.shared_data_dir = sharedDataDir; diff --git a/pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix b/pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix index 3743d6cb9fc8..fac81c8dea12 100644 --- a/pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix +++ b/pkgs/tools/inputmethods/fcitx5/fcitx5-rime.nix @@ -35,6 +35,8 @@ stdenv.mkDerivation rec { librime ]; + patches = [ ./fcitx5-rime-with-nix-env-variable.patch ]; + meta = with lib; { description = "RIME support for Fcitx5"; homepage = "https://github.com/fcitx/fcitx5-rime"; From 2474c8c89a3af7c88a653fc040056d600414307b Mon Sep 17 00:00:00 2001 From: Vonfry Date: Sat, 2 Apr 2022 19:22:24 +0800 Subject: [PATCH 2/2] nixos/fcitx5: add the setting of RIME_DATA_DIR and options for rime-data --- nixos/modules/i18n/input-method/fcitx5.nix | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/nixos/modules/i18n/input-method/fcitx5.nix b/nixos/modules/i18n/input-method/fcitx5.nix index 6fea28e22345..b4b887606e95 100644 --- a/nixos/modules/i18n/input-method/fcitx5.nix +++ b/nixos/modules/i18n/input-method/fcitx5.nix @@ -5,7 +5,9 @@ with lib; let im = config.i18n.inputMethod; cfg = im.fcitx5; - fcitx5Package = pkgs.fcitx5-with-addons.override { inherit (cfg) addons; }; + addons = cfg.addons ++ optional cfg.enableRimeData pkgs.rime-data; + fcitx5Package = pkgs.fcitx5-with-addons.override { inherit addons; }; + whetherRimeDataDir = any (p: p.pname == "fcitx5-rime") cfg.addons; in { options = { i18n.inputMethod.fcitx5 = { @@ -17,16 +19,29 @@ in { Enabled Fcitx5 addons. ''; }; + + enableRimeData = mkEnableOption "default rime-data with fcitx5-rime"; }; }; config = mkIf (im.enabled == "fcitx5") { i18n.inputMethod.package = fcitx5Package; - environment.variables = { - GTK_IM_MODULE = "fcitx"; - QT_IM_MODULE = "fcitx"; - XMODIFIERS = "@im=fcitx"; - }; + environment = mkMerge [{ + variables = { + GTK_IM_MODULE = "fcitx"; + QT_IM_MODULE = "fcitx"; + XMODIFIERS = "@im=fcitx"; + }; + } + (mkIf whetherRimeDataDir { + pathsToLink = [ + "/share/rime-data" + ]; + + variables = { + NIX_RIME_DATA_DIR = "/run/current-system/sw/share/rime-data"; + }; + })]; }; }