nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.56k stars 1.73k forks source link

bug: fontconfig via HM doesn't actually work for me (HM installed fonts not seen by applications) #4048

Open ppenguin opened 1 year ago

ppenguin commented 1 year ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

I just moved the many "extra" fonts for my HM user from the global nixos config into my HM-config.

So I have:

home.packages = with pkgs; [ ... /* many fonts */ ];
fonts.fontconfig.enable = true;

When e.g. running font-manager I can only see the fonts that were installed system wide (via fonts = [ ... ]; in configuration.nix.

Running fc-cache --force --verbose gives me many errors about "looped dirs" (safe to ignore as duplicates?) and non-writable cache dir(s). The latter is to be expected if I understand correctly, since the cache is read-only by design and built to the nix store by the HM module. So fc-cache is ineffectual as well by design for this setup, I guess.

I checked and have ~/.config/fontconfig/conf.d/10-hm-fonts.conf, containing

<?xml version='1.0'?>

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

<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
  <include ignore_missing="yes">/nix/store/8563zkq3iw1k9l3l4a1544xs6nskglzk-home-manager-path/etc/fonts/conf.d</include>
  <include ignore_missing="yes">/nix/store/8563zkq3iw1k9l3l4a1544xs6nskglzk-home-manager-path/etc/fonts/fonts.conf</include>

  <dir>/nix/store/8563zkq3iw1k9l3l4a1544xs6nskglzk-home-manager-path/lib/X11/fonts</dir>
  <dir>/nix/store/8563zkq3iw1k9l3l4a1544xs6nskglzk-home-manager-path/share/fonts</dir>
  <dir>/home/jeroen/.nix-profile/lib/X11/fonts</dir>
  <dir>/home/jeroen/.nix-profile/share/fonts</dir>

  <cachedir>/nix/store/8563zkq3iw1k9l3l4a1544xs6nskglzk-home-manager-path/lib/fontconfig/cache</cachedir>
</fontconfig>

The first <include> appears to be the same one that is pointed to by ~/.nix-profile/etc/fonts/conf.d, the second doesn't exist (?!), the second and fourth <dir> entries are also the same /nix/store path content and the X11 don't exist (I'm on wayland, probably normal).

I also have ~/.nix-profile/etc/fonts/ which only contains a dir conf.d which contains symlinks (e.g. 30-courier-new.conf) to the nix store realisations of corefonts and vistafonts, which I do have in home.packages, but I have many more fonts as well but these are the only ones that are linked here.

When I run a devShell from a flake that does this:

  ...
  let
       fonts = pkgs.makeFontsConf { fontDirectories = with pkgs; [ freefont_ttf fira fira-mono ubuntu_font_family noto-fonts-cjk gyre-fonts hyperscrypt-font lmodern ]; }; # https://github.com/NixOS/nixpkgs/issues/24485
  in
  pkgs.mkShell { 
   ...
    shellHook = ''
    export FONTCONFIG_FILE=${fonts}
  '';
  }

and in this shell start font-manager, I indeed see the selected fonts.

I.e. that begs the question what HM does differently, or why we can't use makeFontsConf in HM as well?

So I'm a bit lost why HM fonts management doesn't work for me, but also it might be better to use the same fonts = [ ... ]; paradigm in HM instead of just putting fonts in home.packages?

Maintainer CC

@rycee

System information

- system: `"x86_64-linux"`
 - host os: `Linux 6.2.16, NixOS, 23.05 (Stoat), 23.05.20230531.3a70dd9`
 - multi-user?: `yes`
 - sandbox: `relaxed`
 - version: `nix-env (Nix) 2.13.3`
 - nixpkgs: `/nix/store/bcwv054bxj0k
nixos-discourse commented 1 year ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/since-upgrade-to-23-05-nerdfonts-wont-show/28636/5

rycee commented 1 year ago

Does the generated configuration show up when you run fc-conflist | grep $HOME? Do any of the fonts show up in fc-list?

exzombie commented 1 year ago

For me, it's even stranger: the ~/.nix-profile/etc/fonts/ directory doesn't exist either. fc-conflist does include /.config/fontconfig/conf.d/10-hm-fonts.conf.

The directory ~/.nix-profile/share/fonts/ exists and the fonts are installed there; fc-list includes the fonts installed by HM, and fc-match can match them. However, other programs are hit or miss. font-manager, for example, doesn't list them.

exzombie commented 1 year ago

Ok, so I tracked the "hit or miss" nature of the problem down to "Hack Nerd Font Mono", which seems to be a bit problematic. For example, it couldn't be loaded by emacs. I tried other Nerd fonts, and they work. Also in other programs, like konsole or libreoffice.

font-manager still doesn't see any Nerd fonts installed by HM. Not a problem for me, though it might indicate not everything is peachy. But it just as well be an issue specific to this program.

stale[bot] commented 10 months ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

fedor-ivn commented 4 months ago

Any updates here? Still reproducible

stale[bot] commented 1 month ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.