summary refs log tree commit diff
path: root/pkgs/data
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2021-04-06 15:06:58 +0200
committerJan Tojnar <jtojnar@gmail.com>2021-04-06 15:28:59 +0200
commit57ced14370dac8324620c031d6e4220ef6ca8acb (patch)
tree9024f244fb45cb90b5ee77389e426cb9653395fd /pkgs/data
parent04a2b269d8921505a2969fc9ec25c1f517f2b307 (diff)
downloadnixpkgs-57ced14370dac8324620c031d6e4220ef6ca8acb.tar
nixpkgs-57ced14370dac8324620c031d6e4220ef6ca8acb.tar.gz
nixpkgs-57ced14370dac8324620c031d6e4220ef6ca8acb.tar.bz2
nixpkgs-57ced14370dac8324620c031d6e4220ef6ca8acb.tar.lz
nixpkgs-57ced14370dac8324620c031d6e4220ef6ca8acb.tar.xz
nixpkgs-57ced14370dac8324620c031d6e4220ef6ca8acb.tar.zst
nixpkgs-57ced14370dac8324620c031d6e4220ef6ca8acb.zip
input-fonts: make Nix download the source
The website generates a ZIP archive with fresh TTF files for each download,
which will have different “modified” field in the TTF metadata each time.
This makes `requireFile` useless as the ZIP file will not have a static hash.

Instead, let’s make user accept the license in Nix and download the file for them.
Then, we can post-process it and hopefully achieve a somewhat fixed output.

This is still not really reproducible since:

- the font can be updated (last update in 2015)
- the fonttools used by the server can be updated to one producing a different output
- the fonttools used by this package can be updated
- the fonttools might actually be non-deterministic

But hopefully these events are rare so it will be more stable than the ZIP produced by upstream,
which changes every time. When that happens, we can always just update it like we did before.
We do not need to worry about cache since the package is unfree.

I also added myself as a maintainer.
Diffstat (limited to 'pkgs/data')
-rw-r--r--pkgs/data/fonts/input-fonts/default.nix84
1 files changed, 66 insertions, 18 deletions
diff --git a/pkgs/data/fonts/input-fonts/default.nix b/pkgs/data/fonts/input-fonts/default.nix
index 9956325e15b..36a18c1f8f1 100644
--- a/pkgs/data/fonts/input-fonts/default.nix
+++ b/pkgs/data/fonts/input-fonts/default.nix
@@ -1,31 +1,76 @@
-{ lib, stdenv, requireFile, unzip }:
+{ lib
+, stdenv
+, fetchzip
+, python3
+, config
+, acceptLicense ? config.input-fonts.acceptLicense or false
+}:
 
-stdenv.mkDerivation {
-  pname = "input-fonts";
-  version = "2019-11-25"; # date of the download and checksum
+let
 
-  src = requireFile {
-    name = "Input-Font.zip";
-    url = "https://input.fontbureau.com/download/";
-    sha256 = "10rax2a7vzidcs7kyfg5lv5bwp9i7kvjpdcsd10p0517syijkp3b";
-  };
+  throwLicense = throw ''
+    Input is available free of charge for private/unpublished usage. This includes things like your personal coding app or for composing plain text documents.
+    To use it, you need to agree to its license: https://input.djr.com/license/
+
+    You can express acceptance by setting acceptLicense to true in your
+    configuration. Note that this is not a free license so it requires allowing
+    unfree licenses.
+
+    configuration.nix:
+      nixpkgs.config.allowUnfree = true;
+      nixpkgs.config.input-fonts.acceptLicense = true;
+
+    config.nix:
+      allowUnfree = true;
+      input-fonts.acceptLicense = true;
+
+    If you would like to support this project, consider purchasing a license at <http://input.djr.com/buy>.
+  '';
 
-  nativeBuildInputs = [ unzip ];
+  releaseDate = "2015-06-24";
 
-  phases = [ "unpackPhase" "installPhase" ];
+in
 
-  sourceRoot = ".";
+stdenv.mkDerivation rec {
+  pname = "input-fonts";
+  version = "1.2";
+
+  src =
+    assert !acceptLicense -> throwLicense;
+    fetchzip {
+      name = "input-fonts-${version}";
+      # Add .zip parameter so that zip unpackCmd can match it.
+      url = "https://input.djr.com/build/?fontSelection=whole&a=0&g=0&i=0&l=0&zero=0&asterisk=0&braces=0&preset=default&line-height=1.2&accept=I+do&email=&.zip";
+      sha256 = "BESZ4Bjgm2hvQ7oPpMvYSlE8EqvQjqHZtXWIovqyIzA=";
+      stripRoot = false;
+
+      extraPostFetch = ''
+        # Reset the timestamp to release date for determinism.
+        PATH=${lib.makeBinPath [ python3.pkgs.fonttools ]}:$PATH
+        for ttf_file in $out/Input_Fonts/*/*/*.ttf; do
+          ttx_file=$(dirname "$ttf_file")/$(basename "$ttf_file" .ttf).ttx
+          ttx "$ttf_file"
+          rm "$ttf_file"
+          touch -m -t ${builtins.replaceStrings [ "-" ] [ "" ] releaseDate}0000 "$ttx_file"
+          ttx --recalc-timestamp "$ttx_file"
+          rm "$ttx_file"
+        done
+      '';
+    };
+
+  dontConfigure = true;
+  dontBuild = true;
 
   installPhase = ''
+    runHook preInstall
+
     mkdir -p $out/share/fonts/truetype
     find Input_Fonts -name "*.ttf" -exec cp -a {} "$out"/share/fonts/truetype/ \;
     mkdir -p "$out"/share/doc
     cp -a *.txt "$out"/share/doc/
-  '';
 
-  outputHashAlgo = "sha256";
-  outputHashMode = "recursive";
-  outputHash = "15sdhqqqd4jgk80fw7ncx49avi9cxbdgyrvnrfya0066x4q4r6lv";
+    runHook postInstall
+  '';
 
   meta = with lib; {
     description = "Fonts for Code, from Font Bureau";
@@ -42,9 +87,12 @@ stdenv.mkDerivation {
       generous spacing, large punctuation, and easily distinguishable
       characters — but without the limitations of a fixed width.
     '';
-    homepage = "https://input.fontbureau.com";
+    homepage = "https://input.djr.com/";
     license = licenses.unfree;
-    maintainers = with maintainers; [ romildo ];
+    maintainers = with maintainers; [
+      jtojnar
+      romildo
+    ];
     platforms = platforms.all;
   };
 }