From 9dc2df53973e857be96f6348de6cea1c44e14928 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Wed, 13 Dec 2023 11:24:04 +0800 Subject: [PATCH] profiles/i18n: refactor module --- modules/nixos/profiles/i18n.nix | 23 +++++++++---------- .../nixos/workflows/a-happy-gnome/default.nix | 5 +--- .../nixos/workflows/mosey-branch/default.nix | 5 +--- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/modules/nixos/profiles/i18n.nix b/modules/nixos/profiles/i18n.nix index 8de4b839..db799ff0 100644 --- a/modules/nixos/profiles/i18n.nix +++ b/modules/nixos/profiles/i18n.nix @@ -9,20 +9,19 @@ in { options.profiles.i18n = { enable = lib.mkEnableOption "main i18n config"; - ibus.enable = lib.mkEnableOption "i18n config with ibus"; - fcitx5.enable = lib.mkEnableOption "i18n config with fcitx5"; + setup = lib.mkOption { + type = lib.types.enum [ "fcitx5" "ibus" ]; + description = '' + The primary input method engine to be used and its related + configuration and setup. + ''; + default = "fcitx5"; + example = "ibus"; + }; }; config = lib.mkIf cfg.enable (lib.mkMerge [ { - assertions = let enabledi18nConfigs = lib.countAttrs (_: setup: lib.isAttrs setup && setup.enable) cfg; in - [{ - assertion = enabledi18nConfigs <= 1; - message = '' - Only one i18n setup should be enabled at any given time. - ''; - }]; - # I don't speak all of the languages. It's just nice to have some # additional language packs for it. ;p i18n.supportedLocales = lib.mkForce [ "all" ]; @@ -47,7 +46,7 @@ in ]; } - (lib.mkIf cfg.ibus.enable { + (lib.mkIf (cfg.setup == "ibus") { i18n.inputMethod = { enabled = "ibus"; ibus.engines = with pkgs.ibus-engines; [ @@ -62,7 +61,7 @@ in }; }) - (lib.mkIf cfg.fcitx5.enable { + (lib.mkIf (cfg.setup == "fcitx5") { i18n.inputMethod = { enabled = "fcitx5"; fcitx5.addons = with pkgs; [ diff --git a/modules/nixos/workflows/a-happy-gnome/default.nix b/modules/nixos/workflows/a-happy-gnome/default.nix index e1cf57be..9fe7f1c0 100644 --- a/modules/nixos/workflows/a-happy-gnome/default.nix +++ b/modules/nixos/workflows/a-happy-gnome/default.nix @@ -156,10 +156,7 @@ in # Check whether this is inside of my personal configuration or nah. (lib.mkIf (attrs ? _isfoodogsquaredcustom && attrs._isfoodogsquaredcustom) { - profiles.i18n = lib.mkDefault { - enable = true; - ibus.enable = true; - }; + profiles.i18n.setup = "ibus"; }) ]); } diff --git a/modules/nixos/workflows/mosey-branch/default.nix b/modules/nixos/workflows/mosey-branch/default.nix index 98b6b1b8..a5a9a080 100644 --- a/modules/nixos/workflows/mosey-branch/default.nix +++ b/modules/nixos/workflows/mosey-branch/default.nix @@ -183,10 +183,7 @@ in # of the flake input, this shouldn't be applied nor be used in the first # place. (lib.mkIf (attrs ? _isfoodogsquaredcustom && attrs._isfoodogsquaredcustom) { - profiles.i18n = { - enable = true; - ibus.enable = true; - }; + profiles.i18n.setup = "ibus"; }) ]); }