Setting up nvidia runtime powermanagement correctly

I’ve been figuring out how to get the nvidia driver to function in multi-gpu setups, and am stumbling across a fair few issues along the way, some in nixpkgs.

My final hurdle along the road is powermanagement. Modern cards support “finegrained” mode, which can turn off the entire card by pushing video memory into main memory. On modern kernels this should just work™, but a little bit of udev magic is required to set the card’s powermanagement to “auto” (see Automated Setup).

The hardware.nvidia.powermanagement.finegrained setting configures this (albeit without a proper package, much to my dismay).

In practice, this doesn’t seem to work. /sys/bus/pci/devices/0000:01:00.0/power/control is always set to on on boot; powermanagement works fine after setting that to auto manually.

I thought that perhaps the issue is modesetting, since that would load the driver much earlier, and tried this:

boot.initrd.services.udev = lib.mkIf config.hardware.nvidia.modesetting.enable {
  rules = lib.mkIf (!config.boot.initrd.systemd.enable) enablePowerManagement;
  packages = lib.mkIf config.boot.initrd.systemd.enable [
    enablePowerManagementPackage
  ];
};

services.udev.packages = [
  enablePowerManagementPackage
];

Where those variables contain the udev rules from the nvidia docs.

This too doesn’t work.

Has anyone seen these udev rules actually fire? Does anyone have an idea of how I could even begin debugging this?