Keyboard layout with GNOME

I am trying to setup the EurKey keyboard layout. However it always defaults back to “us”. My current idea is that GNOME changes the layout.

System info:

nixos-version: 22.05.3201.bcc68429a50 (Quokka)
gnome-version: 42.2

In my configuration.nix I added this:

# Set layout for X11
services.xserver.layout = "eu";

# Set layout in GNOME 
  services.xserver.desktopManager.gnome = { 
    extraGSettingsOverrides = '' 
      [org.gnome.desktop.input-sources] 
      sources='[('xkb', 'eu')]' 
    ''; 
    extraGSettingsOverridePackages = [ 
      pkgs.gsettings-desktop-schemas 
    ]; 
  };

I also tried

sources='[]'

After reboot I get the following:

➜ setxkbmap -query       
rules:      evdev
model:      pc105
layout:     us

but running “setxkbmap eu” does only change the behavior for some applications. Terminal and GNOME text editor still have the “us” keyboard while Firefox has the “eu” keyboard.

However GNOME settings shows correct keyboard
Screenshot from 2022-09-25 14-55-22

➜ gsettings get org.gnome.desktop.input-sources sources 
[('xkb', 'eu')]

Can someone who is using GNOME please share his/her keyboard configuration? Thank you.

You should see the following error when building your system:

nixos-gsettings-desktop-schemas> Error parsing key “sources” in schema “org.gnome.desktop.input-sources” as specified in override file “/nix/store/lrq600a2qamr03nq7wg5jl720dl0imqq-nixos-gsettings-desktop-schemas/share/gsettings-schemas/nixos-gsettings-overrides/glib-2.0/schemas/nixos-defaults.gschema.override”: 0-4:can not parse as value of type 'a(ss)'. Ignoring override for this key.

I guess we should make it fail more loudly.

The issue is that you have extra quotes around the array:

It should be just sources=[('xkb', 'eu')].

Also note that the extraGSettingsOverrides mechanism only allows you to set the default value so in order for it to apply, you will need to run gsettings reset org.gnome.desktop.input-sources sources and re-log in.

I tried this and and get the following results. EurKey layout still wont work.

➜ setxkbmap -query
rules:      evdev
model:      pc105
layout:     us
➜ gsettings get org.gnome.desktop.input-sources sources
[('xkb', 'eu')] 

I also tried setting the option directly with dconf.settings in my home.nix.

dconf.settings = {
  "org/gnome/desktop/input-sources" = {
    sources = [ (mkTuple [ "xkb" "eu" ]) ];
    xkb-options = [ ];
  };
};

I would expect the home-manager config to work, though there might be some state weirdness happening from previous stuff you tried. Try adding an extra language sources = [ (mkTuple [ "xkb" "gb" ]) (mkTuple [ "xkb" "eu" ]) ], activating that home-manager config, and then activating the config with just eu layout. Hopefully, that should make gnome-settings-daemon to notice the change. Or just re-log in.

sources = [ (mkTuple [ "xkb" "gb" ]) ] works but "eu" does not :upside_down_face:

Edit: I also depends on the app. Firefox works after setxkbmap eu but everything GNOME does not.

Hmm, maybe the eu map is somehow wonky then :woman_shrugging:

I would avoid using setxkbmap in GNOME since it might go behind gnome-settings-daemon’s back and result in an inconsistent state between the daemon and settings causing a weird behaviour.

Opened GNOME/Cinnamon/Pantheon: Clean up GSettings overrides and make strict by jtojnar · Pull Request #192969 · NixOS/nixpkgs · GitHub.

I finally go it to work as following:

dconf.settings = {
    "org/gnome/desktop/input-sources" = {
      show-all-sources = true;
      sources = [ (mkTuple [ "xkb" "eu" ]) (mkTuple [ "xkb" "us+altgr-intl" ]) ];
      xkb-options = [ "terminate:ctrl_alt_bksp" ];
    };
};

Keyboard can be changed in the top right corner.