Configuring system-wide gtk settings

I’m gradually switching from Gnome to i3, and figuring out how to translate some settings that Gnome was managing (e.g. via gsettings or the gnome tweak tool) into system-wide config files.

For example, I like using emacs-like keybindings in gtk apps (e.g. chromium), and had been running

gsettings set org.gnome.desktop.interface gtk-key-theme "Emacs"

to configure this. According to the arch wiki, gtk apps will look for system-wide settings in:

/etc/gtk-2.0/gtkrc
/etc/gtk-3.0/settings.ini

I created those files using environment.etc in my nixos config, but my settings weren’t picked up. I finally found an approach that works, and incorporated it into my config.

environment.extraInit = ''
  export XDG_CONFIG_DIRS="/etc/xdg:$XDG_CONFIG_DIRS"
'';

environment.etc."xdg/gtk-2.0/gtkrc".source = ''
  gtk-key-theme-name = "Emacs"
'';

environment.etc."xdg/gtk-3.0/settings.ini".source = ''
  [Settings]
  gtk-key-theme-name = Emacs
'';

This works, but is there a cleaner way?

1 Like

Relevant PR: Theming options for Gtk and Qt · Pull Request #71079 · NixOS/nixpkgs · GitHub

Looking at that PR, I guess the only thing I could change would be to leverage

environment.variables.XDG_DATA_DIRS

rather than doing it in environment.extraInit