CUPS can print various file formats, by converting inpout files into PDF and this PDF into the printer’s native language, the conversion filters are provided by cups-filters. For plain text (ASCII, UTF-8) input files there is a texttopdf
filter which generates a PDF file from plain text input. To do so it needs a standard, monospace font in case of latin letter text, some special fonts for greek, cyrillic, chinese, … The filter users fontconfig to find a suitable font in the system.
In the CUPS Snap this has to be performed inside a Snap, where one does not have access to all the systemś resources. So I decided to install the fonts into the CUPS Snap. With core18 this worked without problems, using this snapcraft.yaml
.
Now I have switched to core20 and after some adjustments it is all working so far except the texttopdf
filter which errors with
Fontconfig error: Cannot load default config file
in error_log
when one tries to print a plain text file. The filter is called by cupsd
when processing a plain text print job. I tried several things to fix this but did not succeed.
Here are the relevant parts of the new snapcraft.yaml
:
name: cups
base: core20
[...]
environment:
[...]
FONTCONFIG_FILE: /snap/cups/current/etc/fonts/fonts.conf
FONTCONFIG_PATH: /snap/cups/current/etc/fonts/conf.d
FONTCONFIG_SYSROOT: /snap/cups/current/etc/fonts
[...]
apps:
cupsd:
command: scripts/run-cupsd
[...]
daemon: simple
plugs: [network, network-bind, avahi-control, raw-usb, etc-cups]
[...]
parts:
[...]
cups-filters:
[...]
build-packages:
[...]
- libfontconfig1-dev
[...]
stage-packages:
[...]
- fonts-freefont-ttf
- fonts-arphic-uming
- fontconfig-config
[...]
override-prime: |
set -eux
perl -p -i \
-e 's:<dir>\S*/usr/share/fonts</dir>:<dir>/snap/cups/current/usr/share/fonts</dir>:;' \
-e 's:<cachedir>\S*/var/cache/fontconfig</cachedir>:<cachedir>/var/snap/cups/current/var/cache/fontconfig</cachedir>:;' \
-e 's:<(cache|)dir>/usr/\S*</(cache|)dir>::;' \
-e 's:<(cache|)dir>~\S*</(cache|)dir>::;' \
$SNAPCRAFT_STAGE/etc/fonts/fonts.conf
snapcraftctl prime
[...]
Especially I have put libfontconfig as build dependency and the fonts into the stage packages, so that they are installed in the Snap. I also have set the environment variables according to man fonts.conf
and modified the $SNAP/etc/fonts/fonts.conf to pint to the font directories inside the Snap.
In addition, in run-cupsd, the script which fires up cupsd I have set the environment variables again:
export FONTCONFIG_FILE=$SNAP/etc/fonts/fonts.conf
export FONTCONFIG_PATH=$SNAP/etc/fonts/conf.d
export FONTCONFIG_SYSROOT=$SNAP/etc/fonts
What am I doing wrong?
I do not want to plug interfaces like “desktop” as I am not sure whether they pull in a lot of unneeded stuff (especially if the CUPS Snap is used on a headless server) or opens too many potential attack points.
Anyone has any experience?