How to change the serviceConfig of a service defined in nixpkgs from configuration.nix?

2.1k Views Asked by At

The nagios in nixpkgs has systemd.services.nagios.serviceConfig.Restart="always"; which is cluttering the journalctl -u nagios log and should be Restart="no"; instead!

MySQL fix

For MySQL this works:

systemd.services.mysql.serviceConfig = {
  Restart = "always";
  RestartSec="10s";
  StartLimitInterval="1min";
};

Since the MySQL service does not list any of the 'Restart', 'RestartSec', or 'StartLimitInterval' I suppose.

Attempted nagios fix

Using the same mechanism for nagios as for MySQL before, I try:

systemd.services.nagios.serviceConfig.Restart = "no";

Gives me a:

error: The option `systemd.services.nagios.serviceConfigRestart' defined in `/etc/nixos/configuration.nix' does not exist.
(use ‘--show-trace’ to show detailed location information)

If I updated it to:

systemd.services.nagios.serviceConfig = lib.mkForce { Restart = "no"; };

The result is that the values in systemd.services.mysql.serviceConfig are now only containing 'Restart' but lack the important 'ExecStart' and other service definitions:

journalctl -u nagios
nagios.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.

Finally using this:

systemd.services.nagios.serviceConfig = config.systemd.services.nagios.serviceConfig // { Restart = "no"; };

Give me a:

nixos-rebuild switch
error: infinite recursion encountered, at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/attrsets.nix:199:44
(use ‘--show-trace’ to show detailed location information)
2

There are 2 best solutions below

0
On

systemd.services.nagios.serviceConfig.Restart = "no";

  • should work

error: The option systemd.services.nagios.serviceConfigRestart' defined in/etc/nixos/configuration.nix' does not exist. (use ‘--show-trace’ to show detailed location information)

  • Suggests that you just accidentally omitted the . in serviceConfig.Restart

Some further explanation in case of it's of any use:

systemd.services.nagios.serviceConfig = lib.mkForce { Restart = "no"; }; the result is that the values in systemd.services.mysql.serviceConfig are now only containing 'Restart' but lack the important 'ExecStart' and other service definitions:

journalctl -u nagios nagios.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.

  • Is because you've forced replacement of serviceConfig

finally using this:

systemd.services.nagios.serviceConfig = config.systemd.services.nagios.serviceConfig // { Restart = "no"; }; give me a:

nixos-rebuild switch error: infinite recursion encountered, at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/attrsets.nix:199:44

  • Is because you're defining the value of serviceConfig to be the value of serviceConfig, which is an infinite recursion!
0
On

turns out, this had been a bug in nixpkgs, see https://github.com/NixOS/nixpkgs/pull/41446