Custom scriptlet

I searched docs but couldn’t find an answer. Is it possible to write my own scriptlet for a package without modifying the actual .rpm? Something like overwriting or adding custom systemd units in /etc/systemd/system/?

Basically I need to run a specific command whenever a specific package is upgraded using dnf.

Take a look at DNF post-transaction-actions Plugin — dnf-plugins-core 4.2.1-1 documentation

If you’re just modifying a systemd service/unit have a look at systemctl edit