Unable to add DesktopItem on custom AppImage wrapper

Hello,

I’m simply trying to wrap the AppImage of SourceGit and create a .desktop to be able to launch it from Gnome.

I’m able to launch the program using a terminal by simply writing sourcegit, but when searching for sourcegit in Gnome, I doesn’t found it.

Nix configuration

I’m using NixOS 24.11 with the stable channel and there is the relevant part of my Nix configuration.

configuration.nix:

{ pkgs, ... }:
{
  # A lot of unrelevant stuff.
  environment.systemPackages = with pkgs; [
    # Other unrelevant packages
    (callPackage ./packages/sourcegit.nix {inherit appimageTools fetchurl copyDesktopItems makeDesktopItem lib stdenv;})
  ];
  # A lot of unrelevant stuff.
}

sourcegit.nix:

#with import <nixpkgs> {}; # I also tried before with this and without the callPackage in configuration.nix without success.

{appimageTools, fetchurl, copyDesktopItems, makeDesktopItem, lib, stdenv}:
appimageTools.wrapType2 rec {
  pname = "sourcegit";
  version = "2025.03";
  arch = "amd64";
  
  src = fetchurl {
    url = "https://github.com/sourcegit-scm/sourcegit/releases/download/v${version}/sourcegit-${version}.linux.${arch}.AppImage";
    hash = "sha256-2EHLDDqb5EsZ3pea5ass1Xpx79ZpOUTxvE1D+klRsms=";
  };

  nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [
    copyDesktopItems
  ];
  
  meta = {
    description = "Opensource Git GUI client.";
    homepage = "https://github.com/sourcegit-scm/sourcegit/";
    downloadPage = "https://github.com/sourcegit-scm/sourcegit/releases/";
    license = lib.licenses.mit;
    sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
    maintainers = with lib.maintainers; [ sourcegit-scm ];
    platforms = [ "x86_64-linux" ];
    mainProgram = "sourcegit";
  };

  desktopItems = [
    (makeDesktopItem {
      name = "SourceGit";
      exec = "sourcegit";
      desktopName = "SourceGit";
    })
  ];
  extraPkgs = pkgs: with pkgs; [ icu git ];
}

Remove the inherit statement, callPackage already takes care of that.

Also, you need to set categories appropriately to use it in GNOME. See Registered Categories | Desktop Menu Specification.

Hi,

Thanks for helping.
I removed the inherit part which result in the following lines in my configuration.nix:

{ pkgs, ... }:
{
  # A lot of unrelevant stuff.
  environment.systemPackages = with pkgs; [
    # Other unrelevant packages
     (callPackage ./packages/sourcegit.nix {})
  ];
  # A lot of unrelevant stuff.
}

I also applied your suggestion about adding the category, which result in the following sourcegit.nix:

{appimageTools, fetchurl, copyDesktopItems, makeDesktopItem, lib, stdenv}:
appimageTools.wrapType2 rec {
  pname = "sourcegit";
  version = "2025.03";
  arch = "amd64";
  
  src = fetchurl {
    url = "https://github.com/sourcegit-scm/sourcegit/releases/download/v${version}/sourcegit-${version}.linux.${arch}.AppImage";
    hash = "sha256-2EHLDDqb5EsZ3pea5ass1Xpx79ZpOUTxvE1D+klRsms=";
  };

  nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [
    copyDesktopItems
  ];
  
  meta = {
    description = "Opensource Git GUI client.";
    homepage = "https://github.com/sourcegit-scm/sourcegit/";
    downloadPage = "https://github.com/sourcegit-scm/sourcegit/releases/";
    license = lib.licenses.mit;
    sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
    maintainers = with lib.maintainers; [ sourcegit-scm ];
    platforms = [ "x86_64-linux" ];
    mainProgram = "sourcegit";
  };

  
  desktopItems = [
    (makeDesktopItem {
      name = "SourceGit";
      exec = "sourcegit";
      desktopName = "SourceGit";
      categories = [ "Development" ];
    })
  ];

  extraPkgs = pkgs: with pkgs; [ icu git ];
}

To give more context, I tried with the following desktopItems in the past without success:

  dektopItems = [(makeDesktopItem {
    name = pname;
    exec = pname;
    icon = pname;
    comment = meta.description;
    desktopName = "SourceGit";
    genericName = meta.description;
    categories = [ "Development" ];
  })];

I rebuild it with sudo nixos-rebuild switch and restart my computer, but it’s still not in my GNOME applications/searchbar. I’m using other Nix packages, like Lutris, Neovim, LunarVim and Steam which can be found. so it should not be a problem between Nix and GNOME. I took a look in the nixpkgs repository and this packages didn’t seems to be using makeDesktopItem or copyDesktopItems to create their .desktop and make it available to GNOME.

I checked again for typos in my properties names, but it seems to be pretty similar to the Nixpkgs Reference Manual - makeDesktopItem - Examples.

I have a feeling that the hook copyDesktopItems is not executed for this wrapper, for some reason (which is probably between my monitor and my chair).
Do I have to do something in particular to get it working or it just magically detect the desktopItems property and make all of them available to GNOME?

Again, thank you for your time.

So I didn’t find a way to make the copyDesktopItem work and I just decided to copy the .desktop manually, which result in the following sourcegit.nix:

{appimageTools, fetchurl, makeDesktopItem, lib}:
appimageTools.wrapType2 rec {
  pname = "sourcegit";
  version = "2025.03";
  arch = "amd64";
  
  src = fetchurl {
    url = "https://github.com/sourcegit-scm/sourcegit/releases/download/v${version}/sourcegit-${version}.linux.${arch}.AppImage";
    hash = "sha256-2EHLDDqb5EsZ3pea5ass1Xpx79ZpOUTxvE1D+klRsms=";
  };

  appImageContent = appimageTools.extract {inherit pname version src;};

  meta = {
    description = "Opensource Git GUI client.";
    homepage = "https://github.com/sourcegit-scm/sourcegit/";
    downloadPage = "https://github.com/sourcegit-scm/sourcegit/releases/";
    license = lib.licenses.mit;
    sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
    maintainers = with lib.maintainers; [ sourcegit-scm ];
    platforms = [ "x86_64-linux" ];
    mainProgram = "sourcegit";
  };
  
  desktopItem = (
    makeDesktopItem {
      name = "SourceGit";
      exec = meta.mainProgram;
      icon = "com.sourcegit_scm.SourceGit";
      comment = meta.description;
      desktopName = "SourceGit";
      categories = [ "Development" ];
    });
  
  extraInstallCommands = ''
    mkdir -p $out/share/applications/
    mkdir -p $out/share/icons/hicolor/256x256/apps/
    install -m 444 -D ${appImageContent}/com.sourcegit_scm.SourceGit.png \
      $out/share/icons/hicolor/256x256/apps/com.sourcegit_scm.SourceGit.png
    cp ${desktopItem}/share/applications/*.desktop $out/share/applications/
  '';

  extraPkgs = pkgs: with pkgs; [ icu git ];
}