{
  config,
  pkgs,
  lib,
  ...
}:
let
  cfg = config.alqueva.system.fonts;
  inherit (lib.options) mkOption mkEnableOption;
  inherit (lib.types)
    listOf
    package
    str
    submodule
    ;
  fontSubmodule =
    letterform: defaultNames: defaultPackages:
    submodule {
      options = {
        names = mkOption {
          description = "Default system fonts used for the ${letterform} font-families.";
          default = defaultNames;
          type = listOf str;
        };
        packages = mkOption {
          description = "Packages for the ${letterform} font-families.";
          default = defaultPackages;
          type = listOf package;
        };
      };
    };
in
{
  options.alqueva.system.fonts = {
    enable = mkEnableOption "" // {
      description = "Whether you want to use this fonts module.";
    };
    extraFonts = mkOption {
      description = "Extra font packages you may need.";
      type = listOf package;
      default = [ ];
    };
    fonts =
      builtins.mapAttrs
        (
          n: v:
          mkOption {
            default = { };
            description = "Options for ${n} font-families";
            type = fontSubmodule n v.defaultNames v.defaultPackages;
          }
        )
        {
          sansSerif = {
            defaultNames = [ "Roboto" ];
            defaultPackages = [ pkgs.roboto ];
          };
          monospace = {
            defaultNames = [ "Roboto Mono" ];
            defaultPackages = [ pkgs.roboto-mono ];
          };
          serif = {
            defaultNames = [ "Roboto Serif" ];
            defaultPackages = [ pkgs.roboto-serif ];
          };
          emoji = {
            defaultNames = [ "Noto Color Emoji" ];
            defaultPackages = [ pkgs.noto-fonts-color-emoji ];
          };
        };
  };
  config = lib.mkIf cfg.enable {
    fonts = {
      packages = builtins.concatMap (v: v.packages) (builtins.attrValues cfg.fonts) ++ cfg.extraFonts;
      fontconfig = {
        enable = true;
        defaultFonts = builtins.mapAttrs (_: v: v.names) cfg.fonts;
      };
    };
  };
}
