How to set an app's icon in the dock on Linux? [Solved]

There’s one more important detail:

  • The name of the .desktop file must match the name of the executable it links to. Otherwise the icon doesn’t show up.

In my example above I have a crystal.desktop file pointing to the crystal binary installed via pipx. If I rename the desktop file to something like net.dafoster.Crystal.desktop then the generic gear icon shows up in the dock rather than the proper app icon!