I set it up as a user service and after removing the specified user, it works like this:
services."notify" = {
script = ''
${pkgs.libnotify}/bin/notify-send --urgency=critical "Systemd Service has failed"
'';
environment = {
# USER = "sperber";
# HOME = "/home/sperber/";
# Display = ":0";
# DBUS_SESSION_BUS_ADDRESS = "unix:path=/run/user/%U/bus";
# DBUS_SESSION_BUS_ADDRESS = "unix:path=/run/user/1000/bus";
# XAUTHORITY = "/home/sperber/.Xauthority";
};
serviceConfig = {
Type = "oneshot";
# User = "sperber";
};
};