Customizing Gnome with Nix and Home Manager
In this post, I will share my experience and some snippets on customizing Gnome using Nix and Home Manager.
Remove utilities installed with Gnome
If you want to start with a minimal system, you can remove all the utilities installed alongside Gnome by default.
# configuration.nix
{ config, pkgs, lib, inputs, ... }:
{
# omitted for brevity
services.gnome.games.enable = false;
services.gnome.core-utilities.enable = false;
environment.gnome.excludePackages =
(with pkgs; [ gnome-tour gnome-shell-extensions ]);
programs.gnome-terminal.enable = false; # make sure you have another terminal program ready before you set this to false
}
And you can install specific utilities you want through home.packages
, so you can keep your system as lean as possible.
# gnome.nix
{ inputs, lib, config, pkgs, ... }: {
# for example, we want to have file manager and secret manager back
home.packages = with pkgs; [
nautilus
seahorse
];
}
Customizing Gnome settings with dconf
dconf
is the low level key-based configuration system used by Gnome, and we can interact with it with Home Manager and create a reproducible configuration of Gnome. To define dconf
settings with Home Manager, you can use dconf.settings
.
Personally I found that dconf-editor
very useful for exploring settings and finding keys in dconf
.
# gnome.nix
{ inputs, lib, config, pkgs, ... }: {
dconf.settings = {
"org/gnome/settings-daemon/plugins/power" = {
power-button-action = "interactive";
sleep-inactive-ac-timeout = 0;
sleep-inactive-ac-type = "nothing";
sleep-inactive-battery-type = "nothing";
};
"org/gnome/desktop/datetime" = { automatic-timezone = true; };
};
}
Customizing fonts settings in Gnome
To set system font families, you can set the value of keys org/gnome/desktop/interface/monospace-font-name
and org/gnome/desktop/interface/document-font-name
in dconf
through dconf.settings
. Make sure you have installed those font packages through home.packages
.
{ inputs, lib, config, pkgs, ... }: {
home.packages = with pkgs; [
(nerdfonts.override { fonts = [ "0xProto" ]; }) # avoid installing everything from nerdfonts
Inter
noto-fonts-cjk-sans
noto-fonts-cjk-serif
];
dconf.settings = {
"org/gnome/desktop/interface" = {
monospace-font-name = "0xProto Nerd Font Mono";
document-font-name = "Inter";
};
};
}
Customizing default font for applications
As Gnome respects configuration of fontconfig
, you can use fonts.fontconfig
for defining default font that will be used by applications(e.g. Firefox). You can define multiple fonts as default at fonts.fontconfig.defaultFonts.monospace
, fonts.fontconfig.defaultFonts.sansSerif
, fonts.fontconfig.defaultFonts.serif
and fonts.fontconfig.defaultFonts.emoji
.
Some applications respect gtk
configuration instead of fontconfig
, to set that we can define the font we want to use in gtk.font
.
{ inputs, lib, config, pkgs, ... }: {
# omitted for brevity
fonts.fontconfig = {
enable = true;
defaultFonts = {
monospace = [ "0xProto Nerd Font Mono" "Noto Sans Mono CJK HK" ];
serif = [ "Noto Serif CJK HK" ];
sansSerif = [ "Inter" "Noto Sans CJK HK" ];
};
};
gtk = {
enable = true;
font = {
name = "Inter";
package = pkgs.inter;
};
};
}
Enable font-hinting and font-antialiasing
If you have a good monitor, you might notice that by default the rendering of font in Gnome is blurry and not as crisp as other systems. To enable RGBA font antialiasing and full font hinting, you can set org/gnome/desktop/interface/font-hinting = "full"
and org/gnome/desktop/interface/font-antialiasing = "rgba"
through dconf.settings
.
{ inputs, lib, config, pkgs, ... }: {
dconf.settings = {
"org/gnome/desktop/interface" = {
font-hinting = "full";
font-antialiasing = "rgba";
};
};
}
Increase system font size
You can set the desired system font size alongside the name of font at org/gnome/desktop/interface/font-name
. The name of font should match org/gnome/desktop/interface/document-font-name
.
{ inputs, lib, config, pkgs, ... }: {
dconf.settings = {
"org/gnome/desktop/interface" = {
font-name = "Inter 11";
};
};
}
Removing suspend button from your quick setting menu
Since my CPU does not come with an integrated GPU, I cannot put my Nvidia GPU into offload mode during suspend. After waking it up, sometimes text on my screen with be broken. If I set NVreg_PreserveVideoMemoryAllocations=1
kernel parameter to preserve video memory after suspend, I can’t even enter suspend.
Therefore, I decided to disable suspend completely. After searching up documentation for a few hours, I finally figured out that can only be disabled through systemd
configuration. No Gnome extension needed.
# configuration.nix
{ config, pkgs, lib, inputs, ... }:
{
systemd.targets.sleep.enable = false;
systemd.targets.suspend.enable = false;
systemd.targets.hibernate.enable = false;
systemd.targets.hybrid-sleep.enable = false;
}
Disabling auto suspend
By default, Gnome will automatically put the computer into suspend after a while. To disable that behavior, you can set org/gnome/settings-daemon/plugins/power/sleep-inactive-ac-timeout = 0
in dconf
through dconf.settings
.
If you want to selectively enable auto suspend based on your power supply, org/gnome/settings-daemon/plugins/power/sleep-inactive-ac-type
and org/gnome/settings-daemon/plugins/power/sleep-inactive-battery-type
might be useful to you.
{ inputs, lib, config, pkgs, ... }: {
dconf.settings = {
"org/gnome/settings-daemon/plugins/power" = {
power-button-action = "interactive";
sleep-inactive-ac-timeout = 0;
sleep-inactive-ac-type = "nothing";
sleep-inactive-battery-type = "nothing";
};
};
}
Customizing mouse speed and profile
If you want to game on Gnome, mouse acceleration is definitely something you want to disable. To tweak mouse speed and profile, you can set org/gnome/desktop/peripherals/mouse/accel-profile
and org/gnome/desktop/peripherals/mouse/speed
in dconf
through dconf.settings
.
{ inputs, lib, config, pkgs, ... }: {
dconf.settings = {
"org/gnome/desktop/peripherals/mouse" = {
accel-profile = "flat";
speed = 0.5;
};
};
}
Customizing wallpapers
If you want to set your own wallpapers and change them based on light and dark mode, you can set org/gnome/desktop/background/picture-uri
and org/gnome/desktop/background/picture-uri-dark
in dconf
through dconf.settings
.
{ inputs, lib, config, pkgs, ... }: {
dconf.settings = {
"org/gnome/desktop/background" = {
picture-uri =
"file:///home/foobar/whereever-you-store-your-wallpapers/example.jpg";
picture-uri-dark =
"file:///home/foobar/whereever-you-store-your-wallpapers/example-dark.jpg";
};
};
}