From 585bae4bbb48789ece06f4b18cb373651760c4ab Mon Sep 17 00:00:00 2001 From: awwpotato Date: Tue, 22 Apr 2025 17:16:13 -0700 Subject: [PATCH] i18n.inputMethod: align enable option with nixos see: https://github.com/NixOS/nixpkgs/pull/310708 --- modules/i18n/input-method/default.nix | 40 +++++++++++++------ modules/i18n/input-method/fcitx5.nix | 2 +- modules/i18n/input-method/hime.nix | 6 ++- modules/i18n/input-method/kime.nix | 3 +- modules/i18n/input-method/nabi.nix | 6 ++- modules/i18n/input-method/uim.nix | 3 +- tests/modules/i18n/input-method/default.nix | 1 + .../input-method/fcitx5-configuration.nix | 3 +- .../i18n/input-method/kime-configuration.nix | 3 +- .../i18n/input-method/old-fcitx5-enable.nix | 40 +++++++++++++++++++ .../modules/misc/qt/qt-platform-theme-gtk.nix | 5 ++- 11 files changed, 89 insertions(+), 23 deletions(-) create mode 100644 tests/modules/i18n/input-method/old-fcitx5-enable.nix diff --git a/modules/i18n/input-method/default.nix b/modules/i18n/input-method/default.nix index 40c011f78..b3f432d74 100644 --- a/modules/i18n/input-method/default.nix +++ b/modules/i18n/input-method/default.nix @@ -4,11 +4,18 @@ lib, ... }: - let - cfg = config.i18n.inputMethod; + allowedTypes = lib.types.enum [ + "fcitx" + "fcitx5" + "nabi" + "uim" + "hime" + "kime" + ]; + gtk2Cache = pkgs.runCommandLocal "gtk2-immodule.cache" { @@ -36,7 +43,6 @@ let GTK_PATH=${cfg.package}/lib/gtk-3.0/ \ gtk-query-immodules-3.0 > $out/etc/gtk-3.0/immodules.cache ''; - in { imports = [ @@ -49,19 +55,23 @@ in options.i18n = { inputMethod = { + enable = lib.mkEnableOption "an additional input method type" // { + default = cfg.enabled != null; + defaultText = lib.literalMD "`true` if the deprecated option `enabled` is set, false otherwise"; + }; + enabled = lib.mkOption { - type = lib.types.nullOr ( - lib.types.enum [ - "fcitx" - "fcitx5" - "nabi" - "uim" - "hime" - "kime" - ] - ); + type = lib.types.nullOr allowedTypes; default = null; example = "fcitx5"; + description = "Deprecated - use `type` and `enable = true` instead"; + }; + + type = lib.mkOption { + type = lib.types.nullOr allowedTypes; + default = cfg.enabled; + defaultText = lib.literalMD "The value of the deprecated option `enabled`, defaulting to null"; + example = "fcitx5"; description = '' Select the enabled input method. Input methods are software to input symbols that are not available on standard input devices. @@ -112,6 +122,10 @@ in } ]; + warnings = + lib.optional (cfg.enabled != null) + "i18n.inputMethod.enabled will be removed in a future release. Please use .type, and .enable = true instead"; + home.packages = [ cfg.package gtk2Cache diff --git a/modules/i18n/input-method/fcitx5.nix b/modules/i18n/input-method/fcitx5.nix index d7ae8b589..0e8902f1a 100644 --- a/modules/i18n/input-method/fcitx5.nix +++ b/modules/i18n/input-method/fcitx5.nix @@ -82,7 +82,7 @@ in }; }; - config = lib.mkIf (im.enabled == "fcitx5") { + config = lib.mkIf (im.enable && im.type == "fcitx5") { i18n.inputMethod.package = fcitx5Package; home = { diff --git a/modules/i18n/input-method/hime.nix b/modules/i18n/input-method/hime.nix index 269f68634..f8b743e31 100644 --- a/modules/i18n/input-method/hime.nix +++ b/modules/i18n/input-method/hime.nix @@ -4,9 +4,11 @@ lib, ... }: - +let + im = config.i18n.inputMethod; +in { - config = lib.mkIf (config.i18n.inputMethod.enabled == "hime") { + config = lib.mkIf (im.enable && im.type == "hime") { i18n.inputMethod.package = pkgs.hime; home.sessionVariables = { diff --git a/modules/i18n/input-method/kime.nix b/modules/i18n/input-method/kime.nix index 7ca7f4786..421ed16f0 100644 --- a/modules/i18n/input-method/kime.nix +++ b/modules/i18n/input-method/kime.nix @@ -14,6 +14,7 @@ let types ; + im = config.i18n.inputMethod; cfg = config.i18n.inputMethod.kime; in { @@ -46,7 +47,7 @@ in }; }; - config = mkIf (config.i18n.inputMethod.enabled == "kime") { + config = mkIf (im.enable && im.type == "kime") { i18n.inputMethod.package = pkgs.kime; home.sessionVariables = { diff --git a/modules/i18n/input-method/nabi.nix b/modules/i18n/input-method/nabi.nix index e0f433997..d96423590 100644 --- a/modules/i18n/input-method/nabi.nix +++ b/modules/i18n/input-method/nabi.nix @@ -4,9 +4,11 @@ lib, ... }: - +let + im = config.i18n.inputMethod; +in { - config = lib.mkIf (config.i18n.inputMethod.enabled == "nabi") { + config = lib.mkIf (im.enable && im.type == "nabi") { i18n.inputMethod.package = pkgs.nabi; home.sessionVariables = { diff --git a/modules/i18n/input-method/uim.nix b/modules/i18n/input-method/uim.nix index fc870b4a1..dc73b0328 100644 --- a/modules/i18n/input-method/uim.nix +++ b/modules/i18n/input-method/uim.nix @@ -7,6 +7,7 @@ let cfg = config.i18n.inputMethod.uim; + im = config.i18n.inputMethod; in { options = { @@ -30,7 +31,7 @@ in }; - config = lib.mkIf (config.i18n.inputMethod.enabled == "uim") { + config = lib.mkIf (im.enable && im.type == "uim") { i18n.inputMethod.package = pkgs.uim; home.sessionVariables = { diff --git a/tests/modules/i18n/input-method/default.nix b/tests/modules/i18n/input-method/default.nix index a9d5764df..4548971aa 100644 --- a/tests/modules/i18n/input-method/default.nix +++ b/tests/modules/i18n/input-method/default.nix @@ -1,4 +1,5 @@ { input-method-fcitx5-configuration = ./fcitx5-configuration.nix; + input-method-fcitx5-old-enable = ./fcitx5-configuration.nix; input-method-kime-configuration = ./kime-configuration.nix; } diff --git a/tests/modules/i18n/input-method/fcitx5-configuration.nix b/tests/modules/i18n/input-method/fcitx5-configuration.nix index 608befd51..614188b8e 100644 --- a/tests/modules/i18n/input-method/fcitx5-configuration.nix +++ b/tests/modules/i18n/input-method/fcitx5-configuration.nix @@ -7,7 +7,8 @@ lib.mkIf config.test.enableBig { i18n.inputMethod = { - enabled = "fcitx5"; + enable = true; + type = "fcitx5"; fcitx5 = { waylandFrontend = true; themes.example = { diff --git a/tests/modules/i18n/input-method/kime-configuration.nix b/tests/modules/i18n/input-method/kime-configuration.nix index aec4402bd..58d885977 100644 --- a/tests/modules/i18n/input-method/kime-configuration.nix +++ b/tests/modules/i18n/input-method/kime-configuration.nix @@ -13,7 +13,8 @@ let in { i18n.inputMethod = { - enabled = "kime"; + enable = true; + type = "kime"; kime.extraConfig = kimeConfig; }; diff --git a/tests/modules/i18n/input-method/old-fcitx5-enable.nix b/tests/modules/i18n/input-method/old-fcitx5-enable.nix new file mode 100644 index 000000000..0a6994264 --- /dev/null +++ b/tests/modules/i18n/input-method/old-fcitx5-enable.nix @@ -0,0 +1,40 @@ +{ + config, + lib, + realPkgs, + ... +}: + +lib.mkIf config.test.enableBig { + i18n.inputMethod = { + enabled = "fcitx5"; + fcitx5 = { + waylandFrontend = true; + themes.example = { + theme = '' + [Metadata] + Name=example + Version=0.1 + Author=home-manager + Description=Theme for testing + ScaleWithDPI=True + ''; + }; + classicUiConfig = "Theme=example"; + }; + }; + + _module.args.pkgs = lib.mkForce realPkgs; + + test.asserts.warnings.expected = [ + "i18n.inputMethod.enabled will be removed in a future release. Please use .type, and .enable = true instead" + ]; + + nmt.script = '' + assertFileExists home-files/.config/systemd/user/fcitx5-daemon.service + assertFileExists home-files/.local/share/fcitx5/themes/example/theme.conf + assertFileExists home-files/.local/share/fcitx5/conf/classicui.conf + assertFileNotRegex home-path/etc/profile.d/hm-session-vars.sh 'GTK_IM_MODULE' + assertFileNotRegex home-path/etc/profile.d/hm-session-vars.sh 'QT_IM_MODULE' + ''; +} diff --git a/tests/modules/misc/qt/qt-platform-theme-gtk.nix b/tests/modules/misc/qt/qt-platform-theme-gtk.nix index d0aaa086e..8e19f47f6 100644 --- a/tests/modules/misc/qt/qt-platform-theme-gtk.nix +++ b/tests/modules/misc/qt/qt-platform-theme-gtk.nix @@ -6,7 +6,10 @@ platformTheme.name = "gtk"; }; - i18n.inputMethod.enabled = "fcitx5"; + i18n.inputMethod = { + enable = true; + type = "fcitx5"; + }; nixpkgs.overlays = [ (final: prev: {