Fontconfig error: no writable cache directories

I am trying to convert the terminal font I use, FiraCode Nerd Font, into a .psf file using pkgs.RunCommand so I can set it as my TTY font. However, the derivations fails with the log only having the message Fontconfig error: no writable cache directories repeated a handful of times.

Below is what I have so far. Note that I’m using Stylix’s font settings to specify the font to use. I assume the first line of runCommand, the line with fc-match, is the one failing with an error.

  console.font =
      let
        font = config.stylix.fonts.monospace;
      in
      pkgs.runCommand "${font.package.name}.psf"
        {
          FONTCONFIG_FILE = pkgs.makeFontsConf { fontDirectories = [ font.package ]; };
        } ''
        # Use fontconfig to select the correct .ttf or .otf file based on name
        font=$(${pkgs.fontconfig}/bin/fc-match -v ${font.name} | grep "file:" | cut -d '"' -f 2)

        # Convert to bdf
        bdfFont=$(mktemp)
        ${pkgs.otf2bdf}/bin/otf2bdf -r 72 -p 16 -c C $font |
          sed -e "s/AVERAGE_WIDTH.*/AVERAGE_WIDTH 80/" > $bdfFont

        # Convert to psf
        ${pkgs.bdf2psf}/bin/bdf2psf $bdfFont ${pkgs.bdf2psf}/share/bdf2psf/standard.equivalents \
          ${pkgs.bdf2psf}/share/bdf2psf/linux.set+${pkgs.bdf2psf}/share/bdf2psf/useful.set} 256 $out
      '';

set export XDG_CACHE_HOME="$(mktemp -d)" at the beginning

1 Like

For posterity, I should note that although setting XDG_CACHE_HOME fixed the issues with the fc-match command, the rest of the code in runCommand from my original post does not work for unrelated reasons. Basically, I was using otf2bdf and bdf2psf incorrectly.

Eventually, I was able to get a working runCommand derivation, but rather than using otf2bdf and bdf2psf directly, I ended up used the mkttyfont package from this flake I happened to stumble upon while looking for alternative approaches: GitHub - Sigmanificient/ttf_to_tty: Converts TTF fonts to PSF, A TTY compatible font format.

Glad i could help you inderectly :smiley:

1 Like