I made a post about this on reddit awhile ago asking how I would do this, nobody had a answer, today I remembered about the issue and found a solution, and its absurdly simple now that I think about it, in hm (I think it’ll work on anywhere that provides a package option), you just write it like this:
dunst = {
enable = true;
package = pkgs.writeShellScriptBin "dunst" ''
if [ "$XDG_CURRENT_DESKTOP" = "KDE" ] || [ "$DESKTOP_SESSION" = "plasma" ]; then
echo "Dunst: Not starting because session is KDE Plasma."
exit 0
fi
exec ${pkgs.dunst}/bin/dunst "$@"
'';
and BAM, only works on KDE, just simple shell… and you could invert the condition to only run on KDE or change it to hyprland, hoping if anyone comes accross this niche issue, with dunst or any other package this can help, it does not even have to be about DE’s, runtime checks work for anything.
For dunst in particular you may have a problem with dbus autostarting it using the dunst.service unit, which bypasses your wrapper. You may want to patch that file as well.
If you are running with module system you are probably better off creating a higher level option that switches which desktop session you using and then doing
because of what @rnhmjoj mentions. The options based approach also allows you to chain other things off config.programs.dunst.enable without knowing what selects it, whereas by pushing this decision to runtime you’ve limited the knowledge of whether dunst is working or not to dunst.
This won’t be the correct approach, as you’re doing a buildtime check for something that can only be determined at runtime (because sessions are, for most people, chosen via the login manager).