summary refs log tree commit diff
path: root/pkgs/data/fonts/iosevka
diff options
context:
space:
mode:
authorThomas Tuegel <ttuegel@mailbox.org>2017-11-19 12:29:40 -0600
committerThomas Tuegel <ttuegel@mailbox.org>2017-11-20 11:07:06 -0600
commitba9cf1f82375644e034400dd541bfbcf7c4db0f4 (patch)
tree02f99e56df736bb7b8d7d3549826552148181e7a /pkgs/data/fonts/iosevka
parent0a6b3492eeafaff36f6f721b7661db504c863103 (diff)
downloadnixpkgs-ba9cf1f82375644e034400dd541bfbcf7c4db0f4.tar
nixpkgs-ba9cf1f82375644e034400dd541bfbcf7c4db0f4.tar.gz
nixpkgs-ba9cf1f82375644e034400dd541bfbcf7c4db0f4.tar.bz2
nixpkgs-ba9cf1f82375644e034400dd541bfbcf7c4db0f4.tar.lz
nixpkgs-ba9cf1f82375644e034400dd541bfbcf7c4db0f4.tar.xz
nixpkgs-ba9cf1f82375644e034400dd541bfbcf7c4db0f4.tar.zst
nixpkgs-ba9cf1f82375644e034400dd541bfbcf7c4db0f4.zip
iosevka: accept custom build options
Diffstat (limited to 'pkgs/data/fonts/iosevka')
-rw-r--r--pkgs/data/fonts/iosevka/default.nix59
1 files changed, 52 insertions, 7 deletions
diff --git a/pkgs/data/fonts/iosevka/default.nix b/pkgs/data/fonts/iosevka/default.nix
index 6c072c16d27..d6d00227ad6 100644
--- a/pkgs/data/fonts/iosevka/default.nix
+++ b/pkgs/data/fonts/iosevka/default.nix
@@ -2,18 +2,29 @@
   stdenv, lib,
   fetchFromGitHub, fetchurl,
   runCommand, writeText,
-  nodejs, ttfautohint, otfcc
+  nodejs, ttfautohint, otfcc,
+
+  # Custom font set options.
+  # See https://github.com/be5invis/Iosevka#build-your-own-style
+  design ? [], upright ? [], italic ? [], oblique ? [],
+  # Custom font set name. Required if any custom settings above.
+  set ? null
 }:
 
-with lib;
+assert (design != []) -> set != null;
+assert (upright != []) -> set != null;
+assert (italic != []) -> set != null;
+assert (oblique != []) -> set != null;
 
 let
   installPackageLock = import ./package-lock.nix { inherit fetchurl lib; };
 in
 
+let pname = if set != null then "iosevka-${set}" else "iosevka"; in
+
 let
   version = "1.13.3";
-  name = "iosevka-${version}";
+  name = "${pname}-${version}";
   src = fetchFromGitHub {
     owner = "be5invis";
     repo ="Iosevka";
@@ -22,8 +33,23 @@ let
   };
 in
 
+with lib;
+let unwords = concatStringsSep " "; in
+
+let
+  param = name: options:
+    if options != [] then "${name}='${unwords options}'" else null;
+  config = unwords (lib.filter (x: x != null) [
+    (param "design" design)
+    (param "upright" upright)
+    (param "italic" italic)
+    (param "oblique" oblique)
+  ]);
+  custom = design != [] || upright != [] || italic != [] || oblique != [];
+in
+
 stdenv.mkDerivation {
-  inherit name version src;
+  inherit name pname version src;
 
   nativeBuildInputs = [ nodejs ttfautohint otfcc ];
 
@@ -36,11 +62,30 @@ stdenv.mkDerivation {
     npm --offline rebuild
   '';
 
+  configurePhase = ''
+    runHook preConfigure
+
+    ${optionalString custom ''make custom-config set=${set} ${config}''}
+
+    runHook postConfigure
+  '';
+
+  buildPhase = ''
+    runHook preBuild
+
+    ${if custom then ''make custom set=${set}'' else ''make''}
+
+    runHook postBuild
+  '';
+
   installPhase = ''
-    fontdir=$out/share/fonts/iosevka
+    runHook preInstall
+
+    fontdir="$out/share/fonts/$pname"
+    install -d "$fontdir"
+    install "dist/$pname/ttf"/* "$fontdir"
 
-    mkdir -p $fontdir
-    cp -v dist/iosevka*/ttf/*.ttf $fontdir
+    runHook postInstall
   '';
 
   meta = with stdenv.lib; {