Kitty has a nice way of showing Nerd Font characters, even if your current font hasn't been patched with them. Normally though, the recommended way of setting this up, is to go to the Nerd Fonts wiki, copy one column from the table of codepoints at the bottom of the page and then adjust the formatting to fit Kitty's options for the symbol_map configuration option.
Now, you have to remember to do this every time Nerd Fonts updates this table, which isn't really announced, so you'll just have to check manually once in a while. Honestly, this isn't ideal and after doing it again recently, I thought this shouldn't really be necessary at all; I'm running NixOS - surely there must be a way for this to be auto-generated?
My first thought was to parse the wiki page from within my Nix config, but considering that Nix is very much a functional language, the codepoints really should come from the input, not an external source that may be out of date (as the git log shows that the wiki has occasionally been). Instead, what if we could get the list of codepoints from the font file itself, format it to fit what Kitty expects and have it be a part of our configuration build?
Luckily, nixpkgs already contains a build of Nerd Fonts that only includes the symbols, so we have everything we need ready to go and fontconfig provides tools that can extract the codepoints.
So, with all the preamble out of the way, I present a Nerd Font configuration for Kitty that will always stay in sync with the version of Nerd Font that's actually installed:
programs.kitty = {
extraConfig = let
fontFile = "${pkgs.nerd-fonts.symbols-only}/share/fonts/truetype/NerdFonts/Symbols/SymbolsNerdFontMono-Regular.ttf";
codepoints = builtins.readFile (pkgs.runCommandLocal "get-nerdfont-codepoints" {} ''
${pkgs.fontconfig}/bin/fc-query --format='%{charset}' ${fontFile} \
| ${pkgs.gnused}/bin/sed 's/\b\([0-9a-f]\+\)\b/U+\U\1/g' \
| ${pkgs.coreutils}/bin/tr ' ' ',' \
> $out
'');
fontName = builtins.readFile (pkgs.runCommandLocal "get-nerdfont-name" {} ''
${pkgs.fontconfig}/bin/fc-query --format='%{fullname}' ${fontFile} > $out
'');
in ''
# Use additional nerd symbols
# https://sw.kovidgoyal.net/kitty/faq/#kitty-is-not-able-to-use-my-favorite-font
symbol_map ${codepoints} ${fontName}
'';
home.packages = [ pkgs.nerd-fonts.symbols-only ];
Another lovely example of Nix allowing me to stop worrying about yet another thing.
NOTE: I know this blog hasn't been updated in a while, and the last post mentions Arch Linux, but in the meantime Nix has slowly but surely taken over most of my tech, and it's been lovely.
