Systemctl in sudoers file is different from systemctl from PATH

Heya!

I have the following in my configuration.nix

	security.sudo = {
		enable = true;
		extraRules = [{
			groups = [ "myuser" ];
			commands = [
			{
				command = "${pkgs.systemd}/bin/systemctl restart my-custom.service";
				options = [ "NOPASSWD" ];
			}
			];
		}];
	};

However, I noticed that sudo systemctl restart my-custom.service resulted in me still needing to fill in my password. When I run ssh myuser@server and run whereis systemctl, I notice that the path is different from the path listed in my sudoers file:

sudo -l
 (ALL : ALL) NOPASSWD: /nix/store/3qdyrj8f9wn8xk8965dkg6fgljg9n2my-systemd-255.6/bin/systemctl restart my-custom.service

And whereis systemctl

systemctl: /nix/store/0lvvpl66mnnb3lwvjn6dqv4nn76ky5gx-system-path/bin/systemctl

So I suspect that is where the error lies. Any reason why the paths differ? What is the correct path to reference in my sudo config?

You could try config.systemd.package instead of pkgs.systemd if anything is setting the former

/nix/store/...-system-path is the derivation that gets linked at /run/current-system/sw, which is the directory whose bin is on your PATH. It’s the one that combines all your environment.systemPackages into a bunch of symlinks. Not sure why whereis is resolving /run/current-system/sw/bin to /nix/store/...-system-path/bin but not /nix/store/...-system-path/bin/systemctl to /nix/store/...-systemd-255.6/bin/systemctl.

I think you could probably try allowing /run/current-system/sw/bin/systemctl instead of ${pkgs.systemd}/bin/systemctl?

Changing to /run/current-system/sw/bin/systemctl solved the issue! Thanks