Unsetting GTK_IM_MODULE environment variable

I’m using fcitx5. Today, I updated my nix flake. when I reenter my desktop, the fcitx5 let I unset GTK_IM_MODULE.
图片
I tried write it into my configurtion:

{ lib, ... }: {
  # ...
  home.sessionVariables.GTK_IM_MODULE = lib.mkForce null;
}

Rebuiling, oh, home-manager can’t use this.

       error: A definition for option `home-manager.users.nahida.home.sessionVariables.GTK_IM_MODULE' is not of type `string or path or signed integer or floating point number'. Definition values:
       - In `/nix/store/1bgg986an8rjw90map6xswphc82zxcrm-source/home-manager/nahida/programs/fcitx5': null

I also tried use builtins.removeAttrs to remove GTK_IM_MODULE in home.sessionVariables:

{ config, ... }: {
  # ...
  home.sessionVariables =
    builtins.removeAttrs config.home.sessionVariables [ "GTK_IM_MODULE" ];
}

Oh, different error!

       error: infinite recursion encountered
       at /nix/store/73mxfyhvp1pdl4p600hij5548vajya1y-source/lib/modules.nix:821:9:
          820|     in warnDeprecation opt //
          821|       { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          822|         inherit (res.defsFinal') highestPrio;

How to unset GTK_IM_MODULE in home-manager configurtion?

The reason why you get infinite recursion is because you are using config.home.sessionVariables to define home.sessionVariables, which is obviously a circular reference.

As far as I know, the way that lists are concatenated using the default list type merge, there’s no way to omit an item from the list.

One potential solution would be to set it to an empty string, like:

home.sessionVariables.GTK_IM_MODULE = lib.mkForce "";

But it does make me wonder if that’s the problem. Is it possible that GTK_IM_MODULE is being set somewhere else? It’s possible to check what your configuration looks like. If you’re using flakes on NixOS, here’s an example of how that might look:

nix eval .#nixosConfigurations.$HOST.config.home-manager.users.$USER.home.sessionVariables

(If you’re not using flakes, or not using NixOS, this will not work as-is.)

You could check to see if it is set on the system level instead, if you are using NixOS:

nix eval .#nixosConfigurations.$HOST.config.environment.sessionVariables

Maybe it’s getting set on the system level due to this bit of Nixpkgs: nixpkgs/nixos/modules/i18n/input-method/fcitx5.nix at 8b07f3e22153529e8c9cb793ce94fcd96f9d03af · NixOS/nixpkgs · GitHub

If that’s the case, try setting config.i18n.inputMethod.fcitx5.waylandFrontend in your system configuration to true. That should take care of it.

If you’re not using NixOS, check your system’s configuration. There’s a whole lot of places environment variables could be being set.

Hope this helps!

1 Like

Are you using flakes or paths-based nix?

Thanks!
I found a home-manager pr fcitx5: add waylandFrontend option to not set env vars by utzuro · Pull Request #5431 · nix-community/home-manager · GitHub when this pr merged, we can use waylandFrontend option in home-manager, but system level fcitx5 configurtion is same as user level for me, so I moved my fcitx5 configurtion to system level to solve it.

{ mypkgs, pkgs, ... }: {
  i18n.inputMethod = {
    enable = true;
    type = "fcitx5";
    fcitx5 = {
      waylandFrontend = true;
      addons = with pkgs; [ fcitx5-chinese-addons mypkgs.fcitx5-theme ];
    };
  };
}