Systemd service failing to run

I am trying to get something to run as soon as possible via a systemd service.

I have tried roughly the following in my configuration: = {
  description = "Mess with the gpu early on boot";
  before = [ "" ];
  script = ''
    echo smash
    echo smash | systemd-cat
  serviceConfig = {
    Type = "oneshot";
    RemainAfterExit = "yes";
    TimeoutStartSec = 300;

But I just cannot seem to get it to run at all. systemctl status gpu-thing stays it is loaded and enabled but it shows that it has not run. Nothing shows up in the various logs. I have looked at various other service declarations in the nix repo and I feel mine is similar enough. I am basically trying to get something to run when this driverctl tool runs in other distros. I just need to do a little fiddling with the gpu as early as possible to aid with some gpu passthough things. What am I missing here?

When my system is running if I do systemctl start gpu-thing then I can see it has done stuff both via systemctl status and journalctl. So I can get it running afterwards manually (and far too late) but it doesn’t run when it should.

Before= specifies only ordering and doesn’t imply that the unit should necessarily be started. You’ll still need something like WantedBy= to establish a dependency on the unit. There are a few examples of this pattern in nixpkgs.

The driverctl@.service you mention is only a template and the actual unit is created dynamically by “wanting” a specific driverctl@________.service from a udev rule.


Thanks! I switched to WantedBy and that fixed it all.