1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7let
8 cfg = config.i18n.inputMethod;
9
10 allowedTypes = lib.types.enum [
11 "ibus"
12 "fcitx5"
13 "nabi"
14 "uim"
15 "hime"
16 "kime"
17 ];
18
19 gtk2_cache =
20 pkgs.runCommand "gtk2-immodule.cache"
21 {
22 preferLocalBuild = true;
23 allowSubstitutes = false;
24 buildInputs = [
25 cfg.package
26 ];
27 }
28 ''
29 mkdir -p $out/etc/gtk-2.0/
30 GTK_PATH=${cfg.package}/lib/gtk-2.0/ ${pkgs.stdenv.hostPlatform.emulator pkgs.buildPackages} ${lib.getExe' pkgs.gtk2.dev "gtk-query-immodules-2.0"} > $out/etc/gtk-2.0/immodules.cache
31 '';
32
33 gtk3_cache =
34 pkgs.runCommand "gtk3-immodule.cache"
35 {
36 preferLocalBuild = true;
37 allowSubstitutes = false;
38 buildInputs = [
39 cfg.package
40 ];
41 }
42 ''
43 mkdir -p $out/etc/gtk-3.0/
44 GTK_PATH=${cfg.package}/lib/gtk-3.0/ ${pkgs.stdenv.hostPlatform.emulator pkgs.buildPackages} ${lib.getExe' pkgs.gtk3.dev "gtk-query-immodules-3.0"} > $out/etc/gtk-3.0/immodules.cache
45 '';
46
47in
48{
49 options.i18n = {
50 inputMethod = {
51 enable = lib.mkEnableOption "an additional input method type" // {
52 default = cfg.enabled != null;
53 defaultText = lib.literalMD "`true` if the deprecated option `enabled` is set, false otherwise";
54 };
55
56 enabled = lib.mkOption {
57 type = lib.types.nullOr allowedTypes;
58 default = null;
59 example = "fcitx5";
60 description = "Deprecated - use `type` and `enable = true` instead";
61 };
62
63 type = lib.mkOption {
64 type = lib.types.nullOr allowedTypes;
65 default = cfg.enabled;
66 defaultText = lib.literalMD "The value of the deprecated option `enabled`, defaulting to null";
67 example = "fcitx5";
68 description = ''
69 Select the enabled input method. Input methods is a software to input symbols that are not available on standard input devices.
70
71 Input methods are specially used to input Chinese, Japanese and Korean characters.
72
73 Currently the following input methods are available in NixOS:
74
75 - ibus: The intelligent input bus, extra input engines can be added using `i18n.inputMethod.ibus.engines`.
76 - fcitx5: The next generation of fcitx, addons (including engines, dictionaries, skins) can be added using `i18n.inputMethod.fcitx5.addons`.
77 - nabi: A Korean input method based on XIM. Nabi doesn't support Qt 5.
78 - uim: The universal input method, is a library with a XIM bridge. uim mainly support Chinese, Japanese and Korean.
79 - hime: An extremely easy-to-use input method framework.
80 - kime: Koream IME.
81 '';
82 };
83
84 package = lib.mkOption {
85 internal = true;
86 type = lib.types.nullOr lib.types.path;
87 default = null;
88 description = ''
89 The input method method package.
90 '';
91 };
92
93 enableGtk2 = lib.mkEnableOption "Gtk2 support";
94
95 enableGtk3 = lib.mkEnableOption "Gtk3 support" // {
96 default = true;
97 };
98 };
99 };
100
101 config = lib.mkIf cfg.enable {
102 warnings =
103 lib.optional (cfg.enabled != null)
104 "i18n.inputMethod.enabled will be removed in a future release. Please use .type, and .enable = true instead";
105 environment.systemPackages = [
106 cfg.package
107 ]
108 ++ lib.optional (
109 cfg.enableGtk2 && (pkgs.stdenv.hostPlatform.emulatorAvailable pkgs.buildPackages)
110 ) gtk2_cache
111 ++ lib.optional (
112 cfg.enableGtk3 && (pkgs.stdenv.hostPlatform.emulatorAvailable pkgs.buildPackages)
113 ) gtk3_cache;
114 };
115
116 meta = {
117 maintainers = with lib.maintainers; [ ];
118 doc = ./default.md;
119 };
120
121}