How to add flags to an existing program .desktop?

The package is signal-desktop. At the moment i have it like this in my config:

(pkgs.signal-desktop.override {
     commandLineArgs = [ "--use-tray-icon" ];
})

It is working but i get the warning that it has been deprecated and will be removed.

evaluation warning: `commandLineArgs` has been deprecated and will be removed in the future. Consider creating a wrapper script or a desktop entry with your desired flags.

My problem is that i don’t want to have two start menu entries for signal if i create an extra desktop entry.
How can i add the startup flag without having two “Signal” programs in my startup menu?

1 Like

You can use this overlay. The content is copied from current nixpkgs with the arg added.

    (final: prev: {
      signal-desktop = prev.signal-desktop.overrideAttrs (final: inner-prev: {
        desktopItems = [
          (prev.makeDesktopItem {
            name = "signal";
            desktopName = "Signal";
            exec = "${final.meta.mainProgram} %U --use-tray-icon";
            type = "Application";
            terminal = false;
            icon = "signal-desktop";
            comment = "Private messaging from your desktop";
            startupWMClass = "signal";
            mimeTypes = [
              "x-scheme-handler/sgnl"
              "x-scheme-handler/signalcaptcha"
            ];
            categories = [
              "Network"
              "InstantMessaging"
              "Chat"
            ];
          })
        ];
      });
    })

The generated desktop entry looks like this:

[Desktop Entry]
Categories=Network;InstantMessaging;Chat
Comment=Private messaging from your desktop
Exec=signal-desktop %U --use-tray-icon
Icon=signal-desktop
MimeType=x-scheme-handler/sgnl;x-scheme-handler/signalcaptcha
Name=Signal
StartupWMClass=signal
Terminal=false
Type=Application
Version=1.5
2 Likes

Thank you <3
it looks like this now:

    home.packages = [
        (pkgs.signal-desktop.overrideAttrs (final: inner-prev: {
            desktopItems = [
              (pkgs.makeDesktopItem {
                name = "signal";
                desktopName = "Signal";
                exec = "${final.meta.mainProgram} --use-tray-icon %U";
                type = "Application";
                terminal = false;
                icon = "signal-desktop";
                comment = "Private messaging from your desktop";
                startupWMClass = "signal";
                mimeTypes = [
                  "x-scheme-handler/sgnl"
                  "x-scheme-handler/signalcaptcha"
                ];
                categories = [
                  "Network"
                  "InstantMessaging"
                  "Chat"
                ];
              })
            ];
          })
        )
    ];

That’s the worst possible solution to this problem. It forces full rebuilds because you’re overriding the original package.

Using an overlay to apply the override is also completely overkill for a simple leaf package, which is going to be the case for all packages where you want to use a .desktop file. But you shouldn’t be overriding to begin with, and @gamebeaker already corrected that.

The good way to do this is to follow the xdg spec’s intended mechanism, add a .desktop file with the same name to a higher-priority path.

So, for example, using home-manager:

{
  xdg.dataFile."applications/signal.desktop" = pkgs.makeDesktopItem {
    name = "signal";
    desktopName = "Signal";
    exec = "signal --use-tray-icon %U";
    # ...
  };
}

You should also never use the fully qualified binary path in .desktop files, because DEs do silly things with these files that can result in them becoming non-symlinks and eventually breaking (hence I don’t use lib.getExe in my example). The file works fine as long as a binary with that name is in $PATH.

If you must include the desktop file in the package, at least use symlinkJoin and friends instead of overrideAttrs so that you don’t have to rebuild the package:

{ pkgs, ... }: {
  environment.systemPackages = [
    (pkgs.symlinkJoin {
      name = "signal-with-edited-desktopfile";
      paths = [
        pkgs.signal
        (pkgs.makeDesktopItem { ... })
      ];
    })
  ];
}

Note that this causes a path collision. I forget off the top of my head whether you need buildEnv to resolve that.

3 Likes

Thanks for the tipp to prevent rebuilds.
I made it like this:

    xdg.dataFile."applications/signal.desktop".enable = true;
    xdg.dataFile."applications/signal.desktop".text = ''
      [Desktop Entry]
      Categories=Network;InstantMessaging;Chat
      Comment=Private messaging from your desktop
      Exec=signal-desktop --use-tray-icon %U
      Icon=signal-desktop
      MimeType=x-scheme-handler/sgnl;x-scheme-handler/signalcaptcha
      Name=Signal
      StartupWMClass=signal
      Terminal=false
      Type=Application
    '';
1 Like

Yeah, I also find just writing out the string easier than using makeDesktopItem.

You can consider using builtins.toTOML to convert nix to a TOML string if you want to use nix functions (the format isn’t quite TOML, but mostly compatible).

But that’s just cosmetics :wink:

1 Like