@dbnicholson
Copy link

On stateless systems like ostree, the appstream cache needs to be rebuilt at runtime after system updates. The way we've typically handled these things at Endless is to add a systemd service that uses the ConditionNeedsUpdate option. That way it runs during boot after an update but not at other times. This would allow us to ship appstream data in the OS at /usr/share/app-info.

You can see an example of this type of unit in systemd. For systems that make use of the /{etc,var}/.updated scheme, this rebuilds the linker cache after an update. On classic stateful systems that don't use that scheme, the unit never runs as it's expected other process take care of updating the linker cache. For example, dpkg or rpm post scripts.

Anyways, I think the unit would essentially be this:

[Unit]
Description=Rebuild Appstream Cache
Documentation=man:appstreamcli(8)
DefaultDependencies=no
Conflicts=shutdown.target
After=local-fs.target
Before=sysinit.target shutdown.target systemd-update-done.service
ConditionNeedsUpdate=|/var

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/appstreamcli refresh-cache

[Install]
WantedBy=multi-user.target

Does that seem like something that would be acceptable here? I can put together a PR if so.