nixpkgs/pkgs/tools/misc/fontforge/default.nix
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00

83 lines
3.1 KiB
Nix

{ stdenv, fetchFromGitHub, lib, fetchpatch
, cmake, uthash, pkg-config
, python, freetype, zlib, glib, giflib, libpng, libjpeg, libtiff, libxml2, cairo, pango
, readline, woff2, zeromq
, withSpiro ? false, libspiro
, withGTK ? false, gtk3
, withGUI ? withGTK
, withPython ? true
, withExtras ? true
, Carbon, Cocoa
}:
assert withGTK -> withGUI;
stdenv.mkDerivation rec {
pname = "fontforge";
version = "20230101";
src = fetchFromGitHub {
owner = pname;
repo = pname;
rev = version;
sha256 = "sha256-/RYhvL+Z4n4hJ8dmm+jbA1Ful23ni2DbCRZC5A3+pP0=";
};
patches = [
(fetchpatch {
name = "CVE-2024-25081.CVE-2024-25082.patch";
url = "https://github.com/fontforge/fontforge/commit/216eb14b558df344b206bf82e2bdaf03a1f2f429.patch";
hash = "sha256-aRnir09FSQMT50keoB7z6AyhWAVBxjSQsTRvBzeBuHU=";
})
# https://github.com/fontforge/fontforge/pull/5423
./replace-distutils.patch
];
# use $SOURCE_DATE_EPOCH instead of non-deterministic timestamps
postPatch = ''
find . -type f -name '*.c' -exec sed -r -i 's#\btime\(&(.+)\)#if (getenv("SOURCE_DATE_EPOCH")) \1=atol(getenv("SOURCE_DATE_EPOCH")); else &#g' {} \;
sed -r -i 's#author\s*!=\s*NULL#& \&\& !getenv("SOURCE_DATE_EPOCH")#g' fontforge/cvexport.c fontforge/dumppfa.c fontforge/print.c fontforge/svg.c fontforge/splineutil2.c
sed -r -i 's#\bb.st_mtime#getenv("SOURCE_DATE_EPOCH") ? atol(getenv("SOURCE_DATE_EPOCH")) : &#g' fontforge/parsepfa.c fontforge/sfd.c fontforge/svg.c
sed -r -i 's#^\s*ttf_fftm_dump#if (!getenv("SOURCE_DATE_EPOCH")) ttf_fftm_dump#g' fontforge/tottf.c
sed -r -i 's#sprintf\(.+ author \);#if (!getenv("SOURCE_DATE_EPOCH")) &#g' fontforgeexe/fontinfo.c
'';
# do not use x87's 80-bit arithmetic, rouding errors result in very different font binaries
env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isi686 "-msse2 -mfpmath=sse";
nativeBuildInputs = [ pkg-config cmake ];
buildInputs = [
readline uthash woff2 zeromq
python freetype zlib glib giflib libpng libjpeg libtiff libxml2
]
++ lib.optionals withSpiro [ libspiro ]
++ lib.optionals withGUI [ gtk3 cairo pango ]
++ lib.optionals stdenv.hostPlatform.isDarwin [ Carbon Cocoa ];
cmakeFlags = [ "-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON" ]
++ lib.optional (!withSpiro) "-DENABLE_LIBSPIRO=OFF"
++ lib.optional (!withGUI) "-DENABLE_GUI=OFF"
++ lib.optional (!withGTK) "-DENABLE_X11=ON"
++ lib.optional withExtras "-DENABLE_FONTFORGE_EXTRAS=ON";
preConfigure = ''
# The way $version propagates to $version of .pe-scripts (https://github.com/dejavu-fonts/dejavu-fonts/blob/358190f/scripts/generate.pe#L19)
export SOURCE_DATE_EPOCH=$(date -d ${version} +%s)
'';
postInstall =
# get rid of the runtime dependency on python
lib.optionalString (!withPython) ''
rm -r "$out/share/fontforge/python"
'';
meta = with lib; {
description = "Font editor";
homepage = "https://fontforge.github.io";
platforms = platforms.all;
license = licenses.bsd3;
maintainers = [ maintainers.erictapen ];
};
}