Jump to content

IBus: Difference between revisions

From NixOS Wiki
imported>Symphorien
ibus with custom emoji
 
Jasi (talk | contribs)
m Installation: Format code block (using nixfmt-rfc-style)
 
(13 intermediate revisions by 8 users not shown)
Line 1: Line 1:
IBus is a bus for various input methods.
[https://en.wikipedia.org/wiki/Intelligent_Input_Bus IBus] is a bus for various input methods.


=== Installation ===
== Installation ==
Enabling IBus is described in the [https://nixos.org/nixos/manual/index.html#module-services-input-methods-ibus manual].
Enabling IBus is described in the [https://nixos.org/nixos/manual/index.html#module-services-input-methods-ibus manual]. To enable it is as follows:
Mainly, it can be done as follows:


{{file|/etc/nixos.configuration.nix|nix|<nowiki>
{{file|3={ pkgs, lib, ... }:
{pkgs, lib, ...}
{
{
i18n.inputMethod = {
  i18n.inputMethod = {
  enabled = "ibus";
    enable = true;
  ibus.engines = with pkgs.ibus-engines; [ /* any engine you want, for example */ anthy ];
    type = "ibus";
};
    ibus.engines = with pkgs.ibus-engines; [
}
      # Your engines here
</nowiki>}}
    ];
  };
}|name=/etc/nixos/configuration.nix|lang=nix}}Available engines are listed under the <code>pkgs.ibus-engines</code> attribute set. The list of available engines can be viewed in the documentation for the {{nixos:option|i18n.inputMethod.ibus.engines}}option.


{{Evaluate}}
After rebuilding and switching to the new configuration, you still need to logout from your session and login again for ibus to work correctly.
After switching, you still need to logout from your session and login again for ibus to work correctly.


==== Input methods ====
== Troubleshooting ==
To get the list of available engines, you can use the tab completion of <code>nix repl</code>.
{{Commands|
$ nix repl
nix-repl> ibus-engines.<Tab>
}}


==== Custom emojis ====
=== Custom emojis ===
Custom emojis can be added to the emoji selection dialog of IBus. This can be used to workaround the fact that GTK does not support compose rules which output more than one unicode codepoint. The core of the method is to set the following hidden gsettings:
Custom emojis can be added to the emoji selection dialog of IBus. This can be used to workaround the fact that GTK does not support compose rules which output more than one unicode codepoint. Here an example [[Home Manager]] snippet.
{{Commands|
{{file|3={ pkgs, lib, config, ... }:
gsettings set org.freedesktop.ibus.panel.emoji favorite-annotations "['shrug']"
gsettings set org.freedesktop.ibus.panel.emoji favorites "['¯\_(ツ)_/¯']"
}}
Then, typing <code>Ctrl+Shift+e</code> and then <code>shrug</code>, Space and Return will insert <code>¯\_(ツ)_/¯</code>.
 
But on NixOS, gsettings cannot access schemas without wrapping. In order to workaround this, and make this declarative, here is a possible [[Home Manager]] module.
{{file|~/.config/nixpkgs/home.nix|nix|<nowiki>
{ pkgs, lib, config, ... }:
let
let
   /* define here the list of desired favorite emoji */
   /* define here the list of desired favorite emoji */
   fav = {
   fav = {
     shrug = ''¯\_(ツ)_/¯'';
     shrug = ''¯\_(ツ)_/¯'';
    "markdown-shrug" = ''¯\\\_(ツ)\_/¯'';
     flip = ''(╯°□°)╯︵ ┻━┻'';
     flip = ''(╯°□°)╯︵ ┻━┻'';
   };
   };
  /* end */
  listToFile = l: builtins.toFile "fav" (builtins.toJSON l);
  /* gsettings needs to be wrapped with ibus to find the schemas */
  gsettings = pkgs.stdenv.mkDerivation {
    name = "gsettings-for-ibus";
    buildInputs = [ pkgs.ibus ];
    nativeBuildInputs = [ pkgs.wrapGAppsHook ];
    dontUnpack = true;
    dontBuild = true;
    installPhase = ''
      mkdir -p $out/bin
      ln -s ${pkgs.glib.bin}/bin/gsettings $out/bin
    '';
  };
  /* this script applies our modifications */
  applyScript = pkgs.writeShellScript "apply-emoji-prefs" ''
    ${gsettings}/bin/gsettings set org.freedesktop.ibus.panel.emoji favorites "$(${pkgs.coreutils}/bin/cat ${listToFile (lib.attrValues fav)})"
    ${gsettings}/bin/gsettings set org.freedesktop.ibus.panel.emoji favorite-annotations "$(${pkgs.coreutils}/bin/cat ${listToFile (lib.attrNames fav)})"
  '';
in
in
{
{
   systemd.user.services.ibus-favorite = {
   dconf.settings."desktop/ibus/panel/emoji" = with lib.hm.gvariant; {
    Unit = {
     favorite-annotations = mkArray type.string (lib.attrNames fav);
      Description = "Set ibus favorite emoji";
     favorites = mkArray type.string (lib.attrValues fav);
     };
    Install = {
      WantedBy = [ "graphical-session.target" ];
     };
    Service = {
      ExecStart = "${applyScript}";
      Type = "oneshot";
      RemainAfterExit = true;
    };
   };
   };
}
}|name=~/.config/home-manager/home.nix|lang=nix}}
 
Then, pressing <code>Ctrl+Shift+e</code> and then typing <code>shrug</code>, then hitting <code>Space</code> and <code>Return</code> will insert <code>¯\_(ツ)_/¯</code>.
 
== See also ==
 
* [[Locales]]


</nowiki>}}
[[Category:Configuration]]
[[Category:NixOS Manual]]

Latest revision as of 00:51, 10 July 2025

IBus is a bus for various input methods.

Installation

Enabling IBus is described in the manual. To enable it is as follows:

❄︎ /etc/nixos/configuration.nix
{ pkgs, lib, ... }:
{
  i18n.inputMethod = {
    enable = true;
    type = "ibus";
    ibus.engines = with pkgs.ibus-engines; [
      # Your engines here
    ];
  };
}

Available engines are listed under the pkgs.ibus-engines attribute set. The list of available engines can be viewed in the documentation for the i18n.inputMethod.ibus.enginesoption.

After rebuilding and switching to the new configuration, you still need to logout from your session and login again for ibus to work correctly.

Troubleshooting

Custom emojis

Custom emojis can be added to the emoji selection dialog of IBus. This can be used to workaround the fact that GTK does not support compose rules which output more than one unicode codepoint. Here an example Home Manager snippet.

❄︎ ~/.config/home-manager/home.nix
{ pkgs, lib, config, ... }:
let
  /* define here the list of desired favorite emoji */
  fav = {
    shrug = ''¯\_(ツ)_/¯'';
    "markdown-shrug" = ''¯\\\_(ツ)\_/¯'';
    flip = ''(╯°□°)╯︵ ┻━┻'';
  };
in
{
  dconf.settings."desktop/ibus/panel/emoji" = with lib.hm.gvariant; {
    favorite-annotations = mkArray type.string (lib.attrNames fav);
    favorites = mkArray type.string (lib.attrValues fav);
  };
}

Then, pressing Ctrl+Shift+e and then typing shrug, then hitting Space and Return will insert ¯\_(ツ)_/¯.

See also