Setting TTY fonts

I have a HiDPI screen and would like to select a larger TTY font.

Here are the relevant settings in /etc/nixos/configuration.nix:

{
  # ...
  i18n.defaultLocale = "en_US.UTF-8";
  console = {
    earlySetup = true;
    font = "ter-v32n";
    packages = with pkgs; [ terminus_font ];
    keyMap = "us";
  };
  # ...
}

I looked at Settings for increasing text-mode font size but didn’t really find a solution there.

I’ve also tried “Lat2-Terminus32” which doesn’t seem to have an effect.

I’ve also tried directly setting the font from the TTY console setfont ter-v32n or setfont Lat2-Terminus32 only to get reports that the fonts don’t exist. Even in a nix-shell -p terminus_font, I get this error:

$ nix-shell -p terminus_font
[nix-shell]$ setfont ter-v32n
setfont: ERROR setfont.c:421 kfont_load_font: Unable to find file: ter-v32n

How can I:

  1. see what console fonts I have installed
  2. install and select a font that’s large enough for a HiDPI screen (DPI = 323)
2 Likes

Following a message on nix-dev, I updated /etc/nixos/configuration.nix as follows:

{
  # ...
  i18n.defaultLocale = "en_US.UTF-8";
  console = {
    earlySetup = true;
    font = "${pkgs.terminus_font}/share/consolefonts/ter-132n.psf.gz";
    packages = with pkgs; [ terminus_font ];
    keyMap = "us";
  };
  # ...
}

I could find the font at that path and use it with setfont, but it was still failing to be picked up during boot. It turns out that was a known issue (NixPkgs #124170) that has been resolved.

A quick sudo nix-channel --update and sudo nixos-rebuild switch, the font is now being picked up during boot. Hooray!

6 Likes

I am having the same problem. With the setup above, after I run nixos-rebuild switch, I can go to a TTY and the font is set properly. However, after a boot, the font is back to the default small font. A quick nixos-rebuild fixes the situation temporarily until the next reboot.

Is this still a bug related to NixPkgs #124170 27? If so, it deson’t seem to be resolved.

If you have problem with fonts,
if this are built-in fonts, make sure the name is correct by going into /etc/kbd/consolefonts, and doing

ls -1 /etc/kbd/consolefonts |sort |less

and verifying

setfont $yourfontname

is loading the font correcty. If it does, you can apply it into configuration.nix:

console.font="$yourfontname"

If font is not built-in, you need to link it in configuration.nix (here for terminus font):

console.packages=[ pkgs.terminus_font ];
console.font="${pkgs.terminus_font}/share/consolefonts/ter-i22b.psf.gz";

Then you need to check if font is loaded by checking console service after the reboot:

systemctl status systemd-vconsole-setup

If the service failed, then there was a problem with file name or problem with font decompressor.

If the service has not failed, but font is still not loaded, then the issue is with a race condition between font and videodriver: fontconfig will load the font bitmap into video memory. Reloading a videodriver will clean the memory and cause fontconfig reset. Currently the video driver is stored in kernel - it can either be built-in or stored as module to be loaded on demand. This driver stays dormant, unless explicitly loaded by user or loaded by xorg/wayland. The problem is that Xorg/Wayland start late on the list - thus the font gets applied near start and then driver load causes the changes to be reset.

First read current kernel configuration to find out how your videodriver is inserted into kernel (use “/searchstring” to lookup (CASE sensitive) and “n” to find next match, arrows+home to navigate, q to quit):

zcat /proc/config.gz |less

or feed it into grep:

zcat /proc/config.gz | grep -i $driver

“y” means its built-in, “m” built into initramfs as module and “n” not built.

Now, you have a videodriver in xorg or wayland (here for example amdgpu):

services.xserver.enable=true;
services.xserver.videoDrivers=["amdgpu"];

and this driver (amdgpu) is built as module (“m”) in kernel, then you need to add it to kernel to prevent reloading during start of Xorg, so its loaded straight away, before vconsole setup does font changes.

boot.initrd.kernelModules=["amdgpu"];

When xorg/wayland start, there will be no driver reload.

Another solution would be to force-set the font twice - on systemd start and after xorg/wayland started.