iosevka: build from source

The Iosevka builder requires Node 8, which is not supported by node2nix yet; the
included package-lock.json is processed in Nix to install the required
dependencies offline.
This commit is contained in:
Thomas Tuegel 2017-11-19 12:03:51 -06:00
parent 2110f96f9b
commit 1d89647433
No known key found for this signature in database
GPG Key ID: 22CBF5249D4B4D59
4 changed files with 1199 additions and 9 deletions

View File

@ -1,18 +1,47 @@
{ stdenv, fetchzip }:
{
stdenv, lib,
fetchFromGitHub, fetchurl,
runCommand, writeText,
nodejs, ttfautohint, otfcc
}:
with lib;
let
installPackageLock = import ./package-lock.nix { inherit fetchurl lib; };
in
let
version = "1.13.3";
in fetchzip rec {
name = "iosevka-${version}";
src = fetchFromGitHub {
owner = "be5invis";
repo ="Iosevka";
rev = "v${version}";
sha256 = "0wfhfiahllq8ngn0mybvp29cfcm7b8ndk3fyhizd620wrj50bazf";
};
in
url = "https://github.com/be5invis/Iosevka/releases/download/v${version}/iosevka-pack-${version}.zip";
stdenv.mkDerivation {
inherit name version src;
postFetch = ''
mkdir -p $out/share/fonts
unzip -j $downloadedFile \*.ttc -d $out/share/fonts/iosevka
nativeBuildInputs = [ nodejs ttfautohint otfcc ];
passAsFile = [ "installPackageLock" ];
installPackageLock = installPackageLock ./package-lock.json;
preConfigure = ''
HOME=$TMPDIR
source "$installPackageLockPath";
npm --offline rebuild
'';
sha256 = "0103rjxcp2sis42xp7fh7g8i03h5snvs8n78lgsf79g8ssw0p9d4";
installPhase = ''
fontdir=$out/share/fonts/iosevka
mkdir -p $fontdir
cp -v dist/iosevka*/ttf/*.ttf $fontdir
'';
meta = with stdenv.lib; {
homepage = https://be5invis.github.io/Iosevka/;
@ -23,6 +52,6 @@ in fetchzip rec {
'';
license = licenses.ofl;
platforms = platforms.all;
maintainers = [ maintainers.cstrahan ];
maintainers = with maintainers; [ cstrahan jfrankenau ];
};
}

1017
pkgs/data/fonts/iosevka/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,142 @@
{ lib, fetchurl }:
with lib; with builtins;
let
# Convert a base64-encoded string into a list of quads and padding.
fromBase64 = str:
let
len = stringLength str;
quads = 3 * len - 4 * padding;
padding =
if hasSuffix "==" str then 2 else
if hasSuffix "=" str then 1 else
0;
chars = stringToCharacters (substring 0 (len - padding) str);
table = {
"A" = [0 0 0];
"B" = [0 0 1];
"C" = [0 0 2];
"D" = [0 0 3];
"E" = [0 1 0];
"F" = [0 1 1];
"G" = [0 1 2];
"H" = [0 1 3];
"I" = [0 2 0];
"J" = [0 2 1];
"K" = [0 2 2];
"L" = [0 2 3];
"M" = [0 3 0];
"N" = [0 3 1];
"O" = [0 3 2];
"P" = [0 3 3];
"Q" = [1 0 0];
"R" = [1 0 1];
"S" = [1 0 2];
"T" = [1 0 3];
"U" = [1 1 0];
"V" = [1 1 1];
"W" = [1 1 2];
"X" = [1 1 3];
"Y" = [1 2 0];
"Z" = [1 2 1];
"a" = [1 2 2];
"b" = [1 2 3];
"c" = [1 3 0];
"d" = [1 3 1];
"e" = [1 3 2];
"f" = [1 3 3];
"g" = [2 0 0];
"h" = [2 0 1];
"i" = [2 0 2];
"j" = [2 0 3];
"k" = [2 1 0];
"l" = [2 1 1];
"m" = [2 1 2];
"n" = [2 1 3];
"o" = [2 2 0];
"p" = [2 2 1];
"q" = [2 2 2];
"r" = [2 2 3];
"s" = [2 3 0];
"t" = [2 3 1];
"u" = [2 3 2];
"v" = [2 3 3];
"w" = [3 0 0];
"x" = [3 0 1];
"y" = [3 0 2];
"z" = [3 0 3];
"0" = [3 1 0];
"1" = [3 1 1];
"2" = [3 1 2];
"3" = [3 1 3];
"4" = [3 2 0];
"5" = [3 2 1];
"6" = [3 2 2];
"7" = [3 2 3];
"8" = [3 3 0];
"9" = [3 3 1];
"+" = [3 3 2];
"/" = [3 3 3];
};
in
take quads (concatMap (c: table.${c}) chars);
# Convert a list of quads with padding into a base16-encoded string.
toBase16 = quads:
if length quads == 0 then "" else
if length quads == 1 then throw "toBase16: odd quads" else
let
hexad = 4 * elemAt quads 0 + elemAt quads 1;
hexits = "0123456789abcdef";
in
substring hexad 1 hexits + toBase16 (drop 2 quads);
in
let
fetchResolved = { resolved, integrity, ... }:
let args = { url = resolved; } // integrityHash integrity; in
fetchurl args;
integrityHash = integrity:
if hasPrefix "sha1-" integrity then integritySHA1 integrity else
if hasPrefix "sha512-" integrity then integritySHA512 integrity else
throw "don't understand integrity: ${integrity}";
integritySHA1 = integrity:
{ sha1 = toBase16 (fromBase64 (removePrefix "sha1-" integrity)); };
integritySHA512 = integrity:
{ sha512 = toBase16 (fromBase64 (removePrefix "sha512-" integrity)); };
in
let
depend = name: attrs@{ version, dependencies ? {}, ... }:
{
inherit name version;
src = fetchResolved attrs;
depends = mapAttrsToList depend dependencies;
};
prepareDepend = { name, src, depends, ... }:
''
unpackFile '${src}'
mv package '${name}'
mkdir -p '${name}/node_modules'
(
cd '${name}/node_modules'
${concatMapStrings prepareDepend depends}
)
'';
in
packageLockFile:
let
packageLock = fromJSON (readFile packageLockFile);
depends = mapAttrsToList depend packageLock.dependencies;
in
''
mkdir -p node_modules
(
cd node_modules
${concatMapStrings prepareDepend depends}
)
''

View File

@ -13392,7 +13392,9 @@ with pkgs;
input-fonts = callPackage ../data/fonts/input-fonts { };
iosevka = callPackage ../data/fonts/iosevka { };
iosevka = callPackage ../data/fonts/iosevka {
nodejs = nodejs-8_x;
};
ipafont = callPackage ../data/fonts/ipafont {};
ipaexfont = callPackage ../data/fonts/ipaexfont {};