{ config, pkgs, ... }:

let
  configFile = "home-files/.config/fontconfig/conf.d/10-hm-fonts.conf";
in
{
  fonts.fontconfig.enable = true;

  nmt.script = ''
    assertFileExists ${configFile}
    assertFileContent ${configFile} ${pkgs.writeText "fonts.conf" ''
      <?xml version='1.0'?>

      <!-- Generated by Home Manager. -->

      <!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'>
      <fontconfig>
      <description>Add fonts in the Nix user profile</description>

      <include ignore_missing="yes">${config.home.path}/etc/fonts/conf.d</include>
      <include ignore_missing="yes">${config.home.path}/etc/fonts/fonts.conf</include>

      <dir>${config.home.path}/lib/X11/fonts</dir>
      <dir>${config.home.path}/share/fonts</dir>
      <dir>${config.home.profileDirectory}/lib/X11/fonts</dir>
      <dir>${config.home.profileDirectory}/share/fonts</dir>

      <cachedir>${config.home.path}/lib/fontconfig/cache</cachedir>

      </fontconfig>
    ''}
  '';
}
