summary refs log tree commit diff
path: root/pkgs/data/fonts/nerdfonts/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/data/fonts/nerdfonts/default.nix')
-rw-r--r--pkgs/data/fonts/nerdfonts/default.nix69
1 files changed, 51 insertions, 18 deletions
diff --git a/pkgs/data/fonts/nerdfonts/default.nix b/pkgs/data/fonts/nerdfonts/default.nix
index 8ffd0e3e43f..35f43c14df4 100644
--- a/pkgs/data/fonts/nerdfonts/default.nix
+++ b/pkgs/data/fonts/nerdfonts/default.nix
@@ -1,35 +1,68 @@
-{ stdenv, fetchFromGitHub, which, withFont ? "" }:
+{ stdenv
+, fetchurl
+, lib
+, unzip
+# To select only certain fonts, put a list of strings to `fonts`: every key in
+# ./shas.nix is an optional font
+, fonts ? []
+}:
+
+let
+  # both of these files are generated via ./update.sh
+  version = import ./version.nix;
+  fontsShas = import ./shas.nix;
+  knownFonts = builtins.attrNames fontsShas;
+  selectedFonts = if (fonts == []) then
+    knownFonts
+  else
+    let unknown = lib.subtractLists knownFonts fonts; in
+    if (unknown != []) then
+      throw "Unknown font(s): ${lib.concatStringsSep " " unknown}"
+    else
+      fonts
+  ;
+  selectedFontsShas = lib.attrsets.genAttrs selectedFonts (
+    fName:
+    fontsShas."${fName}"
+  );
+  srcs = lib.attrsets.mapAttrsToList (
+    fName:
+    fSha:
+    (fetchurl {
+      url = "https://github.com/ryanoasis/nerd-fonts/releases/download/v${version}/${fName}.zip";
+      sha256 = fSha;
+    })
+  ) selectedFontsShas;
+in
 
 stdenv.mkDerivation rec {
-  version = "2.1.0";
+  inherit version;
+  inherit srcs;
   pname = "nerdfonts";
-  src = fetchFromGitHub {
-    owner = "ryanoasis";
-    repo = "nerd-fonts";
-    rev = version;
-    sha256 = "1la79y16k9rwcl2zsxk73c0kgdms2ma43kpjfqnq5jlbfdj0niwg";
-  };
-  dontPatchShebangs = true;
-  buildInputs = [ which ];
-  patchPhase = ''
-    patchShebangs install.sh
-    sed -i -e 's|font_dir="\$HOME/.local/share/fonts|font_dir="$out/share/fonts/truetype|g' install.sh
+  nativeBuildInputs = [
+    unzip
+  ];
+  sourceRoot = ".";
+  buildPhase = ''
+    echo "selected fonts are ${toString selectedFonts}"
+    ls *.otf *.ttf
   '';
   installPhase = ''
-    mkdir -p $out/share/fonts/truetype
-    ./install.sh ${withFont}
+    find -name \*.otf -exec mkdir -p $out/share/fonts/opentype/NerdFonts \; -exec mv {} $out/share/fonts/opentype/NerdFonts \;
+    find -name \*.ttf -exec mkdir -p $out/share/fonts/truetype/NerdFonts \; -exec mv {} $out/share/fonts/truetype/NerdFonts \;
   '';
 
   meta = with stdenv.lib; {
-    description = ''
+    description = "Iconic font aggregator, collection, & patcher. 3,600+ icons, 50+ patched fonts";
+    longDescription = ''
       Nerd Fonts is a project that attempts to patch as many developer targeted
       and/or used fonts as possible. The patch is to specifically add a high
       number of additional glyphs from popular 'iconic fonts' such as Font
       Awesome, Devicons, Octicons, and others.
     '';
-    homepage = https://github.com/ryanoasis/nerd-fonts;
+    homepage = "https://nerdfonts.com/";
     license = licenses.mit;
-    maintainers = with maintainers; [ ];
+    maintainers = with maintainers; [ doronbehar ];
     hydraPlatforms = []; # 'Output limit exceeded' on Hydra
   };
 }