diff --git a/pkgs/by-name/ib/ibm-plex/hashes.nix b/pkgs/by-name/ib/ibm-plex/hashes.nix new file mode 100644 index 000000000000..d22fdab47244 --- /dev/null +++ b/pkgs/by-name/ib/ibm-plex/hashes.nix @@ -0,0 +1,15 @@ +{ + "serif" = "sha256-8ygaAeMKygYS4GCub4YUQmkh87pYHfi3s0PQ6AbaeGw="; + "sans" = "sha256-mK+8GGl2ugF2+fS6yd3p5NWPHHcKEJWiShDS3lihOlI="; + "sans-condensed" = "sha256-/aJTXmrHuoPSrtCKNodBY7I0CriayNTx5LCXw+/MFvE="; + "sans-arabic" = "sha256-qi4k7kMLftIuq87idyxq46FOD6QYycdG6j3zJmu8mhI="; + "sans-devanagari" = "sha256-K57OVqcH5r9tZx8NFEoz1P3xpUooqpF7xxJzNmnObwE="; + "sans-thai" = "sha256-JZVbvZdj+IfBthiqivOXHrvAUe392M9ECGsiJkm0saE="; + "sans-thai-looped" = "sha256-cry/Ctwt1bsrdbvWkJIYWLjsvV6a1lLFsT85znqERnw="; + "sans-tc" = "sha256-kZvzSK6fEjfVMR4kxC4lxtD7GskqvJZx8BBJVT4T9MU="; + "sans-kr" = "sha256-FsHxMvLlI4yylgG96DOZIdW2DYpk7I+c5QgkVIkNZIE="; + "sans-jp" = "sha256-hUl/SSkN6q3pDTtrY2mJepw3ljhhLJskGbxfsTl9TuI="; + "sans-hebrew" = "sha256-rTuBQYLI+6gEFTumCdaWpeoLzRoyFSmqWbXziq+UG6I="; + "mono" = "sha256-OwUmrPfEehLDz0fl2ChYLK8FQM2p0G1+EMrGsYEq+6g="; + "math" = "sha256-dJA6uqxa/yb3eLY4l39NeP0yIl2NfrbaRpf6h0/F7Xc="; +} diff --git a/pkgs/by-name/ib/ibm-plex/package.nix b/pkgs/by-name/ib/ibm-plex/package.nix index a6c7b4d29535..95d0e89dbff4 100644 --- a/pkgs/by-name/ib/ibm-plex/package.nix +++ b/pkgs/by-name/ib/ibm-plex/package.nix @@ -1,22 +1,42 @@ -{ lib, stdenvNoCC, fetchzip }: +{ + lib, + stdenvNoCC, + fetchzip, + families ? [ ], +}: +let + version = import ./version.nix; + availableFamilies = import ./hashes.nix; -stdenvNoCC.mkDerivation rec { + availableFamilyNames = builtins.attrNames availableFamilies; + selectedFamilies = if (families == [ ]) then availableFamilyNames else families; + + unknownFamilies = lib.subtractLists availableFamilyNames families; +in +assert lib.assertMsg (unknownFamilies == [ ]) "Unknown font(s): ${toString unknownFamilies}"; +stdenvNoCC.mkDerivation { pname = "ibm-plex"; - version = "6.4.0"; + inherit version; - src = fetchzip { - url = "https://github.com/IBM/plex/releases/download/v${version}/OpenType.zip"; - hash = "sha256-/aR3bu03VxenSPed6EqrGoPjWCcKT//MVtb9OC8tSRs="; - }; + srcs = builtins.map ( + family: + fetchzip { + url = "https://github.com/IBM/plex/releases/download/%40ibm%2Fplex-${family}%40${version}/ibm-plex-${family}.zip"; + hash = availableFamilies.${family}; + } + ) selectedFamilies; + + dontUnpack = true; + sourceRoot = "."; installPhase = '' runHook preInstall - - install -Dm644 */*.otf IBM-Plex-Sans-JP/unhinted/* -t $out/share/fonts/opentype - + find $srcs -type f -name '*.otf' -exec install -Dm644 {} -t $out/share/fonts/opentype \; runHook postInstall ''; + passthru.updateScript = ./update.sh; + meta = with lib; { description = "IBM Plex Typeface"; homepage = "https://www.ibm.com/plex/"; diff --git a/pkgs/by-name/ib/ibm-plex/update.sh b/pkgs/by-name/ib/ibm-plex/update.sh new file mode 100755 index 000000000000..e974a306b50d --- /dev/null +++ b/pkgs/by-name/ib/ibm-plex/update.sh @@ -0,0 +1,42 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p nix nix-prefetch jq +# shellcheck shell=bash +set -eo pipefail + +families=( + "serif" + "sans" + "sans-condensed" + "sans-arabic" + "sans-devanagari" + "sans-thai" + "sans-thai-looped" + "sans-tc" + "sans-kr" + "sans-jp" + "sans-hebrew" + "mono" + "math" +) + +version=$(curl --silent 'https://api.github.com/repos/IBM/plex/releases/latest' | jq -r '.tag_name | sub("^@ibm/[\\w-]+@"; "")') + +dirname="$(dirname "$0")" +echo \""${version}"\" >"$dirname/version-new.nix" +if diff -q "$dirname/version-new.nix" "$dirname/version.nix"; then + echo No new version available, current: "$version" + rm "$dirname/version-new.nix" + exit 0 +else + echo Updated to version "$version" + mv "$dirname/version-new.nix" "$dirname/version.nix" +fi + +printf '{\n' > "$dirname/hashes.nix" + +for family in "${families[@]}"; do + url="https://github.com/IBM/plex/releases/download/%40ibm%2Fplex-${family}%40${version}/ibm-plex-${family}.zip" + printf ' "%s" = "%s";\n' "$family" "$(nix-prefetch-url --unpack "$url" | xargs nix hash convert --hash-algo sha256)" >>"$dirname/hashes.nix" +done + +printf '}\n' >> "$dirname/hashes.nix" diff --git a/pkgs/by-name/ib/ibm-plex/version.nix b/pkgs/by-name/ib/ibm-plex/version.nix new file mode 100644 index 000000000000..f0947f091566 --- /dev/null +++ b/pkgs/by-name/ib/ibm-plex/version.nix @@ -0,0 +1 @@ +"1.1.0"