OnlyOffice adding font declaratively

This article tell us how to add new fonts in OnlyOffice, one of them is to put the fonts in the ~/.local/share/fonts, but the fonts must have permissions 644 (-rw-r--r--).

I can download the fonts and put the fonts in those folder but how to do that in declarative way? like included in configuration.nix or home.nix if using home-manager? Tried to create link in ~/.local/share/fonts point to /run/current-system/sw/share/X11/fonts but none of the fonts is detected in OnlyOffice.

1 Like

They probably assume regular linux. Just make sure to put your fonts to $out/share/fonts, then font-cache should catch them up eventually after installing the package through environment.systemPackages/home.packages.

There is no reason at all for a font beeing writable by anyone.

Also, if the application doesn’t use font config to look up the fonts, but doing their own thing, that’s a bug, as it behaves different from all other programs in the Linux world.

Regarding fonts, I ran this:

find /nix/store/pn3hbvg3kv3pwabp8clr55zmqvd9dfng-onlyoffice-desktopeditors-7.1.0/share -type f | xargs -I '{}' grep "/usr/share/fonts" {}
grep: /nix/store/pn3hbvg3kv3pwabp8clr55zmqvd9dfng-onlyoffice-desktopeditors-7.1.0/share/desktopeditors/converter/libPdfReader.so: binary file matches
grep: /nix/store/pn3hbvg3kv3pwabp8clr55zmqvd9dfng-onlyoffice-desktopeditors-7.1.0/share/desktopeditors/libcef.so: binary file matches

I suspected that ONLYOFFICE can’t find fonts installed declaratively because it’s looking for fonts at /usr/share/fonts instead of using fontconfig.

I created a patch for the fonts.fontDir module to create /usr/share/fonts with an activation script, but ONLYOFFICE still can’t find the fonts. There are plenty of *.ttf files in /usr/share/fonts, yet ONLYOFFICE still presents a limited list of available fonts.

I believe the problem comes from upstream. In short, the code which reads directories, which is used when reading the files in /usr/share/fonts, doesn’t handle symlinks.

See The core function Directory::GetFiles2 (documentserver-generate-allfonts) does not handle symbolic links · Issue #1859 · ONLYOFFICE/DocumentServer · GitHub

Once that issue is resolved all we need is an additional option in fonts.fontDir to create /usr/share/fonts. I’ve got that code working.

Note that that’s a pretty significant wart; you’re reducing reproducibilty. You will no longer be able to have fonts only for specific applications, or multiple versions of the same font.

Similar suggestions about just creating /bin/bash are always turned down. You can carry it downstream as a workaround, obviously, but I don’t think this should be merged.

It would be much better to just teach onlyoffice to respect fontconfig, or maybe to package it with an fhsUserEnv.

I got it packaged to run with fhsUserEnv using a NixOS module: https://github.com/emmanuelrosa/erosanix/blob/6a2a83b2f0a6a3646bbe3f079a5fa1aad7e71d9f/modules/onlyoffice.nix

fontconfig support in onlyoffice would of course be a better option.

1 Like