Setting caps lock as ctrl not working

I have this in my configuration.nix.

console = {
  font = "Lat2-Terminus16";  
  useXkbConfig = true;
};
services.xserver = {
  enable = true;
  
  layout = "us";
  xkbVariant = "altgr-intl";
  xkbOptions = "ctrl:swapcaps";
  
  displayManager.gdm.enable = true;
  desktopManager.gnome3.enable = true;
  
  libinput.enable = true;
};

I ran sudo nixos-rebuild switch and reboot my machine.

When I booted back up, I could see this.

$ localectl 
   System Locale: LANG=en_US.UTF-8
     VC Keymap: /nix/store/hcbsm4j5zny0d53xjcxax6jwl73s0ni0-xkb-console-keymap
     X11 Layout: us
     X11 Model: pc104
     X11 Variant: altgr-intl
     X11 Options: ctrl:swapcaps

However, my caps lock is still caps lock. (xkb variant seems unaffected as well.)

Is there some other bit of configuration I’m missing?

nixos-version: 20.09.3436.6be212cce73 (Nightingale)

No difference if XDG_SESSION_TYPE is wayland or x11.
However, I can manually set things with setxkbmap after logging in with a x11.

GNOME Settings daemon only uses xkb config for initial setting of input settings. What is worse, those settings cannot be easily updated in NixOS configuration (nixos/dconf: Allow creating custom databases · Issue #54150 · NixOS/nixpkgs · GitHub), you will have to reset corresponding dconf keys (and maybe re-login) for the config to be read. See also Problem with `xkbOptions` - it doesn't seem to take effect

1 Like

Wow. Amazing! I ran

gsettings reset org.gnome.desktop.input-sources xkb-options
gsettings reset org.gnome.desktop.input-sources sources

and rebooted. Works under both x11 and wayland XDG_SESSION_TYPEs.

Thanks! :bowing_man:

2 Likes

Is there a way to automatically run

gsettings reset org.gnome.desktop.input-sources xkb-options
gsettings reset org.gnome.desktop.input-sources sources

whenever I run nixos-rebuild switch? I’m new to NixOS, not sure if there is some post rebuild hook or something I could use. It would be nice if I didn’t have to remember to run those commands manually next time I change those values.

Maybe it would be possible to create systemd user service. But not sure how exactly to configure it to be triggered on activation.

Alternative might be taking

but instead of extraGSettingsOverrides, which only overrides default values again, writing the requested values directly to dconf database using the same method as in

https://github.com/NixOS/nixpkgs/pull/63790

https://search.nixos.org/options?channel=20.09&show=system.activationScripts&from=0&size=50&sort=relevance&query=activationScripts

1 Like

I would not expect that to have access to user’s D-Bus session bus since nixos-rebuild switch is usually run under sudo.

1 Like

I wonder if dconf could be used for this?

Here is a snippet from the home-manager config of one of our art installations that stops the machine from going to sleep or enabling a screensaver.

  # GNOME configuration (e.g. disable sleep, blank display, etc).
  dconf = {
    enable = true;
    settings = {
      # Disable automatic suspension when idle.
      "org/gnome/settings-daemon/plugins/power" = {
        "sleep-inactive-ac-type" = "nothing";
      };
      # Disable screen saver.
      "org/gnome/desktop/session" = {
        "idle-delay" = (lib.hm.gvariant.mkUint32 0);
      };
    };
  };

Yes. But NixOS currently does not have dconf module, see nixos/dconf: Allow creating custom databases · Issue #54150 · NixOS/nixpkgs · GitHub.

using the same method as in: add autoSuspend option (PR)
Hm. Did that PR end up working?

I found this: Disabling gdm.autoSuspend still auto suspends · Issue #100390 · NixOS/nixpkgs · GitHub

It worked last time I tested. I suspect OP forgot to set the option in the user session as worldofpeace says.

1 Like

Comes from https://discourse.nixos.org/t/does-services-xserver-xkbdir-not-work-for-gnome-gdm-on-wayland/28383

I customize keymap by services.xserver.xkbDir = ./xkb, and I find for gnome X11, it can work (services.xserver.displayManager.gdm.wayland = false) but for gnome wayland it cannot work. I try

gsettings reset org.gnome.desktop.input-sources xkb-options
gsettings reset org.gnome.desktop.input-sources sources

But it cannot work for me.

The following is localetctl:

$ localectl
System Locale: LANG=en_US.UTF-8
    VC Keymap: /nix/store/j3r9if1sn1i73a1j4ikv1m65vsc77na1-xkb-console-keymap
   X11 Layout: us
    X11 Model: pc104
  X11 Options: terminate:ctrl_alt_bksp