From ed2072a5206ed1f08f1f4e8f170203fc5dd4e686 Mon Sep 17 00:00:00 2001 From: pancaek <20342389+pancaek@users.noreply.github.com> Date: Tue, 27 Jan 2026 10:29:29 -0800 Subject: [PATCH] installFonts: init hook --- .../setup-hooks/install-fonts.sh | 50 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 4 ++ 2 files changed, 54 insertions(+) create mode 100644 pkgs/build-support/setup-hooks/install-fonts.sh diff --git a/pkgs/build-support/setup-hooks/install-fonts.sh b/pkgs/build-support/setup-hooks/install-fonts.sh new file mode 100644 index 000000000000..15edd18c9a36 --- /dev/null +++ b/pkgs/build-support/setup-hooks/install-fonts.sh @@ -0,0 +1,50 @@ +# shellcheck shell=bash + +# Setup hook that installs font files to their respective locations. +# +# Example usage in a derivation: +# +# { …, installFonts, … }: +# +# stdenvNoCC.mkDerivation { +# … +# outputs = [ +# "out" +# "webfont" # If .woff or .woff2 output is desired +# ]; +# +# nativeBuildInputs = [ installFonts ]; +# … +# } +# +# This hook also provides an `installFont` function that can be used to install +# additional fonts of a particular extension into their respective folder. +# +postInstallHooks+=(installFonts) + +installFont() { + if (($# != 2)); then + nixErrorLog "expected 2 arguments!" + nixErrorLog "usage: installFont fontExt outDir" + exit 1 + fi + + find -iname "*.$1" -print0 | xargs -0 -r install -m644 -D -t "$2" +} + +installFonts() { + if [ "${dontInstallFonts-}" == 1 ]; then return; fi + + installFont 'ttf' "$out/share/fonts/truetype" + installFont 'ttc' "$out/share/fonts/truetype" + installFont 'otf' "$out/share/fonts/opentype" + installFont 'bdf' "$out/share/fonts/misc" + installFont 'otb' "$out/share/fonts/misc" + installFont 'psf' "$out/share/consolefonts" + + if [ -n "${webfont-}" ]; then + installFont 'woff' "$webfont/share/fonts/woff" + installFont 'woff2' "$webfont/share/fonts/woff2" + fi + +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b0bec92c53e1..3bd749fbdfcf 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -710,6 +710,10 @@ with pkgs; makeDesktopItem = callPackage ../build-support/make-desktopitem { }; + installFonts = makeSetupHook { + name = "install-fonts-hook"; + } ../build-support/setup-hooks/install-fonts.sh; + copyPkgconfigItems = makeSetupHook { name = "copy-pkg-config-items-hook"; } ../build-support/setup-hooks/copy-pkgconfig-items.sh;