Detect icon without altering desktop file

I’m currently working on deduplicating the snapcraft configuration for nxengine-evo (Cave Story). The plan is to reuse as much as possible between the packaging metadata for AppImage, Flatpak, and Snap (see the platform/xdg directory).
I managed to configure the snap to use the AppStream metadata. I’m now trying to also reuse the common desktop file.
The remaining issue is that snapcraft does not find the icon. The icon is specified as org.nxengine.nxengine_evo in the desktop file.

Icon org.nxengine.nxengine_evo specified in desktop file usr/share/applications/org.nxengine.nxengine_evo.desktop not found in prime directory

Is it possible to install the icon (platform/xdg/org.nxengine.nxengine_evo.png) to a location such that snapcraft will recognize it without altering the desktop file? Thanks!

That is an icon “name” and not an icon path, snapcraft cannot do much about that but just log a better warning.

@jamesh did some work to support icon names (themed icons) but from an assessment we did earlier to support this with @kenvandine we found that the support is not as complete as it should be on snapd for things to work for the desktop environments


Thanks for the quick reply! I was hoping there might be a way to move it somewhere (like snap/gui or /usr/share/icons/<?>/icon_name.png) such that snapcraft could detect it. Well, then I guess we’ll have to stick with the duplicate desktop file or use sed.

I’ve use an override-pull script for any instances where I am shipping a desktop file. In that script, like you suggest, I use sed to rewrite just the Icon= line.

1 Like

For the record, the restriction on the current code is that it doesn’t let snaps install icons with arbitrary names (similar to how snapd enforces a naming convention on desktop file IDs). If you’re happy to use icon names like snap.$snap_name.*, then it will let you do the following:

  1. provide versions at multiple resolutions, or optimised for pixel doubled 4K displays.
  2. provide specialised versions for use with particular icon themes.

The naming issue is something that we want to solve, but don’t have a timeline for yet. At this point, it will probably take the form of a snap claiming a particular “desktop prefix” and being able to install desktop files and named icons using that prefix. There’d need to be protections against installing snaps with conflicting prefixes, and it might also involve some kind of store review to publish a snap with a prefix.


And a quick rundown of how you can use the support:

  1. Rename your icon images to snap.nxengine-evo, or something matching snap.nxengine-evo.*.
  2. Have one of your parts install icons to $SNAPCRAFT_PART_INSTALL/meta/gui/icons. Treat this as a hierarchy similar to /usr/share/icons, so you might install $SNAPCRAFT_PART_INSTALL/meta/gui/icons/hicolor/256x256/snap.nxengine-evo.png.
  3. Have your desktop file reference the named icon as Icon=snap.nxengine-evo.

On install, the icon will be copied to /var/lib/snapd/desktop/icons, which should be found by tools searching $XDG_DATA_DIRS.

It obviously isn’t quite at the point where you can reuse the desktop file unchanged, and might not be worth using just yet if you only have a single icon image.

1 Like