system.userActivationScripts and auto-restart user systemd service, rootless docker

I’ve had to manually manage this myself after any nixos-rebuild switch that would change rootless docker config. Typically I’d just systemctl --user restart docker depending on the state of the service. Why doesn’t the nix config for virtualisation.docker.rootless restart the systemd service for me after a rebuild?

Trying to do this auto-restart myself, I added to my nix config

  system.userActivationScripts = {
    dockerRootlessRestart.text = "systemctl --user restart docker.service";
  };

but this causes the systemd service, nixos-activation.service, to fail with error, systemctl not found. I’m not sure if a service that restarts a service is best practice, but nix does provide a convenient hook with the config for listening to a nixos-rebuild switch.

You probably wanted:

${pkgs.systemd}/bin/systemctl --user restart docker.service

There’s probably a better way to achieve what you want by changing thr service’s restart triggers, though. Presumably you just modified something that isn’t detected by the module as a change to the service.

1 Like