From 68464b6440ed0e2d2b16872b88160082919dfa4c Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sat, 7 Dec 2019 17:22:14 +0100 Subject: [PATCH 1/6] gohufont: generate opentype files --- pkgs/data/fonts/gohufont/default.nix | 33 ++++++++++++++-------------- pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/pkgs/data/fonts/gohufont/default.nix b/pkgs/data/fonts/gohufont/default.nix index e4e9954d1187..9715e42abfe7 100644 --- a/pkgs/data/fonts/gohufont/default.nix +++ b/pkgs/data/fonts/gohufont/default.nix @@ -1,42 +1,41 @@ { stdenv, fetchurl, fetchFromGitHub , mkfontdir, mkfontscale, bdf2psf, bdftopcf +, fonttosfnt }: stdenv.mkDerivation rec { pname = "gohufont"; version = "2.1"; - src = fetchurl { - url = "https://font.gohu.org/${pname}-${version}.tar.gz"; - sha256 = "10dsl7insnw95hinkcgmp9rx39lyzb7bpx5g70vswl8d6p4n53bm"; - }; - - bdf = fetchFromGitHub { + src = fetchFromGitHub { owner = "hchargois"; repo = "gohufont"; rev = "cc36b8c9fed7141763e55dcee0a97abffcf08224"; sha256 = "1hmp11mrr01b29phw0xyj4h9b92qz19cf56ssf6c47c5j2c4xmbv"; }; - nativeBuildInputs = [ mkfontdir mkfontscale bdf2psf bdftopcf ]; + nativeBuildInputs = + [ mkfontdir mkfontscale bdf2psf bdftopcf fonttosfnt ]; buildPhase = '' - # convert bdf to psf fonts + # convert bdf fonts to psf build=$(pwd) mkdir psf cd ${bdf2psf}/share/bdf2psf - for i in $bdf/*.bdf; do + for i in $src/*.bdf; do + name=$(basename $i .bdf) bdf2psf \ --fb "$i" standard.equivalents \ ascii.set+useful.set+linux.set 512 \ - "$build/psf/$(basename $i .bdf).psf" + "$build/psf/$name.psf" done cd $build - # convert hidpi variant to pcf - for i in $bdf/hidpi/*.bdf; do - name=$(basename $i .bdf).pcf - bdftopcf -o "$name" "$i" + # convert bdf fonts to pcf and otb + for i in *.bdf $src/hidpi/*.bdf; do + name=$(basename $i .bdf) + bdftopcf -o "$name.pcf" "$i" + fonttosfnt -v -o "$name.otb" "$i" || true done ''; @@ -46,10 +45,10 @@ stdenv.mkDerivation rec { mkdir -p "$fontDir" mv -t "$fontDir" psf/*.psf - # install the pcf fonts (for xorg applications) + # install the pcf and otb fonts (for xorg applications) fontDir="$out/share/fonts/misc" mkdir -p "$fontDir" - mv -t "$fontDir" *.pcf.gz *.pcf + mv -t "$fontDir" *.pcf *.otb cd "$fontDir" mkfontdir @@ -58,7 +57,7 @@ stdenv.mkDerivation rec { outputHashAlgo = "sha256"; outputHashMode = "recursive"; - outputHash = "0kl7k8idl0fnsap2c4j02i33z017p2s4gi2cgspy6ica46fczcc1"; + outputHash = "0j9fhvzkascpb5y8lc1pmmmgd74apgw9mimbj0bk2chcbfsi852p"; meta = with stdenv.lib; { description = '' diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index c0c475483078..44b17172e8ef 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17493,7 +17493,7 @@ in geolite-legacy = callPackage ../data/misc/geolite-legacy { }; - gohufont = callPackage ../data/fonts/gohufont { }; + gohufont = callPackage ../data/fonts/gohufont { inherit (xorg) fonttosfnt mkfontdir; }; gnome-user-docs = callPackage ../data/documentation/gnome-user-docs { }; From 8784637f12d1cd4678d44373da93841e260c1e8c Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Fri, 7 Feb 2020 10:02:17 +0100 Subject: [PATCH 2/6] bdf2psf: fix for cross compilation --- pkgs/tools/misc/bdf2psf/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/tools/misc/bdf2psf/default.nix b/pkgs/tools/misc/bdf2psf/default.nix index defdd9494e51..07bc5de371f3 100644 --- a/pkgs/tools/misc/bdf2psf/default.nix +++ b/pkgs/tools/misc/bdf2psf/default.nix @@ -9,7 +9,7 @@ stdenv.mkDerivation rec { sha256 = "10c0rbhqscizfa063m6mms31i0knh25bxr35s008b6mp5pxr33mc"; }; - buildInputs = [ dpkg ]; + nativeBuildInputs = [ dpkg ]; dontConfigure = true; dontBuild = true; From 3f29e19a48ba5ae78359650c04854fd75884eaef Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Fri, 7 Feb 2020 10:53:23 +0100 Subject: [PATCH 3/6] gohufont: fix for cross compilation --- pkgs/top-level/all-packages.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 44b17172e8ef..90c390ba4156 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17493,7 +17493,8 @@ in geolite-legacy = callPackage ../data/misc/geolite-legacy { }; - gohufont = callPackage ../data/fonts/gohufont { inherit (xorg) fonttosfnt mkfontdir; }; + gohufont = callPackage ../data/fonts/gohufont + { inherit (buildPackages.xorg) fonttosfnt mkfontdir; }; gnome-user-docs = callPackage ../data/documentation/gnome-user-docs { }; From 1cc11b98f15c6cf6e4012c21cbdfcc1b4279796c Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Fri, 7 Feb 2020 18:20:47 +0100 Subject: [PATCH 4/6] xorg.fonttosfnt: add patch to fix uninitialized memory bug --- .../x11/xorg/fix-uninitialised-memory.patch | 61 +++++++++++++++++++ pkgs/servers/x11/xorg/overrides.nix | 5 ++ 2 files changed, 66 insertions(+) create mode 100644 pkgs/servers/x11/xorg/fix-uninitialised-memory.patch diff --git a/pkgs/servers/x11/xorg/fix-uninitialised-memory.patch b/pkgs/servers/x11/xorg/fix-uninitialised-memory.patch new file mode 100644 index 000000000000..53f22d7f39cf --- /dev/null +++ b/pkgs/servers/x11/xorg/fix-uninitialised-memory.patch @@ -0,0 +1,61 @@ +From 51e8117654fb092ae5412d7aa184bfc6b498c954 Mon Sep 17 00:00:00 2001 +From: rnhmjoj +Date: Fri, 7 Feb 2020 17:46:54 +0100 +Subject: [PATCH 1/2] Fix incorrect error handling in macTime() + +mktime() and time() return (time_t -1) to signal an error. +Checking for negative values will incorrectly assume an error +happened for any calendar date before the unix epoch. +--- + util.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/util.c b/util.c +index bcbfa2f..4482c9a 100644 +--- a/util.c ++++ b/util.c +@@ -213,10 +213,10 @@ macTime(int *hi, unsigned *lo) + tm.tm_isdst = -1; + + macEpoch = mktime_gmt(&tm); +- if(macEpoch < 0) return -1; ++ if(macEpoch == -1) return -1; + + current = time(NULL); +- if(current < 0) ++ if(current == -1) + return -1; + + if(current < macEpoch) { +-- +2.23.0 + +From 81a61c049e6de80120531f0770b22e7637c9acb9 Mon Sep 17 00:00:00 2001 +From: rnhmjoj +Date: Fri, 7 Feb 2020 17:47:52 +0100 +Subject: [PATCH 2/2] Fix uninitialised memory write + +If macTime() fails write zeros instead of unitialized memory to +the date fields. +--- + write.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/write.c b/write.c +index 318adef..c8a86e4 100644 +--- a/write.c ++++ b/write.c +@@ -434,8 +434,8 @@ fixupChecksum(FILE *out, int full_length, int head_position) + static int + writehead(FILE* out, FontPtr font) + { +- int time_hi; +- unsigned time_lo; ++ int time_hi = 0; ++ unsigned time_lo = 0; + + macTime(&time_hi, &time_lo); + +-- +2.23.0 + diff --git a/pkgs/servers/x11/xorg/overrides.nix b/pkgs/servers/x11/xorg/overrides.nix index 7a9ffcfc6469..2261831586a5 100644 --- a/pkgs/servers/x11/xorg/overrides.nix +++ b/pkgs/servers/x11/xorg/overrides.nix @@ -22,6 +22,11 @@ self: super: buildInputs = attrs.buildInputs ++ [ self.xorgproto ]; }); + fonttosfnt = super.fonttosfnt.overrideAttrs (attrs: { + # https://gitlab.freedesktop.org/xorg/app/fonttosfnt/merge_requests/6 + patches = [ ./fix-uninitialised-memory.patch ]; + }); + bitmap = super.bitmap.overrideAttrs (attrs: { nativeBuildInputs = attrs.nativeBuildInputs ++ [ makeWrapper ]; postInstall = '' From 96606b67faea751ac20c49043e247ed5822ab991 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Fri, 7 Feb 2020 18:21:29 +0100 Subject: [PATCH 5/6] gohufont: make fonttosfnt deterministic --- pkgs/data/fonts/gohufont/default.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkgs/data/fonts/gohufont/default.nix b/pkgs/data/fonts/gohufont/default.nix index 9715e42abfe7..ec36d9230f5b 100644 --- a/pkgs/data/fonts/gohufont/default.nix +++ b/pkgs/data/fonts/gohufont/default.nix @@ -1,6 +1,6 @@ { stdenv, fetchurl, fetchFromGitHub , mkfontdir, mkfontscale, bdf2psf, bdftopcf -, fonttosfnt +, fonttosfnt, libfaketime }: stdenv.mkDerivation rec { @@ -15,7 +15,9 @@ stdenv.mkDerivation rec { }; nativeBuildInputs = - [ mkfontdir mkfontscale bdf2psf bdftopcf fonttosfnt ]; + [ mkfontdir mkfontscale bdf2psf bdftopcf + fonttosfnt libfaketime + ]; buildPhase = '' # convert bdf fonts to psf @@ -35,7 +37,7 @@ stdenv.mkDerivation rec { for i in *.bdf $src/hidpi/*.bdf; do name=$(basename $i .bdf) bdftopcf -o "$name.pcf" "$i" - fonttosfnt -v -o "$name.otb" "$i" || true + faketime -f "1970-01-01 00:00:01" fonttosfnt -v -o "$name.otb" "$i" || true done ''; @@ -57,7 +59,7 @@ stdenv.mkDerivation rec { outputHashAlgo = "sha256"; outputHashMode = "recursive"; - outputHash = "0j9fhvzkascpb5y8lc1pmmmgd74apgw9mimbj0bk2chcbfsi852p"; + outputHash = "028mq0j6w76isv4ycj1jzx7ih9d9cz5012np7f1pf3bvnvw3ajw2"; meta = with stdenv.lib; { description = '' From c5a0d66eb7cd17880b6238541d4189da6987e711 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Fri, 7 Feb 2020 22:49:24 +0100 Subject: [PATCH 6/6] gohufont: split outputs into out and otb --- pkgs/data/fonts/gohufont/default.nix | 34 ++++++++++++++++------------ pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/pkgs/data/fonts/gohufont/default.nix b/pkgs/data/fonts/gohufont/default.nix index ec36d9230f5b..b331edf7aa1e 100644 --- a/pkgs/data/fonts/gohufont/default.nix +++ b/pkgs/data/fonts/gohufont/default.nix @@ -1,5 +1,5 @@ { stdenv, fetchurl, fetchFromGitHub -, mkfontdir, mkfontscale, bdf2psf, bdftopcf +, mkfontscale, bdf2psf, bdftopcf , fonttosfnt, libfaketime }: @@ -15,7 +15,7 @@ stdenv.mkDerivation rec { }; nativeBuildInputs = - [ mkfontdir mkfontscale bdf2psf bdftopcf + [ mkfontscale bdf2psf bdftopcf fonttosfnt libfaketime ]; @@ -33,33 +33,37 @@ stdenv.mkDerivation rec { done cd $build - # convert bdf fonts to pcf and otb + # convert bdf fonts to pcf for i in *.bdf $src/hidpi/*.bdf; do name=$(basename $i .bdf) bdftopcf -o "$name.pcf" "$i" - faketime -f "1970-01-01 00:00:01" fonttosfnt -v -o "$name.otb" "$i" || true + done + + # convert unicode bdf fonts to otb + for i in *-uni*.bdf $src/hidpi/*-uni*.bdf; do + name=$(basename $i .bdf) + faketime -f "1970-01-01 00:00:01" \ + fonttosfnt -v -o "$name.otb" "$i" done ''; installPhase = '' # install the psf fonts (for the virtual console) fontDir="$out/share/consolefonts" - mkdir -p "$fontDir" - mv -t "$fontDir" psf/*.psf + install -D -m 644 -t "$fontDir" psf/*.psf - # install the pcf and otb fonts (for xorg applications) + # install the pcf fonts (for xorg applications) fontDir="$out/share/fonts/misc" - mkdir -p "$fontDir" - mv -t "$fontDir" *.pcf *.otb + install -D -m 644 -t "$fontDir" *.pcf + mkfontdir "$fontDir" - cd "$fontDir" - mkfontdir - mkfontscale + # install the otb fonts (for gtk applications) + fontDir="$otb/share/fonts/misc" + install -D -m 644 -t "$fontDir" *.otb + mkfontdir "$fontDir" ''; - outputHashAlgo = "sha256"; - outputHashMode = "recursive"; - outputHash = "028mq0j6w76isv4ycj1jzx7ih9d9cz5012np7f1pf3bvnvw3ajw2"; + outputs = [ "out" "otb" ]; meta = with stdenv.lib; { description = '' diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 90c390ba4156..c292398c9c62 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17494,7 +17494,7 @@ in geolite-legacy = callPackage ../data/misc/geolite-legacy { }; gohufont = callPackage ../data/fonts/gohufont - { inherit (buildPackages.xorg) fonttosfnt mkfontdir; }; + { inherit (buildPackages.xorg) fonttosfnt mkfontscale; }; gnome-user-docs = callPackage ../data/documentation/gnome-user-docs { };