NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.43k stars 12.93k forks source link

Using nerd-fonts to patch arbitrary fonts #44329

Open ninjarai4 opened 5 years ago

ninjarai4 commented 5 years ago

The existing nerd-fonts derivation currently just installs a few predetermined patched fonts, but the nerd-fonts project is also able to patch any font that you supply it. This functionality is missing in nixpkgs currently.

It would be nice if we had the ability to apply a function to an existing derivation and return a derivation with all of the fonts patched by nerd-fonts.

So for example your fonts.fonts could look like with pkgs; [dejavu-fonts emojione (nerd-fontify my-iosevka-with-custom-build-options)]

stale[bot] commented 4 years ago

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.
Jake-Gillberg commented 3 years ago

I'm wondering if someone has found a good method for doing this. I want the most up-to-date (and possibly custom) Iosevka font with patched glyphs, and the nerd-font distribution of Iosevka has fallen a bit behind.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

pinpox commented 3 years ago

Still interested in this, any solutions?

NomisIV commented 3 years ago

Instead of a function I propose to have it be an option in the package instead, I think that would be easier to implement. This would look something like nerdfonts.override { patchFonts = [ iosevka.override { privateBuildPlan = { ... }; } ]; }. I'll try to make a prototype of this

EDIT: Here is a link to the drafted PR https://github.com/NixOS/nixpkgs/pull/124042

luxus commented 1 year ago

i found this https://github.com/montchr/dotfield/blob/main/packages/fonts/iosevka/default.nix and this https://codeberg.org/harrisonthorne/iosevka-muse/src/commit/ca362ea18ef57eef395a96b9f9c9cb06d1fef3f2/flake.nix#L24

eigengrau commented 1 year ago

I’m currently using:

{ nerd-font-patcher, stdenv }:
font:
stdenv.mkDerivation {
  name = "${font.name}-nerd-font-patched";
  src = font;
  nativeBuildInputs = [ nerd-font-patcher ];
  buildPhase = ''
    find -name \*.ttf -o -name \*.otf -exec nerd-font-patcher -c {} \;
  '';
  installPhase = "cp -a . $out";
}

But I guess it would be nice to have something built into nixpkgs.

zeorin commented 1 year ago

In the meantime it's also possible to install just the symbols (called "Symbols Nerd Font"):

      # Nerd Fonts but just the symbols
      # Set FontConfig to use it as a fallback for most monospaced fonts
      (stdenv.mkDerivation {
        pname = "symbols-nerd-font";
        version = "2.2.0";
        src = fetchFromGitHub {
          owner = "ryanoasis";
          repo = "nerd-fonts";
          rev = "FontPatcher";
          sha256 = "ORQUN4oMxgf9y1K0cQqgiREefk6edbvmRFPQ5G4uKwo=";
          sparseCheckout = ''
            10-nerd-font-symbols.conf
            patched-fonts/NerdFontsSymbolsOnly
          '';
        };
        dontConfigure = true;
        dontBuild = true;
        installPhase = ''
          runHook preInstall

          fontconfigdir="$out/etc/fonts/conf.d"
          install -d "$fontconfigdir"
          install 10-nerd-font-symbols.conf "$fontconfigdir"

          fontdir="$out/share/fonts/truetype"
          install -d "$fontdir"
          install "patched-fonts/NerdFontsSymbolsOnly/complete/Symbols-2048-em Nerd Font Complete.ttf" "$fontdir"

          runHook postInstall
        '';
        enableParallelBuilding = true;
      })

It includes a fontconfig that sets it up as a fallback for most programming fonts so you don't have to patch. Patching can give better results, but this is handy in a pinch.

metiulekm commented 1 year ago

If somebody finds this and tries something similar, I got a solution similar to @eigengrau's working, but I needed a couple changes, most notably:

-    find -name \*.ttf -o -name \*.otf -exec nerd-font-patcher -c {} \;
+    find \( -name \*.ttf -o -name \*.otf \) -execdir nerd-font-patcher -c {} \;

I needed some extra parens in find, due to https://superuser.com/questions/1774731/why-does-find-o-print-produce-no-output/1774734#1774734; it seems that without it, it would only work for OTF. Also, I needed to use -execdir to ensure the font files would end up in the same place as the originals, otherwise fontconfig did not see them on my configuration.

carnotweat commented 1 year ago

I am using this atm ( not mine) , but I find it neat, wrt hashing/downloading problem of with nix,fetchzip + mammoth clone of newdfonts https://dee.underscore.world/blog/home-manager-fonts/