{ stdenv, fetchurl, fontforge, unzip, parallel, python3, libarchive, p7zip, }: let sfMono = fetchurl { url = "https://developer.apple.com/design/downloads/SF-Mono.dmg"; sha256 = "6d4a0b78e3aacd06f913f642cead1c7db4af34ed48856d7171a2e0b55d9a7945"; }; fontPatcher = fetchurl { url = "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.3.0/FontPatcher.zip"; sha256 = "ce4284e7d1a8816d29bb3a358e33a44e55804792e7925ed0022ba1b3ab1a9d34"; }; ligaturizer = fetchurl { url = "https://github.com/ToxicFrog/Ligaturizer/archive/refs/tags/v5.tar.gz"; sha256 = "da7c20e7622f7381e6905fbbed736dc50dd8515f412b040adbfe31dfd9b9efb4"; }; firaCode = fetchurl { url = "https://github.com/tonsky/FiraCode/releases/download/6.2/Fira_Code_v6.2.zip"; sha256 = "0949915ba8eb24d89fd93d10a7ff623f42830d7c5ffc3ecbf960e4ecad3e3e79"; }; in stdenv.mkDerivation { pname = "nerd-fonts-sf-mono-ligatures"; version = "3.3.0"; src = sfMono; buildInputs = [ fontforge unzip parallel python3 libarchive p7zip ]; unpackPhase = '' # Extract SF Mono DMG mkdir extracted 7z x ${sfMono} -oextracted # Extract package contents bsdtar xvPf extracted/SFMonoFonts/SF\ Mono\ Fonts.pkg bsdtar xvPf SFMonoFonts.pkg/Payload # Unzip FontPatcher unzip ${fontPatcher} # Unzip FiraCode unzip ${firaCode} -d FiraCode # Extract Ligaturizer bsdtar xvPf ${ligaturizer} ''; buildPhase = '' mkdir -p patched echo "Patching all fonts" parallel -j$(nproc) python ./font-patcher -c {} -out patched ::: Library/Fonts/*.otf mkdir -p otf for f in FiraCode/ttf/*.ttf; do file=$(basename "$f") base=$(echo "$file" | cut -d. -f1) fontforge -c "import fontforge; from sys import argv; f = fontforge.open(argv[1]); f.generate(argv[2])" "$f" "otf/$base.otf" done mkdir -p Ligaturizer-5/fonts/fira/distr/otf cp otf/FiraCode*.otf Ligaturizer-5/fonts/fira/distr/otf mkdir -p ligaturized echo "Ligaturizing all fonts" cd Ligaturizer-5 parallel -j$(nproc) fontforge -lang py -script ligaturize.py \ --output-dir ../ligaturized --output-name SFMonoNerdFont {} ::: ../patched/*.otf cd .. ''; installPhase = '' mkdir -p $out/share/fonts/apple cp ligaturized/*.otf $out/share/fonts/apple/ ''; meta = { description = "Monospaced variant of San Francisco patched with Nerd Fonts and Fira Code ligatures"; license = "proprietary"; maintainers = ["relms"]; platforms = ["x86_64-linux" "aarch64-linux"]; }; }