mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
fontconfig: add fonts.fontconfig.extraConfigFiles option (#7754)
Co-authored-by: Tim Keller <tjk@tjkeller.xyz> Co-authored-by: Benedikt M. Rips <benedikt.rips@gmail.com>
This commit is contained in:
parent
75f97fcbe3
commit
fad8e3033e
4 changed files with 161 additions and 23 deletions
|
|
@ -15,6 +15,39 @@ let
|
||||||
|
|
||||||
profileDirectory = config.home.profileDirectory;
|
profileDirectory = config.home.profileDirectory;
|
||||||
|
|
||||||
|
fontConfigFileType = lib.types.submodule (
|
||||||
|
{ name, ... }:
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
enable = lib.mkEnableOption "Whether this font config file should be generated.";
|
||||||
|
text = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.lines;
|
||||||
|
default = null;
|
||||||
|
description = "Verbatim contents of the config file. If this option is null then the 'source' option must be set.";
|
||||||
|
};
|
||||||
|
source = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.path;
|
||||||
|
default = null;
|
||||||
|
description = "Config file to source. Alternatively, use the 'text' option instead.";
|
||||||
|
};
|
||||||
|
label = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = name;
|
||||||
|
defaultText = "<name>";
|
||||||
|
description = "Label to use for the name of the config file.";
|
||||||
|
};
|
||||||
|
priority = lib.mkOption {
|
||||||
|
type = lib.types.ints.between 0 99;
|
||||||
|
default = 90;
|
||||||
|
description = ''
|
||||||
|
Determines the order in which configs are loaded.
|
||||||
|
Must be a value within the range of 0-99, where priority 0 is the highest priority and 99 is the lowest.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
meta.maintainers = with lib.maintainers; [
|
meta.maintainers = with lib.maintainers; [
|
||||||
|
|
@ -125,6 +158,44 @@ in
|
||||||
example = "rgb";
|
example = "rgb";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
configFile = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf fontConfigFileType;
|
||||||
|
default = { };
|
||||||
|
description = ''
|
||||||
|
Extra font config files that will be added to `~/.config/fontconfig/conf.d/`.
|
||||||
|
Files are named like `fontconfig/conf.d/{priority}-{label}.conf`.
|
||||||
|
'';
|
||||||
|
example = {
|
||||||
|
tamzen = {
|
||||||
|
enable = true;
|
||||||
|
label = "tamzen-disable-antialiasing";
|
||||||
|
text = ''
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
|
||||||
|
|
||||||
|
<fontconfig>
|
||||||
|
<description>Disable anti-aliasing for Tamzen since it is a bitmap font</description>
|
||||||
|
<match target="pattern">
|
||||||
|
<test name="family" compare="eq" qual="any">
|
||||||
|
<string>Tamzen</string>
|
||||||
|
</test>
|
||||||
|
<edit name="antialias" mode="assign">
|
||||||
|
<bool>false</bool>
|
||||||
|
</edit>
|
||||||
|
</match>
|
||||||
|
</fontconfig>
|
||||||
|
'';
|
||||||
|
priority = 90;
|
||||||
|
}; # => conf.d/90-tamzen-disable-antialiasing.conf
|
||||||
|
commit-mono-options = {
|
||||||
|
enable = true;
|
||||||
|
source = "./resources/fontconfig/commit-mono.conf";
|
||||||
|
priority = 80;
|
||||||
|
}; # => conf.d/80-commit-mono-options.conf
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -164,7 +235,7 @@ in
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
xdg.configFile =
|
fonts.fontconfig.configFile =
|
||||||
let
|
let
|
||||||
mkFontconfigConf = conf: ''
|
mkFontconfigConf = conf: ''
|
||||||
<?xml version='1.0'?>
|
<?xml version='1.0'?>
|
||||||
|
|
@ -178,21 +249,25 @@ in
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
"fontconfig/conf.d/10-hm-fonts.conf".text = mkFontconfigConf ''
|
fonts = {
|
||||||
<description>Add fonts in the Nix user profile</description>
|
enable = true;
|
||||||
|
priority = 10;
|
||||||
|
source = null; # Set the source as null explicitly so that it cannot be overwritten by mistake by a user
|
||||||
|
text = mkFontconfigConf ''
|
||||||
|
<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/conf.d</include>
|
||||||
<include ignore_missing="yes">${config.home.path}/etc/fonts/fonts.conf</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}/lib/X11/fonts</dir>
|
||||||
<dir>${config.home.path}/share/fonts</dir>
|
<dir>${config.home.path}/share/fonts</dir>
|
||||||
<dir>${profileDirectory}/lib/X11/fonts</dir>
|
<dir>${profileDirectory}/lib/X11/fonts</dir>
|
||||||
<dir>${profileDirectory}/share/fonts</dir>
|
<dir>${profileDirectory}/share/fonts</dir>
|
||||||
|
|
||||||
<cachedir>${config.home.path}/lib/fontconfig/cache</cachedir>
|
<cachedir>${config.home.path}/lib/fontconfig/cache</cachedir>
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
"fontconfig/conf.d/10-hm-rendering.conf" =
|
rendering =
|
||||||
let
|
let
|
||||||
set =
|
set =
|
||||||
name: value:
|
name: value:
|
||||||
|
|
@ -222,13 +297,15 @@ in
|
||||||
set "rgba" (builtins.replaceStrings [ "ertical-" ] [ "" ] cfg.subpixelRendering)
|
set "rgba" (builtins.replaceStrings [ "ertical-" ] [ "" ] cfg.subpixelRendering)
|
||||||
);
|
);
|
||||||
in
|
in
|
||||||
lib.mkIf (builtins.length content > 0) {
|
{
|
||||||
|
enable = builtins.length content > 0;
|
||||||
|
priority = 10;
|
||||||
|
source = null;
|
||||||
text = mkFontconfigConf (
|
text = mkFontconfigConf (
|
||||||
lib.concatStrings ([ "<description>Set the rendering mode</description>\n" ] ++ content)
|
lib.concatStrings ([ "<description>Set the rendering mode</description>\n" ] ++ content)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
default-fonts =
|
||||||
"fontconfig/conf.d/52-hm-default-fonts.conf".text =
|
|
||||||
let
|
let
|
||||||
genDefault =
|
genDefault =
|
||||||
fonts: name:
|
fonts: name:
|
||||||
|
|
@ -245,13 +322,26 @@ in
|
||||||
</alias>
|
</alias>
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
mkFontconfigConf ''
|
{
|
||||||
<!-- Default fonts -->
|
enable = true;
|
||||||
${genDefault cfg.defaultFonts.sansSerif "sans-serif"}
|
priority = 52;
|
||||||
${genDefault cfg.defaultFonts.serif "serif"}
|
source = null;
|
||||||
${genDefault cfg.defaultFonts.monospace "monospace"}
|
text = mkFontconfigConf ''
|
||||||
${genDefault cfg.defaultFonts.emoji "emoji"}
|
<!-- Default fonts -->
|
||||||
'';
|
${genDefault cfg.defaultFonts.sansSerif "sans-serif"}
|
||||||
|
${genDefault cfg.defaultFonts.serif "serif"}
|
||||||
|
${genDefault cfg.defaultFonts.monospace "monospace"}
|
||||||
|
${genDefault cfg.defaultFonts.emoji "emoji"}
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
xdg.configFile = lib.mapAttrs' (
|
||||||
|
name: config:
|
||||||
|
lib.nameValuePair "fontconfig/conf.d/${builtins.toString config.priority}-hm-${config.label}.conf" {
|
||||||
|
inherit (config) enable text;
|
||||||
|
source = lib.mkIf (config.source != null) config.source;
|
||||||
|
}
|
||||||
|
) cfg.configFile;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,5 @@
|
||||||
|
|
||||||
fontconfig-default-rendering = ./default-rendering.nix;
|
fontconfig-default-rendering = ./default-rendering.nix;
|
||||||
fontconfig-custom-rendering = ./custom-rendering.nix;
|
fontconfig-custom-rendering = ./custom-rendering.nix;
|
||||||
|
fontconfig-extra-config-files = ./extra-config-files.nix;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
33
tests/modules/misc/fontconfig/extra-config-files.nix
Normal file
33
tests/modules/misc/fontconfig/extra-config-files.nix
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
let
|
||||||
|
sampleTextContent = "hello world";
|
||||||
|
fcConfD = "home-files/.config/fontconfig/conf.d";
|
||||||
|
in
|
||||||
|
{
|
||||||
|
fonts.fontconfig = {
|
||||||
|
enable = true;
|
||||||
|
configFile = {
|
||||||
|
text-label-test = {
|
||||||
|
enable = true;
|
||||||
|
label = "sample-text-config";
|
||||||
|
text = sampleTextContent;
|
||||||
|
priority = 55;
|
||||||
|
};
|
||||||
|
source-nolabel-test = {
|
||||||
|
enable = true;
|
||||||
|
source = ./sample-extra-config.conf;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertDirectoryExists ${fcConfD}
|
||||||
|
|
||||||
|
assertFileExists ${fcConfD}/55-hm-sample-text-config.conf
|
||||||
|
assertFileContent ${fcConfD}/55-hm-sample-text-config.conf \
|
||||||
|
${builtins.toFile "sample-text-config" sampleTextContent}
|
||||||
|
|
||||||
|
assertFileExists ${fcConfD}/90-hm-source-nolabel-test.conf
|
||||||
|
assertFileContent ${fcConfD}/90-hm-source-nolabel-test.conf \
|
||||||
|
${./sample-extra-config.conf}
|
||||||
|
'';
|
||||||
|
}
|
||||||
14
tests/modules/misc/fontconfig/sample-extra-config.conf
Normal file
14
tests/modules/misc/fontconfig/sample-extra-config.conf
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
|
||||||
|
|
||||||
|
<fontconfig>
|
||||||
|
<description>Disable anti-aliasing for Tamzen since it is a bitmap font</description>
|
||||||
|
<match target="pattern">
|
||||||
|
<test name="family" compare="eq" qual="any">
|
||||||
|
<string>Tamzen</string>
|
||||||
|
</test>
|
||||||
|
<edit name="antialias" mode="assign">
|
||||||
|
<bool>false</bool>
|
||||||
|
</edit>
|
||||||
|
</match>
|
||||||
|
</fontconfig>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue