Adding environment variables to a user service

I want to add an environment variable to a systemd user service to get more verbose logs from it, KDE Plasma Powerdevil in particular.

To do so I added the following to my config:

systemd.user.services.plasma-powerdevil.environment = {
    QT_LOGGING_RULES = "org.kde.powerdevil=true"; 
};

I would expect this to add that environment variable to the service, leaving everything else untouched. However, it replaces the service entirely making it not work anymore.

Before the service file looked as follows:

[Unit]
Description=Powerdevil
PartOf=graphical-session.target
After=plasma-core.target

[Service]
ExecStart=/nix/store/bagdjv9pazhybd5kf7lxdh1d0igmdhd0-powerdevil-6.2.5/libexec/org_kde_powerdevil
Type=dbus
BusName=org.kde.Solid.PowerManagement
TimeoutStopSec=5sec
Slice=background.slice
Restart=on-failure

after adding the option:

[Unit]

[Service]
Environment="LOCALE_ARCHIVE=/nix/store/z3zx69xr38jlrv875ld0i0c11njfflzi-glibc-locales-2.40-66/lib/locale/locale-archive"
Environment="PATH=/nix/store/9m68vvhnsq5cpkskphgw84ikl9m6wjwp-coreutils-9.5/bin:/nix/store/vc2d1bfy1a5y1195nq7k6p0zcm6q89nx-findutils-4.10.0/bin:/nix/store/qjsj5vnbfpbg6r7jhd7znfgmcy0arn8n-gnugrep-3.11/bin:/nix/store/3ks7b6p43dpvnlnxgvlcy2jaf1np37p2-gnused-4.9/bin:/nix/store/w9qcpyhjrxsqrps91wkz8r4mqvg9zrxc-systemd-256.10/bin:/nix/store/9m68vvhnsq5cpkskphgw84ikl9m6wjwp-coreuti>
Environment="QT_LOGGING_RULES=org.kde.powerdevil=true"
Environment="TZDIR=/nix/store/l6mypzy4rvkxd5kwzs18d88syirislib-tzdata-2024b/share/zoneinfo"

How can I add en environment variable to a user service without changing anything else?

Turns out the original unit file was probably not generated by nixos and I was able to override it’s contents using systemctl --user edit plasma-powerdevil.service

But why would you do that? I mean the whole purpose of using NixOS is that you get a reproducible system. If you reinstall now you wouldn’t receive the same system. I would rather try to find out how to solves this.

You are right, but I believe this is more KDE specific than my original question reflects. When I make the changes mentioned in the original post, the path of the systemd unit changes completely.

I have no real idea whats going on and the KDE nixos modules are also confusing enough to read that I wasn’t able to find out so far.

Since I only need the environment variable on that service temporarily it is fine to do it mutably imo, but I’d love to find out how to add it reproducibility if anyone knows how.