stylix icon indicating copy to clipboard operation
stylix copied to clipboard

fonts: set home-manager fonts.fontconfig.defaultFonts

Open mightyiam opened this issue 11 months ago • 9 comments

Not much to see here...

Things done

Notify maintainers

mightyiam avatar May 17 '25 08:05 mightyiam

Will this allow users to add their own fallback fonts for fontconfig?

musjj avatar May 17 '25 08:05 musjj

Hrm... with NixOS and home-manager each providing this feature, one can already set their preferred fonts (a list that determines precedence) without stylix. It seems to me that the only benefit stylix adds on top of that is explicitly setting fonts for apps that somehow (I don't know how this works) do not obey fontconfig. Which is most likely a minority of apps.

mightyiam avatar May 17 '25 12:05 mightyiam

What I meant is that if I want to add additional fallback fonts like this:

fonts.fontconfig = {
  defaultFonts = {
    monospace = [ myFontA ];
    serif = [ myFontB ];
    sansSerif = [ myFontC ];
    emoji = [ myFontD ];
  };
};

Will this clash with the behavior introduced in this PR?

musjj avatar May 22 '25 05:05 musjj

What I meant is that if I want to add additional fallback fonts like this:

fonts.fontconfig = {
  defaultFonts = {
    monospace = [ myFontA ];
    serif = [ myFontB ];
    sansSerif = [ myFontC ];
    emoji = [ myFontD ];
  };
};

Will this clash with the behavior introduced in this PR?

No, the definitions should be merged automatically.

Flameopathic avatar May 23 '25 01:05 Flameopathic

Oh yeah, I can confirm that it works.

This config:

stylix.enable = true;
                                                                                    
fonts.fontconfig.defaultFonts = {
  monospace = [ "myFontA" "myFontB" ];
  serif = [ "myFontC" "myFontD" ];
  sansSerif = [ "myFontE" "myFontF" ];
  emoji = [ "myFontG" "myFontH" ];
};

Will produce:

nix-repl> :p config.fonts.fontconfig.defaultFonts
{
  emoji = [
    "Noto Color Emoji"
    "myFontG"
    "myFontH"
  ];
  monospace = [
    "DejaVu Sans Mono"
    "myFontA"
    "myFontB"
  ];
  sansSerif = [
    "DejaVu Sans"
    "myFontE"
    "myFontF"
  ];
  serif = [
    "DejaVu Serif"
    "myFontC"
    "myFontD"
  ];
}

But we should treat fontconfig as a target right? So that users can enable/disable it.

musjj avatar May 23 '25 09:05 musjj

But we should treat fontconfig as a target right? So that users can enable/disable it.

Well the equivalent NixOS module doesn't seem to introduce a target:

https://github.com/nix-community/stylix/blob/34b5930894d8315401d93bd8a9a6635e1cd28eff/stylix/nixos/fonts.nix

mightyiam avatar May 24 '25 15:05 mightyiam

But we should treat fontconfig as a target right? So that users can enable/disable it.

Well the equivalent NixOS module doesn't seem to introduce a target:

https://github.com/nix-community/stylix/blob/34b5930894d8315401d93bd8a9a6635e1cd28eff/stylix/nixos/fonts.nix

Interesting, you're right. This seems like bad practice and just vestigial code from the very early days of Stylix. I support making a font-config module with NixOS and Home Manager targets.

CC: @danth

Flameopathic avatar May 25 '25 01:05 Flameopathic

Interesting, you're right. This seems like bad practice and just vestigial code from the very early days of Stylix. I support making a font-config module with NixOS and Home Manager targets.

#1381

mightyiam avatar May 25 '25 03:05 mightyiam

Yes, I agree, we should move fontconfig to a target :))

danth avatar May 25 '25 13:05 danth

Successfully created backport PR for release-25.05:

  • #1475

stylix-automation[bot] avatar Jun 10 '25 17:06 stylix-automation[bot]

Thanks everyone!

mightyiam avatar Jun 11 '25 00:06 mightyiam