Skip to content

Commit

Permalink
nerdfonts: separate into individual packages under namespace nerd-fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
rc-zb committed Nov 19, 2024
1 parent 7cea3c6 commit 9ceb003
Show file tree
Hide file tree
Showing 14 changed files with 6,562 additions and 182 deletions.
6 changes: 6 additions & 0 deletions nixos/doc/manual/release-notes/rl-2411.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,12 @@
rather than dotnet 6. For packages that still need dotnet 6, use
`dotnet-sdk_6`, etc.

- `nerdfonts` has been separated into individual font packages under the namespace `nerd-fonts`. The directories for font
files have changed from `$out/share/fonts/{opentype,truetype}/NerdFonts` to
`$out/share/fonts/{opentype,truetype}/NerdFonts/<fontDirName>`, where `<fontDirName>` can be found in the
[official website](https://www.nerdfonts.com/font-downloads) as the titles in preview images, with the "Nerd Font"
suffix and any whitespaces trimmed.

## Other Notable Changes {#sec-release-24.11-notable-changes}

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
Expand Down
4 changes: 2 additions & 2 deletions pkgs/applications/terminal-emulators/kitty/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
, harfbuzz, fontconfig, pkg-config, ncurses, imagemagick
, libstartup_notification, libGL, libX11, libXrandr, libXinerama, libXcursor
, libxkbcommon, libXi, libXext, wayland-protocols, wayland, xxHash
, nerdfonts
, nerd-fonts
, lcms2
, librsync
, openssl
Expand Down Expand Up @@ -144,7 +144,7 @@ buildPythonApplication rec {
# Add the font by hand because fontconfig does not finds it in darwin
mkdir ./fonts/
cp "${(nerdfonts.override {fonts = ["NerdFontsSymbolsOnly"];})}/share/fonts/truetype/NerdFonts/SymbolsNerdFontMono-Regular.ttf" ./fonts/
cp "${nerd-fonts.symbols-only}/share/fonts/truetype/NerdFonts/Symbols/SymbolsNerdFontMono-Regular.ttf" ./fonts/
${ lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) "export MACOSX_DEPLOYMENT_TARGET=11" }
${if stdenv.hostPlatform.isDarwin then ''
Expand Down
28 changes: 28 additions & 0 deletions pkgs/data/fonts/nerd-fonts/convert-license.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ lib }:
let
ls = lib.licenses;
in
licenseString:
builtins.getAttr licenseString (
(
with builtins;
lib.trivial.pipe (attrValues ls) [
(filter (l: l ? spdxId))
(map (l: lib.attrsets.nameValuePair l.spdxId l))
listToAttrs
]
)
// {
"Bitstream-Vera AND MIT" = with ls; [
bitstreamVera
mit
];
"LicenseRef-Monofur" = ls.free; # upstream `src/unpatched-fonts/Monofur/LICENSE.txt`
"LicenseRef-UbuntuFont" = ls.ufl;
"LicenseRef-VicFieger" = ls.free; # upstream `src/unpatched-fonts/HeavyData/Vic Fieger License.txt`
"MIT OR OFL-1.1-no-RFN" = ls.mit;
"OFL-1.1-RFN" = ls.ofl;
"OFL-1.1-no-RFN or LGPL-2.1-only" = ls.ofl;
"OFL-1.1-no-RFN" = ls.ofl;
}
)
89 changes: 89 additions & 0 deletions pkgs/data/fonts/nerd-fonts/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
lib,
callPackage,
stdenvNoCC,
fetchurl,
}:

let
releaseInfo = lib.trivial.importJSON ./manifests/release.json;
fontsInfo = (lib.trivial.importJSON ./manifests/fonts.json).fonts;
hashes = lib.trivial.importJSON ./manifests/hashes.json;

# Always aborts if finding nothing.
firstFound = pred: lib.lists.findFirst pred (throw "nothing found");

convertAttrName =
name:
let
lowerName = lib.strings.toLower name;
in
if builtins.match "[[:digit:]].*" lowerName != null then "_" + lowerName else lowerName;

convertLicense = callPackage ./convert-license.nix { };

makeNerdFont =
{
caskName,
description,
folderName,
licenseId,
patchedName,
version,
...
}:
stdenvNoCC.mkDerivation {
pname = lib.strings.toLower caskName;
version =
if builtins.match "[[:digit:]].*" version != null then
version
else
"0-unstable-" + builtins.head (lib.strings.splitString "T" releaseInfo.published_at);

src =
let
filename = folderName + ".tar.xz";
url = (firstFound (a: a.name == filename) releaseInfo.assets).browser_download_url;
hash = (firstFound (i: i.filename == filename) hashes).hash;
in
fetchurl {
inherit url hash;
};

sourceRoot = ".";

installPhase =
let
dirName = lib.strings.concatStrings (lib.strings.splitString " " patchedName);
in
''
runHook preInstall
dst_opentype=$out/share/fonts/opentype/NerdFonts/${dirName}
dst_truetype=$out/share/fonts/truetype/NerdFonts/${dirName}
find -name \*.otf -exec mkdir -p $dst_opentype \; -exec cp -p {} $dst_opentype \;
find -name \*.ttf -exec mkdir -p $dst_truetype \; -exec cp -p {} $dst_truetype \;
runHook postInstall
'';

passthru.updateScript = ./update.rb;

meta = {
description = "Nerd Fonts: " + description;
license = convertLicense licenseId;
homepage = "https://nerdfonts.com/";
changelog = "https://github.com/ryanoasis/nerd-fonts/blob/${releaseInfo.tag_name}/changelog.md";
platforms = lib.platforms.all;
maintainers = with lib.maintainers; [
doronbehar
rc-zb
];
};
};
in

builtins.listToAttrs (
map (font: lib.attrsets.nameValuePair (convertAttrName font.caskName) (makeNerdFont font)) fontsInfo
)
Loading

0 comments on commit 9ceb003

Please sign in to comment.