From d3025ee8c62cba6e92de8d3900beb73889ca01ca Mon Sep 17 00:00:00 2001 From: V Date: Fri, 22 May 2020 00:44:58 +0200 Subject: [PATCH] iosevka-bin: add support for variants This adds the ability to select a specific prebuilt variant. It also adds an updater script for generating their hashes. Additionally, switching to TTC files reduces the package size by an order of magnitude. Example usage: fonts.fonts = with pkgs; [ (iosevka-bin.override { variant = "ss10"; }) (iosevka-bin.override { variant = "sparkle"; }) (iosevka-bin.override { variant = "aile"; }) ]; --- pkgs/data/fonts/iosevka/bin.nix | 37 ++++++++++++++++++++-------- pkgs/data/fonts/iosevka/update.sh | 28 +++++++++++++++++++++ pkgs/data/fonts/iosevka/variants.nix | 24 ++++++++++++++++++ 3 files changed, 79 insertions(+), 10 deletions(-) create mode 100755 pkgs/data/fonts/iosevka/update.sh create mode 100644 pkgs/data/fonts/iosevka/variants.nix diff --git a/pkgs/data/fonts/iosevka/bin.nix b/pkgs/data/fonts/iosevka/bin.nix index 0f88aa05e4cf..c3e77c1051fb 100644 --- a/pkgs/data/fonts/iosevka/bin.nix +++ b/pkgs/data/fonts/iosevka/bin.nix @@ -1,20 +1,35 @@ -{ stdenv, fetchzip }: +{ stdenv, lib, fetchurl, unzip +, variant ? "" +}: let - version = "3.4.6"; -in fetchzip { - name = "iosevka-bin-${version}"; + name = "iosevka" + lib.optionalString (variant != "") "-" + variant; - url = "https://github.com/be5invis/Iosevka/releases/download/v${version}/ttc-iosevka-${version}.zip"; + variantHashes = import ./variants.nix; + validVariants = map (lib.removePrefix "iosevka-") + (builtins.attrNames (builtins.removeAttrs variantHashes [ "iosevka" ])); +in stdenv.mkDerivation rec { + pname = "${name}-bin"; + version = "3.7.1"; - postFetch = '' + src = fetchurl { + url = "https://github.com/be5invis/Iosevka/releases/download/v${version}/ttc-${name}-${version}.zip"; + sha256 = variantHashes.${name} or (throw '' + No such variant "${variant}" for package iosevka-bin. + Valid variants are: ${lib.concatStringsSep ", " validVariants}. + ''); + }; + + nativeBuildInputs = [ unzip ]; + + phases = [ "unpackPhase" ]; + + unpackPhase = '' mkdir -p $out/share/fonts - unzip -j $downloadedFile \*.ttc -d $out/share/fonts/truetype + unzip -d $out/share/fonts/truetype $src ''; - sha256 = "1nab49gkpxahwvvw39xcc32q425qkccr7ffmz87jbcdv71qy7pp9"; - - meta = with stdenv.lib; { + meta = with lib; { homepage = "https://be5invis.github.io/Iosevka/"; downloadPage = "https://github.com/be5invis/Iosevka/releases"; description = '' @@ -25,4 +40,6 @@ in fetchzip { platforms = platforms.all; maintainers = [ maintainers.cstrahan ]; }; + + passthru.updateScript = ./update.sh; } diff --git a/pkgs/data/fonts/iosevka/update.sh b/pkgs/data/fonts/iosevka/update.sh new file mode 100755 index 000000000000..df78c62a6ce8 --- /dev/null +++ b/pkgs/data/fonts/iosevka/update.sh @@ -0,0 +1,28 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p curl jq + +set -e + +release=$(curl -s https://api.github.com/repos/be5invis/Iosevka/releases/latest) + +oldVersion=$(nix-instantiate --eval -E 'with import ./. {}; lib.getVersion iosevka-bin' | tr -d '"') +version=$(echo "$release" | jq -r .tag_name | tr -d v) + +if test "$oldVersion" = "$version"; then + echo "New version same as old version, nothing to do." >&2 + exit 0 +fi + +file=$(nix-instantiate --eval -A iosevka-bin.meta.position | sed -r 's/^"(.*):[0-9]+"$/\1/') +sed -i "s/$oldVersion/$version/" "$file" + +{ + echo '# This file was autogenerated. DO NOT EDIT!' + echo '{' + for asset in $(echo "$release" | jq -r '.assets[].name | select(startswith("ttc"))'); do + printf ' %s = "%s";\n' \ + $(echo "$asset" | sed -r "s/^ttc-(.*)-$version.zip$/\1/") \ + $(nix-prefetch-url "https://github.com/be5invis/Iosevka/releases/download/v$version/$asset") + done + echo '}' +} >$(dirname "$file")/variants.nix diff --git a/pkgs/data/fonts/iosevka/variants.nix b/pkgs/data/fonts/iosevka/variants.nix new file mode 100644 index 000000000000..b3fd986c4caf --- /dev/null +++ b/pkgs/data/fonts/iosevka/variants.nix @@ -0,0 +1,24 @@ +# This file was autogenerated. DO NOT EDIT! +{ + iosevka = "0h226f32nwlqnsdc86bwk2wcdl2hsq5q1s2ln6dsf9m7w8ajn0nr"; + iosevka-aile = "05k3h7n7mkpdsjcxha27vjj503b4129jd90wj8qyk5h0nrgy1rc6"; + iosevka-curly = "0fxcc99n9ghkdjmfxba9mg4fc0dwlvnnxlmc618jv6s3k2xn7sza"; + iosevka-curly-slab = "1qgxyw5v91l4cw3mvqzagk9amyy63iqh72bnsz63daxgss3fpsab"; + iosevka-etoile = "184rjidnjayv5wsrxxxf39mvdcjafdwcvp0h4rfniy9s0ifrwjvf"; + iosevka-slab = "1cbrv5pyhnvwrdaj8r011igw2yjgzzigd82g1r10d348lk64wja1"; + iosevka-sparkle = "124jnjzffnfw58b78svw8rzgal10z5nspwc267pvq7q0f2ak1wpp"; + iosevka-ss01 = "18ckb0ch4za4vgwqz8azx8vhg9v9a922ffbckrbmy8n5bi03dl7w"; + iosevka-ss02 = "0cwm2jdni5m9z0xagpmq9vvjp3yvin7c7bnavsj15yfvpq8b8qsp"; + iosevka-ss03 = "1yzbvkr726f8mm024qzy2hdd7nz4kymgjm0cj5208c57bln0byr2"; + iosevka-ss04 = "1kpz84a1cb39rxc87whw0fh0k9ak2qbcq59hm425da2acf27a648"; + iosevka-ss05 = "1xnnm96jnw90mhwylsw1ad6m8pr4r1bd02l7g82m5hmr7bc4b7dd"; + iosevka-ss06 = "1raw01ijiawaqxfmj0m8z8jrb2ns7vzy68lak63mss8j35xzg1l5"; + iosevka-ss07 = "0bjhjwjif7qw6wyyrzfg2pdvy1b070k053ndmjard6sh1rcln02d"; + iosevka-ss08 = "1qwgk8riff57np4hlmd0kcl9bx511x9zmnlrjq3ilfn6abdwgm7i"; + iosevka-ss09 = "0sfnhmcrsv1v7l756hx70y1mrp35fbs6wrsczw4vxfbbaigs767r"; + iosevka-ss10 = "10n70z7588h8y2z274vjn6hvzc7lg87znibcmkk2brmx2g5bw2wl"; + iosevka-ss11 = "0mnyd04vdqr8jm3syv6ddrn61f27k91kxkdy86pp34xaac2ipmm0"; + iosevka-ss12 = "1f8pn2220s6r566b40ncnqrfmfdhnlr0nkvzj9swgvx66jr8mlhj"; + iosevka-ss13 = "1py5qgfqm9wp9pzcxg83mydvf3r6nhrqi21d0fvmnk04ghk1psd6"; + iosevka-ss14 = "0z47kqicd26x5v94zy97xyl277v0s6856pbllfn1gv92ax2dg5cy"; +}