How to use fcitx in a app installed with nix-env on a non-nixos system?

On NixOS, fcitx can be easily configured by editing /etc/nixos/configuration.nix, according to the NixOS manual.

  i18n.inputMethod = {
    enabled = "fcitx";
  };

It works as expected (i.e. I was able to type chinese characters with Fcitx) and I enjoy my time with NixOS.

And now I installed Nix on another PC with an Arch Linux system:

sh <(curl https://nixos.org/nix/install) --daemon

I don’t have a Fcitx installation before I install Nix. And I tried to install Chrome and Fcitx by creating a .config/nixpkgs/config.nix file in my home directory, according to the NIxpkgs manual:

{
  allowUnfree = true;
  packageOverrides = pkgs: with pkgs; {
    myPackages = pkgs.buildEnv {
      name = "my-packages";
      paths = [
        google-chrome
        fcitx-configtool
        fcitx
      ];
    };
  };
}

and run this as a non-root user:

nix-env -iA nixpkgs.myPackages

And I edit the /etc/environment file:

GTK_IM_MODULE=fcitx
QT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx

Then I reboot. Both apps are installed as expected. I launch fcitx, and it works on the apps which I installed using the system’s package mananger (i.e. pacman). But when I try to launch Chrome which I installed with nix-env, fcitx doesn’t work (i.e. Fcitx is running but I cannot type in any chinese characters).

Later I tried to remove fcitx from config.nix and re-run nix-env -iA nixpkgs.myPackages and install fcitx using pacman then reboot, the result is the same.

I am not familiar with Nix and can anyone offer me some help on that?

I guess user-scoped (non-root installed) software brought by Nix would not respect /etc/environment? Just a thought

1 Like

The problem was solved by replacing Arch with NixOS:sweat_smile:

However, other workarounds are welcomed to post here for those who cannot change their OS… :rofl: