In this case it looks like your goal is to run Element with support for Wayland. It’s not well documented yet but there’s now a built in way to do that:
If you are using Wayland you can choose to use the Ozone Wayland support in Chrome and several Electron apps by setting the environment variable NIXOS_OZONE_WL=1 (for example via environment.sessionVariables.NIXOS_OZONE_WL = "1" ). This is not enabled by default because Ozone Wayland is still under heavy development and behavior is not always flawless. Furthermore, not all Electron apps use the latest Electron versions.
Using Home Manager this would look like:
home.sessionVariables.NIXOS_OZONE_WL = "1";
This works because the Element package already includes a wrapper that automatically adds --enable-features=UseOzonePlatform and --ozone-platform=wayland when NIXOS_OZONE_WL is set.
To answer your question though, both xdg.dataFile and xdg.desktopEntries are intended for creating new files, and they’re totally unaware of any existing entries. The only way to modify the entry created by a package is to modify the package, and each package may be different so you must begin by reading its source.
This package uses makeDesktopItem and references the result in its installPhase, so you have to both override makeDesktopItem and update installPhase. The process is explained in detail here, but would look something like this:
element-desktop.overrideAttrs (e: rec {
# Add arguments to the .desktop entry
desktopItem = e.desktopItem.override (d: {
exec = "${d.exec} --example-one --example-two";
});
# Update the install script to use the new .desktop entry
installPhase = builtins.replaceStrings [ "${e.desktopItem}" ] [ "${desktopItem}" ] e.installPhase;
})
Since the ability to override makeDesktopItem is a recent addition, this probably won’t work until NixOS 22.11.
I have a different way of doing this with home-manager using home.file.
Here is an example. I like my backup software to have a very low scheduling priority, otherwise my computer stutters every time a backup starts or finishes. So I replace the exec line like so:
# My Desktop Entries Home-Manager Module
{ pkgs, ... }:
let
vorta.exec = "chrt -i 0 ionice -c 3 vorta";
vorta.filename = "com.borgbase.Vorta"; # Check /run/current-system/sw/share/applications/ for filename of the .desktop you want to modify
vorta.source = builtins.readFile "${pkgs.vorta}/share/applications/${vorta.filename}.desktop";
vorta.text = pkgs.runCommand "modified-vorta-desktop" {} ''
echo "${vorta.source}" > $out
sed -i 's|^Exec=.*|Exec=${vorta.exec}|' $out # Copy and paste this line on a new line as many times as needed, replace "Exec" with desired line of .desktop to replace, and create variable above for that line.
'';
in {
home.file = {
vorta = {
text = builtins.readFile "${vorta.text}";
target = ".local/share/applications/${vorta.filename}.desktop";
};
};
}
It’s a manual process but it’s pretty easy to copy and paste things around to modify different lines, add more desktop entries to modify etc.
I’m not smart/experienced enough to do it myself but I’d love a home manager module that automates this somehow. Something like:
# FAKE MOCKUP, DO NOT COPY/PASTE
xdg.desktopEntries.modify = [
{
package = pkgs.vorta;
replace = {
Exec = "chrt -i 0 ionice -c 3 vorta";
};
}
{
packqage = pkgs.vorta;
replace = {
Name = "Vorta No Sched Change";
Exec = "vorta";
};
}
];
# (This would generate two entries, one that would override the
# standard vorta in launchers with altered sched priority, and
# another that would launch vorta as normal when required with
# the name "Vorta No Sched Change")
# Not sure how it would handle packages that make multiple .desktops.