Nixos options to configure Gnome Keyboard Shortcuts

I’ve been setting up a laptop with NixOS and I’m most familiar with Gnome, so I’ve been using that. I’ve noticed that the Ctrl-Alt-T shortcut that I am used to for launching the terminal doesn’t work under NixOS. I can configure it manually in gnome-control-center, but I would prefer to configure it declaratively. I haven’t been able to find an option to do this in either NixOS or Home-Manager, is there a way to accomplish this in my nix configuration that I am missing?

gnome-settings-daemon is configured through GSettings, ordinarily stored in dconf database.

Usually, the best way to set it declaratively is to set it in the GUI and then look in dconf-editor or the output of dconf dump to see what changed. In my case it were these settings:

[org/gnome/settings-daemon/plugins/media-keys]
custom-keybindings=['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']

[org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0]
binding='<Super>t'
command='gnome-terminal'
name='Open terminal'

You can then set the default values in configuration.nix:

{
  services.xserver.desktopManager.gnome3 = {
    extraGSettingsOverridePackages = with pkgs; [ gnome3.gnome-settings-daemon ];
    extraGSettingsOverrides = ''
      [org.gnome.settings-daemon.plugins.media-keys]
      custom-keybindings=['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']


      [org.gnome.settings-daemon.plugins.media-keys.custom-keybindings.custom0]
      binding='<Super>t'
      command='gnome-terminal'
      name='Open terminal'
    '';
  };
}

Note you will have to reset them using dconf reset for the defaults to be picked up.

But that might not work since /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ is a relocatable schema.

home-manager has a dconf.settings option that should work, though.

Hi, I haven’t been able to try this today unfortunately, but wanted to thank you for your reply. Putting me on the track of looking for GSettings and dconf options is a huge help, and is something that would have taken me hours to figure out on my own.

Thank You!

Just to follow up on this, I did get it working eventually. I had a couple false starts, so I think it’s useful to post this for anyone else trying to do this, and to see if someone suggests something I could do better.

First, to go over my solution:

I adding the following to my Home-manager config:

dconf.settings = {
  "org/gnome/settings-daemon/plugins/media-keys" = {
    custom-keybindings = [
      "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/"
    ];
  };
};

"org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0" = {
  binding = "<Primary><Alt>t";
  command = "alacritty";
  name = "open-terminal";
};

I should note, that the leading and trailing / in custom-keybindings was critical. Originally I didn’t have them, and without that I got into a state where gnome would crash as soon as I logged in. This wasn’t something that went away by booting a previous generation, and the only way I recovered was logging in as root, and restoring ~/.config/dconf/user from a previous filesystem snapshot, git stashing my config changes and doing a nixos-rebuild

Per this, I also had to add the below to get Home-manager to actually apply my dconf changes.

services.dbus.packages = [ pkgs.gnome3.dconf ]; 

Other than all that, it was easy… :smile: