{
  stdenv,
  lib,
  pkgs,
  makeDesktopItem,
}:

let
  version = "2.5.29";
  icon = pkgs.fetchurl {
    url = "https://github.com/SteamGridDB/steam-rom-manager/blob/master/src/assets/icons/512x512.png?raw=true";
    hash = "sha256-Nx29nJ2+44AYrTLP+CNmDJFAf2sjrH7sfYhg9fJx2qo=";
  };
in
stdenv.mkDerivation {
  name = "steam-rom-manager";
  src = pkgs.fetchurl {
    url = "https://github.com/SteamGridDB/steam-rom-manager/releases/download/v${version}/Steam-ROM-Manager-${version}.AppImage";
    hash = "sha256-6ZJ+MGIgr2osuQuqD6N9NnPiJFNq/HW6ivG8tyXUhvs=";
  };
  phases = [
    "installPhase"
  ];
  installPhase = ''
    runHook preInstall
    mkdir -p $out/bin
    install --mode=0755 $src $out/bin/steam-rom-manager
    runHook postInstall
  '';
  # We have to use 555 instead of the normal 444 here because the .desktop file ends up inside $HOME on steam deck and desktop files must be either not in $HOME or must be executable, otherwise KDE Plasma refuses to execute them.
  postInstall = ''
    mkdir -p $out/share/{applications,pixmaps}
    install -m 555 -D "$desktopItem/share/applications/"* -t $out/share/applications/
    install -m 444 -D "${icon}" $out/share/pixmaps/steamrommanager.png
  '';

  desktopItem = makeDesktopItem {
    name = "steam-rom-manager";
    desktopName = "Steam Rom Manager";
    comment = "Manage additional entries in the Steam launcher.";
    categories = [
      "Application"
      "Utility"
    ];
    icon = "steamrommanager";
    type = "Application";
    exec = "steam-rom-manager";
  };
}
