[9sep2024] fontconfig+nix: getting fonts via nix
Table of Contents
1. Problem
Setting up new desktop PC running windows 11 + WSL2 + nix.
Invoking emacs from xo-nix2 flake (https://github.com/rconybea/xo-nix2/flake.nix) reveals
that emacs doesn't get inconsolata from nix as I thought – .emacs
complains that Inconsolata
isn't available, and reverts to some non-fixed-width font (probably Ubuntu Sans or something).
Previous PC not immediately accessible (it's in NYC, and I'm writing this from Chicago); but from memory had installed an ubuntu package to make this work.
Since I couldn't quickly find ubuntu package, looked into incorporating nixpkgs-provided fonts into my WSL2/ubuntu account setup.
2. Strategy
Want to use something like
nix-env -i inconsolata-lgc
to make a font available. This command populates ~/.nix-profile/share/fonts
,
but need something more to get ubuntu to see them.
3. Investigation
Arch linux wiki https://wiki.archlinux.org/title/Font_configuration has good writeup on fonts.
4. Solution
4.1. Add fontconfig dir
Need to provide .config/fontconfig/fonts.conf
:
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd"> <!-- After changing this file: $ fc-cache -fv List available fonts: $ fc-list --> <fontconfig> <!-- also pull in any fonts provided via nix package manager --> <dir>~/.nix-profile/share/fonts</dir> <dir>~/.local/share/fonts</dir> </fontconfig>
fontconfig
already knows to look in this location
4.2. Tweak .emacs
With this change, add to ~/.emacs
:
(set-frame-font "Inconsolata LGC 9" nil t)
That's all!