From df2c6b96577d4e3cf6105a43fb10e41b8d7e85a9 Mon Sep 17 00:00:00 2001 From: Andrei Jiroh Halili Date: Sat, 3 Oct 2026 19:07:50 +0800 Subject: [PATCH] chore(desktop): implement fix for non-Nix apps not finding system fonts/icons/themes Initially with help from Claude via https://claude.ai/chat/c29287be-3d19-452a-a2b6-15fd55de9682 on fixing font-related issues for Obsidian via Flatpak,but also checked the NixOS Wiki at https://wiki.nixos.org/wiki/Fixes_for_non-Nix_applications for the rest. Assisted-by: Claude Sonnet 5 via Claude.ai Signed-off-by: Andrei Jiroh Halili --- shared/desktop/base.nix | 1 + shared/desktop/fonts.nix | 14 ++++++++-- shared/desktop/misc-usr-fix.nix | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 shared/desktop/misc-usr-fix.nix diff --git a/shared/desktop/base.nix b/shared/desktop/base.nix index 181415b..e759ede 100644 --- a/shared/desktop/base.nix +++ b/shared/desktop/base.nix @@ -8,6 +8,7 @@ ./fonts.nix ./yubikey.nix ../flatpak.nix + ./misc-usr-fix.nix ]; # List packages installed in system profile. To search, run: diff --git a/shared/desktop/fonts.nix b/shared/desktop/fonts.nix index 30174a4..e09457c 100644 --- a/shared/desktop/fonts.nix +++ b/shared/desktop/fonts.nix @@ -4,16 +4,26 @@ config = { # enable font dirs fonts = { + # Expose all fonts under /run/current-system/sw/share/X11/fonts fontDir.enable = true; + # TODO: Sync packages with those on my home-manager config packages = with pkgs; [ + noto-fonts dejavu_fonts cascadia-code + fira + jetbrains-mono + ubuntu-sans + ubuntu-sans-mono + ibm-plex # nerd fonts (requires setting system.stateVersion to 25.05+) + nerd-fonts.noto nerd-fonts.fira-code nerd-fonts.caskaydia-mono nerd-fonts.caskaydia-cove + nerd-fonts.ubuntu ]; }; - }; -} \ No newline at end of file +}; +} diff --git a/shared/desktop/misc-usr-fix.nix b/shared/desktop/misc-usr-fix.nix new file mode 100644 index 0000000..09189b7 --- /dev/null +++ b/shared/desktop/misc-usr-fix.nix @@ -0,0 +1,47 @@ +{ pkgs, lib, config, ... }: + +let + mountOptions = [ + "ro" # read-only: this mount only ever needs to be read + "resolve-symlinks" # follow symlinks as if they were real files — + # some apps (OnlyOffice-style) refuse to read + # through symlinks under /usr/share + "x-gvfs-hide" # keep this mount out of file-manager sidebars + ]; +in +{ + # Purpose: NixOS has no /usr/share/fonts (fonts live in /nix/store and are + # symlink-farmed under /run/current-system/sw/share/...), so Flatpak's + # built-in host-font mount (/usr/share/fonts -> sandbox's /run/host/fonts) + # finds nothing. This bind-mounts your actual font set onto the FHS path + # non-Nix sandboxed apps expect, fixing tofu-box rendering for anything + # that runs (even partially) inside a Flatpak sandbox. + # + # See also: + # - https://wiki.nixos.org/wiki/Fixes_for_non-Nix_applications (NixOS Wiki docs re this situation) + # - https://claude.ai/share/aefa1d19-b347-43d6-b6ad-d1a4a0e22714 + # (original chat transcript for ~ajhalili2006: https://claude.ai/chat/c29287be-3d19-452a-a2b6-15fd55de9682) + system.fsPackages = with pkgs; [ + bindfs + ]; + + # Note that you need to set fonts.fontDir.enable to true in your NixOS config + # for this to work (it adds the fonts to the FHS path under /run/current-system/sw/share/...). See ./fonts.nix#L8 for details. + fileSystems."/usr/share/fonts" = { + device = "/run/current-system/sw/share/X11/fonts"; + fsType = "fuse.bindfs"; + options = mountOptions; + }; + + # Similar with icons and themes here + fileSystems."/usr/share/icons" = { + device = "/run/current-system/sw/share/icons"; + fsType = "fuse.bindfs"; + options = mountOptions; + }; + fileSystems."/usr/share/themes" = { + device = "/run/current-system/sw/share/themes"; + fsType = "fuse.bindfs"; + options = mountOptions; + }; +} -- knotmirror 0.0.1