From e727049d67c5ef92ec6e3e398c814774ebfc6181 Mon Sep 17 00:00:00 2001 From: Kalah <58551020+lucannez64@users.noreply.github.com> Date: Tue, 20 Oct 2026 12:14:32 +0200 Subject: [PATCH] Fix Nix FHS text fonts and fontconfig aliases (#113) --- .github/workflows/source-check.yml | 6 +++ docs/NIX.md | 21 +++++++++ flake.nix | 73 ++++++++++++++++++++++++------ 3 files changed, 86 insertions(+), 14 deletions(-) diff --git a/.github/workflows/source-check.yml b/.github/workflows/source-check.yml index 20552db..c068e01 100644 --- a/.github/workflows/source-check.yml +++ b/.github/workflows/source-check.yml @@ -3,6 +3,12 @@ on: [push, pull_request] permissions: contents: read jobs: + nix-fonts: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@3c6342b75005b9cc7c7d4069c3e9179247c89012 # v31 + - run: nix build .#checks.x86_64-linux.fonts --no-link -L validate: runs-on: ubuntu-latest steps: diff --git a/docs/NIX.md b/docs/NIX.md index fe6e9e4..c831f34 100644 --- a/docs/NIX.md +++ b/docs/NIX.md @@ -207,6 +207,27 @@ If you start Darling manually in this shell, run `darling shutdown` there before exiting. A separately launched shell cannot reconnect to an existing Darling namespace; `darling-lol --stop` can still stop it. +### Text fonts + +The FHS environment bundles Liberation and DejaVu text fonts and uses its own +fontconfig configuration and standard aliases. It does not depend on fonts in +the host's `/usr/share/fonts`, which the FHS environment replaces. Fonts in your +user font directories remain available. This also prevents an icon-only user +font inventory from becoming the only fallback for ordinary text. + +To check font availability without starting Darling or Riot: + +```sh +nix run .#default -- fc-match sans-serif +nix run .#default -- fc-match Arial +``` + +These should select DejaVu Sans and Liberation Sans respectively. The standalone +`nix build .#checks.x86_64-linux.fonts` check verifies generic and common Windows +font aliases with both an empty home directory and icon-only user fonts. This +checks font availability; CAPTCHA text rendering still needs manual verification +in Riot's UI. + ## Files and operational limits - Workspace: `${XDG_DATA_HOME:-$HOME/.local/share}/darling-lol`. diff --git a/flake.nix b/flake.nix index 8d418d8..de2c1af 100644 --- a/flake.nix +++ b/flake.nix @@ -12,6 +12,14 @@ pkgs = nixpkgs.legacyPackages.${system}; llvmPackages = pkgs.llvmPackages_21; + # Host /etc/fonts survives buildFHSEnv, but host /usr/share/fonts does + # not. Use store paths for both text fonts and the standard alias rules. + darlingFonts = [ pkgs.liberation_ttf pkgs.dejavu_fonts ]; + darlingFontsConf = pkgs.makeFontsConf { + fontDirectories = darlingFonts; + includes = [ "${pkgs.fontconfig.out}/etc/fonts/conf.d" ]; + }; + # Python environment with dependencies required by tooling pythonEnv = pkgs.python3.withPackages ( ps: with ps; [ @@ -155,6 +163,8 @@ export DPREFIX="''${DPREFIX:-$HOME/.darling}" export LC_ALL=C.UTF-8 export LANG=C.UTF-8 + export FONTCONFIG_FILE=${darlingFontsConf} + export FONTCONFIG_PATH=${pkgs.fontconfig.out}/etc/fonts export DARLING_RUNNER_DIR=${darlingRunner}/bin export PATH="$DARLING_RUNNER_DIR:/usr/local/bin:''${PATH:-}" export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/share/pkgconfig:''${PKG_CONFIG_PATH:-}" @@ -253,20 +263,55 @@ DESKTOP_EOF }; in { - checks.${system}.packaging = pkgs.runCommand "darling-lol-packaging-tests" { - nativeBuildInputs = [ pythonEnv pkgs.bash pkgs.git pkgs.coreutils pkgs.util-linux pkgs.gawk ]; - } '' - cp -R ${darlingLol}/share/darling-lol source - chmod -R u+w source - cd source - export HOME="$TMPDIR/home" PYTHONDONTWRITEBYTECODE=1 - mkdir -p "$HOME" - # Tests use private stub binaries/repositories, never Darling itself. - python3 -m unittest discover -s tests -v - python3 scripts/validate.py - grep -q '^Terminal=true$' ${darlingLol}/share/applications/darling-lol.desktop - touch "$out" - ''; + checks.${system} = { + fonts = pkgs.runCommand "darling-lol-font-tests" { + nativeBuildInputs = [ pkgs.fontconfig ]; + } '' + export HOME="$TMPDIR/home" XDG_CONFIG_HOME="$TMPDIR/config" + export XDG_DATA_HOME="$TMPDIR/data" XDG_CACHE_HOME="$TMPDIR/cache" + export FONTCONFIG_FILE=${darlingFontsConf} + export FONTCONFIG_PATH=${pkgs.fontconfig.out}/etc/fonts + mkdir -p "$HOME" "$XDG_CONFIG_HOME" "$XDG_DATA_HOME" "$XDG_CACHE_HOME" + # Check real font selection with no host or user text fonts available. + check_font() { + actual=$(fc-match --format '%{family}' "$1") + if [ "$actual" != "$2" ]; then + echo "Font match for $1: expected $2, got $actual" >&2 + exit 1 + fi + test -r "$(fc-match --format '%{file}' "$1")" + } + check_aliases() { + check_font sans-serif 'DejaVu Sans' + check_font serif 'DejaVu Serif' + check_font monospace 'DejaVu Sans Mono' + check_font Arial 'Liberation Sans' + check_font 'Times New Roman' 'Liberation Serif' + check_font 'Courier New' 'Liberation Mono' + } + check_aliases + # Reproduce an icon-only user inventory without host text fonts. + cp -R ${pkgs.font-awesome}/share/fonts "$XDG_DATA_HOME/fonts" + fc-list --format '%{file}\n' | grep -F "$XDG_DATA_HOME/fonts/" + check_aliases + touch "$out" + ''; + + packaging = pkgs.runCommand "darling-lol-packaging-tests" { + nativeBuildInputs = [ pythonEnv pkgs.bash pkgs.git pkgs.coreutils pkgs.util-linux pkgs.gawk ]; + } '' + cp -R ${darlingLol}/share/darling-lol source + chmod -R u+w source + cd source + export HOME="$TMPDIR/home" PYTHONDONTWRITEBYTECODE=1 + mkdir -p "$HOME" + # Tests use private stub binaries/repositories, never Darling itself. + python3 -m unittest discover -s tests -v + python3 scripts/validate.py + grep -q '^Terminal=true$' ${darlingLol}/share/applications/darling-lol.desktop + touch "$out" + ''; + }; packages.${system} = { darling-lol = darlingLol;