nix-community / home-manager

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

fonts qq #703

Closed ylixir closed 5 years ago

ylixir commented 5 years ago

I can't for the life of me figure out to get fonts working.

here is my home.nix

{ pkgs, ... }:

{
    home.packages = with pkgs; [
      fontconfig
      google-fonts
    ];

    fonts.fontconfig.enable = true;

    programs.home-manager.enable = true;
}

here is home-managers output

building '/nix/store/gqp24w85111ndl2r5zxf8zivv9qv6l40-home-manager-path.drv'...
created 43 symlinks in user environment
/nix/store/5h4rvb9imlag856jvqb9v5nndzb3siwd-home-manager-path/share/fonts: failed to write cache
/nix/store/5h4rvb9imlag856jvqb9v5nndzb3siwd-home-manager-path/share/fonts/truetype: failed to write cache
builder for '/nix/store/gqp24w85111ndl2r5zxf8zivv9qv6l40-home-manager-path.drv' failed with exit code 2
cannot build derivation '/nix/store/910zacmsm51hr54bzlapnzv5i1q7kgwb-home-manager-generation.drv': 1 dependencies couldn't be built
error: build of '/nix/store/910zacmsm51hr54bzlapnzv5i1q7kgwb-home-manager-generation.drv' failed

i'm running nixpkgs standalone, not on nixos

Fonts are the whole reason I'm trying out home manager instead of rolling my own config from scratch.

Originally I started out with home-manager building, but not making fonts available to me (fc-list only shows one dejavu font).

Trying to create a minimal example and now i can't even get things building period.

rycee commented 5 years ago

Thanks for the report! Yeah, the font cache generation is a bit buggy. I'll see about fixing it but I believe you can work around it by adding some library to home.packages. Give

{ pkgs, ... }:

{
    home.packages = with pkgs; [
      fontconfig
      google-fonts
      zlib # workaround for #703
    ];

    fonts.fontconfig.enable = true;

    programs.home-manager.enable = true;
}

a try.

ylixir commented 5 years ago

Thank you for home-manager. It's incredibly slick. I'm glad I tried it.

I guess missing zlib explains why my less minimal real setup had a different issue. Now with zlib the real problem is reproduced. None of the google fonts (or any other fonts for that matter) show up. Just a lonely dejavu.

$ fc-list
Fontconfig error: Cannot load default config file
/nix/store/8gn2b5vvlazg608cj1y5l4igp9rckmnq-dejavu-fonts-minimal-2.37/share/fonts/truetype/DejaVuSans.ttf: DejaVu Sans:style=Book
rycee commented 5 years ago

I'm glad you like Home Manager, despite the bugs 🙂

Unfortunately I can't reproduce the fc-list error. I've never had google-fonts installed before and after adding it to home.packages I get

$ home-manager switch
…
$ fc-list
…
/nix/store/hw3k43wviirfj9y7aqinl50ybk8ahjh6-home-manager-path/share/fonts/truetype/Assistant-Light.ttf: Assistant,Assistant Light:style=Light,Regular
/nix/store/hw3k43wviirfj9y7aqinl50ybk8ahjh6-home-manager-path/share/fonts/truetype/JollyLodger-Regular.ttf: Jolly Lodger:style=Regular
/nix/store/hw3k43wviirfj9y7aqinl50ybk8ahjh6-home-manager-path/share/fonts/truetype/Trykker-Regular.ttf: Trykker:style=Regular

with the majority of output referring to google-fonts.

The

Fontconfig error: Cannot load default config file

message is quite curious. Could you share the output you get from running

$ FC_DEBUG=1024 fc-list

?

ylixir commented 5 years ago

Absolutely nothing helpful

FC_DEBUG=1024
Fontconfig error: Cannot load default config file
/nix/store/8gn2b5vvlazg608cj1y5l4igp9rckmnq-dejavu-fonts-minimal-2.37/share/fonts/truetype/DejaVuSans.ttf: DejaVu Sans:style=Book

Same deal after switching to the bugfix branch.

$ nix-channel --add https://github.com/rycee/home-manager/archive/bugfix/fontconfig-with-no-lib-pkg.tar.gz home-manager
$ nix-channel --update && nix-env -u
$ home-manager switch

Googling around a little I see references to setting FONTCONFIG_PATH which is not set for me, but I'm not sure what is should be set to. I'll tool around a little later today and see if I can make any progress.

But I think the idea of missing libraries or dependencies is on the right track, I have a very minimal void linux install that I'm working off of.

rycee commented 5 years ago

Curious that FC_DEBUG=1024 didn't cause any output. When I run the same command the output starts with

FC_DEBUG=1024
        Loading config file from /etc/fonts/2.11/fonts.conf
        Scanning config dir /etc/fonts/2.11/conf.d
        …

and lists a bunch of additional configuration files.

So if it says "Fontconfig error: Cannot load default config file" perhaps it means that /etc/fonts/2.11/fonts.conf doesn't exist? Do you have a fontconfig config anywhere else in /etc?

A possibility might be to run strace -e openat fc-list or strace -e stat fc-list to see which files it tries to read.

ylixir commented 5 years ago

i have no idea what is going on. no matter what I've tried from within nix/home-manager land I can't get fc-list with strace (stat or openat) always shows the following lines one after the other.

FC_DEBUG=1024
Fontconfig error: Cannot load default config file

so it's not even trying to read a config i guess?

I even tried creating a stub from the information here and manually pointing FONTCONFIG_PATH to it. but nothing.

mostly it just dumps info for loading dynamic libraries, with all seem to succeed eventually, followed by the eror above, then some stuff about the dejavu fonts.

Interestingly when i install fontconfig in the host system, with the native package manager (void linux, xbps) then the nix stuff just starts working, minus a few errors. So I guess that's good enough for me? At this point I'm not even convinced that there is anything wrong with home-manager. It almost seems like either a configuaration issue with in nixpkgs or some hardcoding in fontconfig?

ylixir commented 5 years ago

Well fc-list works, but font-manager doesn't show the fonts installed with home-manager.

I'm way past where I understand how X and fonts interact though. I dunno if this is a problem with home-manager or X, which is way outside of home-managers scope since I'm on WSL and X is a windows program.

I'm okay if you close this issue out. I've found workarounds and it's very edge case.

I'll let you close it though in case there's an actual problem with home-manager and not upstream since I really have no idea what's going on ;-)

Thank you for all of your help. Even though fonts didn't work out, switching to home-manager has dratically simplified my dotfiles, and should make it easyier to leap to realsies nixos when I decide to go for it.

rycee commented 5 years ago

For what it's worth, I tried font-manager and it also didn't show the fonts I have installed through Home Manager. Looking at the strace output for font-manager I see no particular reason why.

All other programs seem to find the fonts just fine, for example gnome-font-viewer. Very peculiar.