When fonts.fonts = [ ]; list is modified in nixos, it causes fonts cache update. It'd be handy to have such option for fonts installed via home-manager so that you don't need to execute fc-cache -f manually.
Currently I use the following hack:
{config, pkgs, lib, ...}:
let
cfg = config.fonts;
in
with lib;
{
options = {
fonts.fonts = mkOption {
type = types.listOf types.package;
default = [];
example = literalExample "[ pkgs.dejavu_fonts ]";
description = "List of fonts.";
};
};
config = {
home.packages = cfg.fonts;
home.file."${config.xdg.cacheHome}/hm-fonts" = let
getHash = drv: builtins.elemAt (builtins.match "${builtins.storeDir}/([a-z0-9]{32})-.*.drv" drv.drvPath) 0;
in {
text = concatMapStringsSep "\n" getHash cfg.fonts;
onChange = ''
echo "Caching fonts"
$DRY_RUN_CMD fc-cache -f
'';
};
};
}
It just saves a list of hashes of fonts derivations in a file and updates cache when the list changes.
@rycee Do you think it'll be useful to include it in some form in home-manager?
This looks like a good idea to me :+1:
Why fonts.fonts though? Maybe just a rootlevel fonts or do home.fonts?
I realize that NixOS uses fonts.fonts, i find the attribute name choice weird though.
Why fonts.fonts though? Maybe just a rootlevel fonts or do home.fonts?
There is already fonts.fontconfig, so it can't be just fonts. fonts.fonts is at least known from nixos.
Oh, there is. Makes sense to follow NixOS then. I'd probably have chosen fonts.packages, but yours makes sense due to NixOS's choice :smiley:
@rycee, @wedens are you still interested in having this added to home-manager?
If anybody is able to try it out then please have a look at #682, which I believe will resolve this issue. Note, you will have to add
fonts.fontconfig.enable = true;
to your configuration for it it take effect.
Most helpful comment
@rycee, @wedens are you still interested in having this added to home-manager?