Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use fonts installed with home-manager #18982

Open
1 task done
poopsicles opened this issue Oct 10, 2024 · 7 comments
Open
1 task done

Cannot use fonts installed with home-manager #18982

poopsicles opened this issue Oct 10, 2024 · 7 comments
Labels
bug [core label] font Font feedback for readability, size, style, etc linux linux-wayland Linux Wayland nix Nix configuration support setting Feedback for preferences, configuration, etc

Comments

@poopsicles
Copy link

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

Fonts installed with home-manager aren't valid options in the buffer_font_family and ui_font_family options.

Putting fonts installed using home-manager (for me I have Inter and CodeNewRoman Nerd Font) as values for those options doesn't work, with a "Value is not accepted" warning popping up.

Curiously:

  • .SystemUIFont set as the value for buffer_font_family sets Inter as the font (but Inter doesn't).
  • monospace and .monospace don't work either.

The relevant sections of my home.nix (the full thing is here) are:

{ config, pkgs, apple-emoji, ... }:
{
  fonts.fontconfig = {
    enable = true;
    defaultFonts = {
      emoji = ["Apple Color Emoji"];
      monospace = ["FiraCode Nerd Font Mono"];
      sansSerif = ["Inter"];
      serif = ["Noto Serif"];
    };
  };

  home.packages = [
    pkgs.inter
    (pkgs.nerdfonts.override {
        fonts = ["CodeNewRoman" "FiraCode"];
    })
  ];
}

Environment

Zed: v0.155.2 (Zed)
OS: Linux Wayland fedora 40
Memory: 15.4 GiB
Architecture: x86_64
GPU: Intel(R) UHD Graphics 620 (KBL GT2) || Intel open-source Mesa driver || Mesa 24.1.7

If applicable, add mockups / screenshots to help explain present your vision of the feature

image

transcription

a picture of two panes in Zed,

  • the left pane has settings.json open with the following content:

    // Zed settings
    //
    // For information on how to configure Zed, see the Zed
    // documentation: https://zed.dev/docs/configuring-zed
    //
    // To see all of Zed's default settings without changing your
    // custom settings, run the `zed: Open Default Settings` command
    // from the command palette
    {
      "ui_font_size": 16,
      "buffer_font_size": 16,
      "theme": {
        "mode": "system",
        "light": "One Light",
        "dark": "Catppuccin Mocha"
      },
      "assistant": {
        "version": "2",
        "enabled": false
      },
      "restore_on_startup": "none",
      "buffer_font_family": "CodeNewRoman Nerd Font"
    }

    the last line has a warning attached, with the message "Value is not accepted."

  • the right pane has a terminal open, with the following content:

    $ fc-match "CodeNewRoman Nerd Font"
    CodeNewRomanNerdFont-Regular.otf: "CodeNewRoman Nerd Font" "Regular"
    
    $ fc-match "monospace"
    FiraCodeNerdFontMono-Regular.ttf: "FiraCode Nerd Font Mono" "Regular"
    
    $ fc-match "SystemUIFont"
    Inter.ttc: "Inter" "Regular"
    
    $ fc-list "CodeNewRoman Nerd Font"
    /home/fumnanya/.nix-profile/share/fonts/opentype/NerdFonts/CodeNewRomanNerdFont-Regular.otf: CodeNewRoman Nerd Font:style=Regular
    /nix/store/21225n1bhl7rk8x8jbmf2nlshx051h3z-home-manager-path/share/fonts/opentype/NerdFonts/CodeNewRomanNerdFont-Bold.otf: CodeNewRoman Nerd Font:style=Bold
    /nix/store/21225n1bhl7rk8x8jbmf2nlshx051h3z-home-manager-path/share/fonts/opentype/NerdFonts/CodeNewRomanNerdFont-Italic.otf: CodeNewRoman Nerd Font:style=Italic
    /home/fumnanya/.nix-profile/share/fonts/opentype/NerdFonts/CodeNewRomanNerdFont-Italic.otf: CodeNewRoman Nerd Font:style=Italic
    /nix/store/21225n1bhl7rk8x8jbmf2nlshx051h3z-home-manager-path/share/fonts/opentype/NerdFonts/CodeNewRomanNerdFont-Regular.otf: CodeNewRoman Nerd Font:style=Regular
    /home/fumnanya/.nix-profile/share/fonts/opentype/NerdFonts/CodeNewRomanNerdFont-Bold.otf: CodeNewRoman Nerd Font:style=Bold

If applicable, attach your Zed.log file to this issue.

Zed.log
@poopsicles poopsicles added admin read bug [core label] labels Oct 10, 2024
@JosephTLyons JosephTLyons added setting Feedback for preferences, configuration, etc font Font feedback for readability, size, style, etc linux linux-wayland Linux Wayland and removed triage labels Oct 12, 2024
@notpeter notpeter added the nix Nix configuration support label Oct 26, 2024
@poopsicles
Copy link
Author

Did a little investigating:

Now, if fontconfig wasn't enabled then yeah, it'd only look in /usr/share/fonts/, /usr/local/share/fonts/, ~/.local/share/fonts, and ~/.fonts, which mostly don't exist on NixOS,,,but it is turned on...so it falls to load_fontconfig() which looks for a ~/.config/fontconfig/fonts.conf.

However, in my Nix install:

$ ls .config/fontconfig
conf.d
                                                                                                                                                                                                                  
$ ls .config/fontconfig/conf.d
10-hm-fonts.conf  52-hm-default-fonts.conf

So, fontdb needs to walk the conf.d folder if it finds one, to load the fonts...and the latest version of the package doesn't do that yet. The author has expressed fatigue about Linux fontconfig problems: RazrFalcon/fontdb#71, RazrFalcon/fontdb#59, RazrFalcon/fontdb#24, but maybe I'll give it a try and we'll see what happens.

Alternatively,,maybe instructions could be given on how to make a regular fonts.conf that just includes everything in the directory...I don't know if Riey/fontconfig-parser would be able to handle that,,, but it's probably the easier option to test rn,,,

Not sure how related to #17203 this is, I'm not familiar with Guix.

(why aren't the code snippets aren't rendering sigh...)

@maciej-lech
Copy link

maciej-lech commented Feb 10, 2025

Everything works fine for me. Nix-installed fonts are available in Zed.

{ config, pkgs, ... }:
{
  home.packages = with pkgs; [
    nerd-fonts.jetbrains-mono
  ]

  fonts.fontconfig = {
    enable = true;
  };
}

@repomaa
Copy link

repomaa commented Feb 26, 2025

Is there a workaround for this? @maciej-lech from your snippet i'm guessing you're running unstable? Doesn't work for me on stable and stable home manager. I tried using the nerd-fonts package from unstable but it didn't fix it.

@poopsicles
Copy link
Author

@maciej-lech sigh welp, i cant figure it out...because now it works? even with fontdb v0.18
maybe it's cos i was on Fedora before and now I'm on NixOS? or perhaps home-manager has changed something related to fonts? (unlikely because fontconfig.nix was last touched in May)

@repomaa what's your environment?

if possible, could you make a rust project with the following snippet and see if adding/removing fonts with HM changes what shows?

use fontdb::Database;

fn main() {
    let mut db = Database::new();
    db.load_system_fonts();

    println!("{} font faces", db.len());

    for f in db.faces() {
        println!("{}", f.post_script_name);
    }
}

@maciej-lech
Copy link

@repomaa yes, unstable.

SRugina added a commit to SRugina/fontconfig-parser that referenced this issue Mar 7, 2025
A `for..in` loop on a `BinaryHeap` is not sorted,
see https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html#method.iter
so the old code, whilst presumably _intended_ to be sorted, was actually
iterating with a random order.

Collecting as a `Vec` then sorting is simpler and more efficient since
`read_dir` depends on FS and can be in ascending order which degrades
each insertion from `O(1)` to `O(log(n))`, amortised for `BinaryHeap`,
see https://doc.rust-lang.org/alloc/collections/binary_heap/struct.BinaryHeap.html#time-complexity-3

That random order was causing downstream bugs:

- zed-industries/zed#18982
- zed-industries/zed#22676
- flathub/dev.lapce.lapce#50
- RazrFalcon/fontdb#78

as, e.g. inside a flatpak, `/etc/fonts/conf.d/05-flatpak-fontpath.conf`
features a `<remove-dirs />` that would then hide the flatpak-specific
`<dir>`s like `/run/host/fonts` in `/etc/fonts/conf.d/50-flatppk.conf`
if the `05-` file gets merged after the `50-` file.
SRugina added a commit to SRugina/fontconfig-parser that referenced this issue Mar 7, 2025
A `for..in` loop on a `BinaryHeap` is not sorted,
see https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html#method.iter
so the old code, whilst presumably _intended_ to be sorted, was actually
iterating with a random order.

Collecting as a `Vec` then sorting is simpler and more efficient since
`read_dir` depends on FS and can be in ascending order which degrades
each insertion from `O(1)` to `O(log(n))`, amortised, for `BinaryHeap`,
see https://doc.rust-lang.org/alloc/collections/binary_heap/struct.BinaryHeap.html#time-complexity-3

That random order was causing downstream bugs:

- zed-industries/zed#18982
- zed-industries/zed#22676
- flathub/dev.lapce.lapce#50
- RazrFalcon/fontdb#78

as, e.g. inside a flatpak, `/etc/fonts/conf.d/05-flatpak-fontpath.conf`
features a `<remove-dirs />` that would then hide the flatpak-specific
`<dir>`s like `/run/host/fonts` in `/etc/fonts/conf.d/50-flatppk.conf`
if the `05-` file gets merged after the `50-` file.
SRugina added a commit to SRugina/fontconfig-parser that referenced this issue Mar 7, 2025
A `for..in` loop on a `BinaryHeap` is not sorted,
see https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html#method.iter
so the old code, whilst presumably _intended_ to be sorted, was actually
iterating with a random order.

Collecting as a `Vec` then sorting is simpler and more efficient since
`read_dir` depends on FS and can be in ascending order which degrades
each insertion from `O(1)` to `O(log(n))`, amortised, for `BinaryHeap`,
see https://doc.rust-lang.org/alloc/collections/binary_heap/struct.BinaryHeap.html#time-complexity-3

That random order was causing downstream bugs:

- zed-industries/zed#18982
- zed-industries/zed#22676
- flathub/dev.lapce.lapce#50
- RazrFalcon/fontdb#78

as, e.g. inside a flatpak, `/etc/fonts/conf.d/05-flatpak-fontpath.conf`
features a `<reset-dirs />` that would then hide the flatpak-specific
`<dir>`s like `/run/host/fonts` in `/etc/fonts/conf.d/50-flatppk.conf`
if the `05-` file gets merged after the `50-` file.
@jcdickinson
Copy link
Contributor

jcdickinson commented Mar 8, 2025

Background:

I fixed this problem in fontdb 0.19.0+ (I think, it might have been 0.18.0+). I attempted to propagate the fix to all dependent crates (and ultimately here), either with issues or PRs.

The problem is that the author of the crate doesn't use Cargo versioning correctly - meaning that Cargo considers 0.17.0 and 0.18.0 etc. incompatible (they are, in fact, compatible). Furthermore, the same author is responsible for a widely used SVG crate that uses fontdb, and it seems that they are/were experiencing massive burnout (which is completely understandable, especially given their location) - so it took a significant amount of time for them to get round to updating the fontdb dep in usvg.

During that time, upgrading fontdb was attempted but had to be rolled back: pop-os/cosmic-text#295 - the reason is that cosmic-ui used usvg, so cosmic-ui wound up with different versions of fontdb (one via cosmic-text, the other via resvg/usvg).

Ultimately it looks like the System76 developers are going to have to coordinate a crate update for cosmic-text and cosmic-ui (resvg+usvg seems to have been updated since I last looked at this, but not cosmic-text).

This is why my flake+fork (which danielgafni has since forked and begun to maintain) uses a fontdb override, to a fontdb fork of mine that falsely declares it's the older version: https://github.com/jcdickinson/fontdb/tree/0-18-backport . zed-industries could do likewise, fontdb is a relatively slow moving crate - so it shouldn't take much effort.

@P1n3appl3 just a lay of the land/minefield so that you can avoid the failures that I made. I haven't kept track of this since the cosmic-text rollback, so maybe something has changed.

Edit: the underlying bug is that symlinks aren't followed at all, and given how everything Nix works...

@SRugina
Copy link

SRugina commented Mar 8, 2025

Just an extra note to add if petitioning for a coordinated crate update train starts soon:

Another bug certain setups might encounter (the big one being (almost) all flatpak installs, but I'm sure certain Nix setups too hence the relevancy here) is actually one further level upstream than fontdb: fontconfig-parser was not processing config files in lexicographic order (01-... before 02-...), which would break things that depended on that order of precedence being respected.

That's fixed in this PR: Riey/fontconfig-parser#11 pending review & merge.

This is, arguably, quite a big bug, so ideally the update train will include it - especially since it sounds like updating fontdb will be challenging; may as well get all the fixes done in one go.

Ideally, system font discovery should really be its own package that uses the OS' database, with fontdb used only to hold what a Rust app actually needs after the app separately queries the system fonts it wants. However, fontdb's dev says relying on the system fontconfig has performance issues, so for now the behaviour bundled in fontdb does seem to be the "good enough", if heavy-handed, approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] font Font feedback for readability, size, style, etc linux linux-wayland Linux Wayland nix Nix configuration support setting Feedback for preferences, configuration, etc
Projects
No open projects
Status: No status
Development

No branches or pull requests

7 participants