How to modify files in /etc within the sandbox during flatpak build?

Hi,

when building a flatpak, is there a way to modify or add files in /etc within the sandbox?

Background: I am the maintainer of the eu.betterbird.Betterbird flatpak. Users have reported that under certain circumstances fonts are looking ugly in the flatpak app, but they look fine if the app is run outside of the sandbox. There is a known work-around to fix the issue, which involves adding a configuration file in ~/.var/app/eu.betterbird.Betterbird/config/fontconfig.
Instead of requiring every user suffering from the issue to manually apply the workaround I’d rather ship the workaround in my flatpak. I think the easiest option to achieve this would be to add a config in /etc/fonts/conf.d within the sandbox, if that is possible at all.

Best,
Martin

if that is possible at all.

No, this is unfortunately not possible. You can’t modify files outside /app during the build. A ugly workaround would be to include a script in the Flatpak that automatic which writes the file in the user save directory.

Hm, that’s unfortunate. I thought of this workaround, too, but it really is ugly: Every update of the flatpak would override changes to the config that the user may have done in the mean time. That’s not what you typically would expect from a user config.

I think the cleanest solution would be a modified version of the runtime because that’s what defines the content of /etc. But I am not sure how easy setting up a runtime is and if it’s worth the effort just to include this tiny modification in my flatpak.

Any further suggestions are highly appreciated!

Martin

Every update of the flatpak would override changes to the config that the user may have done in the mean time

Not necessarily, you can test if ~/.var/app/eu.betterbird.Betterbird/config/fontconfig/fonts.conf exists, only if not exists you copy the file. Only do the previous when running as flatpak (from inside the application you can check for the existance of /.flatpak-info)

For me checking and writing the config is far more easy, specially since it’s your application and not someone else, so you can code it in. When this is not your application you usually create a run.sh (referenced in .desktop file Exec key) which does that and then exec your-app

I think you can simply include your configuration to /app/etc/fonts/local.conf and it’ll be used by the runtime. At least that’s how I’d interpret this file: /etc/fonts/conf.d/50-flatpak.conf

1 Like

Dang, good spot! I’ve only tried /app/etc/fonts/fonts.conf so far which obviously did not work. I’ll try local.conf and report back.

Using /app/etc/fonts/local.conf works fine. Thanks all for helping me out!

Martin