Skip to content

Instantly share code, notes, and snippets.

@worldofpeace
Last active September 6, 2020 17:02
Show Gist options
  • Save worldofpeace/d546167739cb41d87f965c9a81e78530 to your computer and use it in GitHub Desktop.
Save worldofpeace/d546167739cb41d87f965c9a81e78530 to your computer and use it in GitHub Desktop.
Nix Expression for FiraCode nerdfont
{ stdenv, fetchzip }:
let
pname = "FiraCode";
version = "v2.0.0";
in
stdenv.mkDerivation rec {
name = "${pname}-nerdfont-${version}";
src = fetchzip {
url = "https://github.com/ryanoasis/nerd-fonts/releases/download/${version}/${pname}.zip";
sha256 = "1bnai3k3hg6sxbb1646ahd82dm2ngraclqhdygxhh7fqqnvc3hdy";
stripRoot = false;
};
buildCommand = ''
install --target $out/share/fonts/opentype -D $src/*.otf
'';
meta = with stdenv.lib; {
description = "Nerdfont version of Fira Code";
homepage = https://github.com/ryanoasis/nerd-fonts;
license = licenses.mit;
};
}
@con-f-use
Copy link

con-f-use commented Jul 19, 2020

Thanks! Is there a reason for the camel case in pname and the "v" in version?

Seems like it's not in line with:

$ nix-env -qa '.*fira.*'                                                                                                                                                        
fira-4.106
fira-4.202
fira-4.202
fira-code-2
fira-code-5.2
fira-code-5.2
fira-code-symbols-20160811
fira-code-symbols-20160811
fira-code-symbols-20160811
fira-mono-3.206
fira-mono-3.206
fira-mono-3.206
rictydiminished-with-firacode-1.2.0
rictydiminished-with-firacode-1.2.2
rictydiminished-with-firacode-1.2.2

Edit: Ah, nevermind, I overlooked that is part of the download URL.

Also, shound't this also update the font-cache or what's the schtick there?

@worldofpeace
Copy link
Author

worldofpeace commented Jul 19, 2020

This expression is now obsolete by https://github.com/NixOS/nixpkgs/blob/eb54aa1f6cc9a817bad76145894a49722cd0005b/pkgs/data/fonts/nerdfonts/default.nix#L7, where the nerd font package in nixpkgs can select a font by overriding the package

fonts.fonts = with pkgs; [
  (nerdfonts.override {
    fonts = [ 
      "FiraCode"
    ];
  })
];

@con-f-use
Copy link

con-f-use commented Jul 20, 2020

I, see. Thanks for taking the time to tell me. If I could get just one more question in, what does the fonts.fonts part exactly do? It seems to be a NixOS module. So what would a non-NixOS user do instead, say if it was a dependency of a custom package.

@con-f-use
Copy link

con-f-use commented Sep 6, 2020

I tried (nerdfonts.override { fonts = [ "FiraCode" ]; }) but that just gives me

error: anonymous function at /nix/store/42s3x72zmvijdjf62ng1091nnhd1ma8g-nixos-20.03.2882.51d115ac89d/nixos/pkgs/data/fonts/nerdfonts/default.nix:1:1 called with unexpected argument 'fonts'

Edit:

Ah I see, it's nerdfonts.override { withFont = "FiraCode"; }), now.

Oh god, that downloads a 2 GB file, rather than the specialized release files for the respective font!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment