refactor: refactor fonts option
This commit is contained in:
parent
cb376aa64b
commit
0e93cee685
6 changed files with 134 additions and 125 deletions
|
@ -6,85 +6,75 @@
|
|||
}:
|
||||
let
|
||||
cfg = config.alqueva.system.fonts;
|
||||
inherit (lib) types mkOption;
|
||||
mkStringsOption =
|
||||
default: letterform:
|
||||
mkOption {
|
||||
type = types.listOf types.str;
|
||||
inherit default;
|
||||
description = "The default fonts for ${letterform}.";
|
||||
};
|
||||
mkPackagesOption =
|
||||
default: letterform:
|
||||
mkOption {
|
||||
type = types.listOf types.package;
|
||||
inherit default;
|
||||
description = "The packages you want to use for your ${letterform} 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 = lib.mkEnableOption "" // {
|
||||
enable = mkEnableOption "" // {
|
||||
description = "Whether you want to use this fonts module.";
|
||||
};
|
||||
packages =
|
||||
{
|
||||
extra = mkOption {
|
||||
type = types.listOf types.package;
|
||||
default = [ ];
|
||||
description = "Extra font packages you want installed.";
|
||||
};
|
||||
}
|
||||
// builtins.mapAttrs (_n: v: mkPackagesOption v.default v.letterform) {
|
||||
sansSerif = {
|
||||
default = [ pkgs.roboto ];
|
||||
letterform = "sans-serif";
|
||||
};
|
||||
monospace = {
|
||||
default = [ pkgs.roboto-mono ];
|
||||
letterform = "monospace";
|
||||
};
|
||||
serif = {
|
||||
default = [ pkgs.roboto-serif ];
|
||||
letterform = "serif";
|
||||
};
|
||||
emoji = {
|
||||
default = [ pkgs.noto-fonts-color-emoji ];
|
||||
letterform = "emoji";
|
||||
};
|
||||
};
|
||||
names = builtins.mapAttrs (_n: v: mkStringsOption v.default v.letterform) {
|
||||
sansSerif = {
|
||||
default = [ "Roboto" ];
|
||||
letterform = "sans-serif";
|
||||
};
|
||||
monospace = {
|
||||
default = [ "Roboto Mono" ];
|
||||
letterform = "monospace";
|
||||
};
|
||||
serif = {
|
||||
default = [ "Roboto Serif" ];
|
||||
letterform = "serif";
|
||||
};
|
||||
emoji = {
|
||||
default = [ "Noto Color Emoji" ];
|
||||
letterform = "emoji";
|
||||
};
|
||||
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.concatLists (builtins.attrValues cfg.packages);
|
||||
packages = builtins.concatMap (v: v.packages) (builtins.attrValues cfg.fonts);
|
||||
fontconfig = {
|
||||
defaultFonts = {
|
||||
inherit (cfg.names)
|
||||
sansSerif
|
||||
monospace
|
||||
serif
|
||||
emoji
|
||||
;
|
||||
};
|
||||
enable = true;
|
||||
defaultFonts = builtins.mapAttrs (_: v: v.names) cfg.fonts;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue