Something went wrong. Try again.
A Zig library that finds fonts as fontconfig does, without it: the same configuration, OpenType and bitmap fonts, and the same answers.
Something went wrong. Try again.
zig-font-config flake.nix
3.6 kB · 115 lines
Nix
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us># SPDX-License-Identifier: MIT
{ description = "A Zig library that finds fonts the way fontconfig does, from fontconfig's own configuration";
inputs = { nixpkgs = { url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.zst"; }; # nixpkgs has no Zig 0.17 yet, so the compiler comes from the overlay. zig = { url = "git+https://git.jcollie.dev/jeff/zig-overlay.git"; inputs.nixpkgs.follows = "nixpkgs"; }; zon2nix = { url = "git+https://git.jcollie.dev/jeff/zon2nix.git"; inputs.nixpkgs.follows = "nixpkgs"; inputs.zig.follows = "zig"; }; };
outputs = { nixpkgs, zig, zon2nix, ... }: let inherit (nixpkgs) lib; linuxSystems = builtins.filter ( system: (lib.systems.elaborate system).isLinux ) lib.systems.flakeExposed; makePackages = system: import nixpkgs { inherit system; }; # The 0.17.0 release, rather than `master`, which moves on to the 0.18 # nightlies. zigFor = system: zig.packages.${system}."0.17.0"; forAllSystems = lib.genAttrs linuxSystems; packagesFor = system: let pkgs = makePackages system; zig_0_17 = zigFor system; in rec { zig-deps = pkgs.callPackage ./build.zig.zon.nix { inherit zig_0_17; }; zig-font-config = pkgs.callPackage ./package.nix { zig = zig_0_17; inherit zig-deps; }; default = zig-font-config; }; in { packages = forAllSystems packagesFor;
# The differential test: the same queries put to fontconfig's own # fc-match and fc-query and to this library's zfc, over the same # configuration and the same fonts, must give the same answers. checks = forAllSystems ( system: let pkgs = makePackages system; packages = packagesFor system; in { inherit (packages) zig-font-config; differential = pkgs.callPackage ./tests/differential.nix { inherit (packages) zig-font-config; }; } );
devShells = forAllSystems ( system: let pkgs = makePackages system; zig_0_17 = zigFor system; in { default = pkgs.mkShell { name = "zig-font-config"; nativeBuildInputs = [ # fc-match, fc-query and fc-list: the reference everything here # is checked against. pkgs.fontconfig # Uploads zig-out/docs to https://jeff.jcollie.page/zig-font-config/. pkgs.git-pages-cli pkgs.kcov pkgs.reuse zig_0_17 # Regenerates build.zig.zon.nix: # zon2nix --17 --nix=build.zig.zon.nix build.zig.zon # zon2nix shells out to `zig env`, so it is wrapped to find this # project's Zig rather than whatever the caller has. (pkgs.symlinkJoin { name = "zon2nix"; paths = [ zon2nix.packages.${system}.zon2nix ]; nativeBuildInputs = [ pkgs.makeWrapper ]; postBuild = '' wrapProgram $out/bin/zon2nix \ --prefix PATH : ${lib.makeBinPath [ zig_0_17 ]} ''; }) ]; }; } ); };}