The keyboard layout does not change after modifying config

When I run setxkbmap -layout cz -variant coder the layout changes to the correct one.

I tried to change to this layout permanently by adding the following to the configuration.nix:

  # Enable the X11 windowing system.
  services.xserver = {
      enable = true;
      layout = "cz";
      xkbVariant = "coder";
      displayManager.gdm.enable = true;
      desktopManager.gnome.enable = true;  

But after every reboot, it switches back to the US layout. Any ideas?

It’s seems like you forgot to run nixos-rebuild switch since writing your config file doesn’t apply the changes automatically

I did sudo nixos-rebuild switch. There is still the old keyboard layout.

I have the same issue when I generate a custom iso. When I boot the layout is always set to “us” no matter what I put in the config I generate the iso from. The other settings of the config are transfered correctly. Did you find a solution?

No, I did not find a solution.

Is the relevant line in the X11 config files in your system?

I’ve had an similar issue when using i3 with an wireless keyboard, every time the keyboard reconnected the layout was reset to default, this wasn’t a problem with Mate or Gnome since those seem to apply the correct layout automatically but for i3 to work this way I had to set the layout using home-manager aswell.

I am not sure if I understand your question. It is in a file, that is imported by the configuration.nix

I think the question is, if you ignore your nixos config, and just look at the files that X11 itself reads, is the configuration set?

Looking at the xserver module, that would be in /etc/X11/xorg.conf.d/00-keyboard.conf.

I suspect that the answer will simply be “yes”, though. There’s even validation for this, it’d be very odd if this wasn’t true.

My hunch is that gdm/GNOME have their own keyboard layout handling, since GNOME is very much designed for imperative system configuration, and carries its own configuration interfaces. It’s probably overriding what you’re doing. Have you tried starting an xserver without ever launching anything GNOME-related?

If my hunch is correct and you can verify that, we might be able to tame GNOME from there :slight_smile:

1 Like

The config is indeed correct. I was unable to start x server by itself. If I run startx, I am dropped into an environment where I can see several windows, but can not interact in any way and have to restart the computer.

Comment out any references to gdm or gnome for the moment, and then set services.xserver.displayManager.startx.enable for now. Also add xterm to environment.systemPackages for the time being.

Then create a ~/.xinitrc file with these contents:

exec xterm

If you use startx on a tty after that (preferably after a reboot, just to rule out any imperative interference), you should just get an xterm window, which should be enough to test if your layout is being respected. Just hover with your cursor above the window while you’re typing :slight_smile:

Indeed, see, for example, Problem with `xkbOptions` - it doesn't seem to take effect

1 Like

I can confirm the selected layout works with pure x-server. Maybe I should report the issue to Gnome then?

They shouldn’t care - you’re using gnome in an unintended way (by them), and will likely be told to use the imperative config instead, or get the NixOS maintainers to help support your use case :wink:

There are workarounds, check the discussion @jtojnar linked. There’s a potential proper fix on the horizon if we ever fix nixos/dconf: Allow creating custom databases · Issue #54150 · NixOS/nixpkgs · GitHub

1 Like