Keyboard layout not working as expected in KDE Plasma

I’m having issues with keyboard layout on a physical machine. I have a Swedish Microsoft Natural Ergonomic Keyboard 4000.

I’m using settings:

  services.xserver = {
    autoRepeatDelay = 100;
    autoRepeatInterval = 10;
    layout = "se";
    xkbVariant = "nodeadkeys";
    #xkbOptions = "eurosign:e";
    xkbModel = "microsoft4000";

  console.useXkbConfig = true;

and I can see the settings are there:

localectl status
   System Locale: LANG=en_US.UTF-8
       VC Keymap: /nix/store/nq288vykaaxxyj4dc6wikich9w7p2sdy-xkb-console-keymap
      X11 Layout: se
       X11 Model: microsoft4000
     X11 Variant: mac
     X11 Options: terminate:ctrl_alt_bksp

But I’m definitely not getting a working “se” layout for my keyboard, keyboard still works like us keyboard. Or actually, switching out of KDE and running a shell I get weird characters for my swedish åäö:

Do I have to do it all custom layout to get a keyboard like this working?

I’ve read the docs at Keyboard Layout Customization - NixOS Wiki and I really got the feeling that just setting an “se” layout should be enough to get a reasonable swedish layout with the åäö’s I want…? Also I thought console.useXkbConfig = true would mean that these settings are used for other console tty’s as well?

I think (for the console) what you need is a font which supports Swedish characters (not sure which font supports it), but you can use following variable to set it once you find:


Couldn’t understand the issue with KDE, but as far as I remember, once you set it on plasma’s keyboard settings once, it should be pretty sticky.

1 Like

need is a font which supports Swedish characters

Thanks! Yeah, that was it for the console. I still have issues there though, because I’m on HiDPI and I had:

 console.font = lib.mkDefault "${pkgs.terminus_font}/share/consolefonts/ter-u28n.psf.gz";

to scale the fonts. I guess not all fonts can be scaled like that? Need to be bitmapped ones, right? Got atlassian-mono, my preferred dev font, working for SE but got tiny. Anyone have tips on a scalable font like that with SE support? Or can you scale a vector based font for the terminal, no?

As for my other issue, I was probably naive thinking that those xserver settings would be picked up by KDE ? Got the feeling that would be the case with services.xserver.layout for instance, but simply isn’t working. I guess I need KDE specific settings and if I want to be pure nix, I’d need to start learning about makeWrapper then?

Maybe this is a question of timing. I probably started KDE Plasma before doing those xserver nix settings and therefore files where persisted under ~/.config? Now I did the settings with clicketiclick (ugh) within Plasma and subsequently found the settings file under:

cat /.config/kxkbrc


Could the issue be that since I started KDE before doing the nix settings, I might have had a file there already with the default us layout that wouldn’t be replaced?

I really would like to have as little external state as possible and not litter my home folder with mutable config (hey, that’s why I’m here in nix land to begin with)

I guess some software is harder than others and KDE seem to have generated a lot under my ~/.config folder :.(

Seems so. I nuked /.config/kxkbrc and restarted KDE. Then I got a new file with the settings from my xserver nix settings except that the model didn’t come through:

$ diff ~/.config/kxkbrc ~/.config/kxkbrc_old
< Model=
> Model=microsoft4000

even though:

$ cat ~/nixfiles/machines/marfa/keyboard.nix
{ pkgs, … }:

  services.xserver = {
    autoRepeatDelay = 200;
    autoRepeatInterval = 20;
    layout = "se";
    xkbVariant = "mac";
    xkbModel = "microsoft4000";

  console.useXkbConfig = true;

Yep, that’s why I wasn’t sure, because I never tried different-locale supporting font on TTY. But here is a helpful thread, maybe it’ll work.

And yeah, KDE is pretty insisting on its configs. I’ve tried to declare the config files via nix but only had more issues afterwards with different cache folders etc… You might want to manually set some stuff, but as far as I can see it’s mostly OK now except the model.