News for hackers. Stuff that matters.
Re:Avoiding Complexity with Systemd by nh2 on Sunday June 27, 2021 @11:04AM (#27652128)
You can override NixOS's predefined systemd settings from _outside_ using NixOS module options. This allows you to change default settings that are not optimal for your use case, without having to patch NixOS itself, or write your own unit config.

For example, systemd by default permanently gives up restarting services after a few number of tries (e.g. 5), even if you have set `Restart=always`. This is suboptimal for web servers that should recover by themselves after arbitrarily long failures (e.g. network downtimes outside of your control).

On NixOS, you can, from your machine config, set:

    systemd.services.nginx.unitConfig.StartLimitIntervalSec = 0;
This sets/overrides just that specific systemd option for the existing nginx module. On other distros, you often have to resort to global mutation in `/etc` that does not compose well.

We use NixOS for our infra (having used Ansible before), and this ability to override anything cleanly and keeping defaults otherwise made for much easier to maintain infra code and less ugly/surprising compromises.

Re:Avoiding Complexity with Systemd by Arnavion on Sunday June 27, 2021 @12:25PM (#27652876)
>On other distros, you often have to resort to global mutation in `/etc` that does not compose well.

Why does this "not compose well" ?

You don't have to override the whole unit as /etc/systemd/system/nginx.service , which would have problems if two things wanted to override different parts of the original unit. Just drop an override file in /etc/systemd/system/nginx.service.d/90-restart-always.conf with that one specific config you want to override.

Re:Avoiding Complexity with Systemd by nh2 on Sunday June 27, 2021 @05:26PM (#27655573)
> Why does this "not compose well" ?

Because you cannot easily write libraries/components that do this.

In NixOS, other modules can override the options of other modules. For example, a a web app can set the nginx options that it needs, instead of requiring you (the admin) to "drop a file" in /etc.

This is one of the reasons why on Ansible Galaxy (community repository of Ansible roles) there are 527 nginx roles [1], and in NixOS there is 1 nginx module that everybody code-reuses.

[1]: https://galaxy.ansible.com/search?deprecated=false&tags=web&...

Re:Avoiding Complexity with Systemd by Arnavion on Sunday June 27, 2021 @06:27PM (#27656062)
What does

    systemd.services.nginx.unitConfig.StartLimitIntervalSec = 0;
do that it doesn't require root?

If the point is that it's not manipulating a system-level nginx service but a user-level one, then writing the systemd override file in the way I described doesn't require root either.

Re:Avoiding Complexity with Systemd by nh2 on Monday June 28, 2021 @12:47PM (#27664222)
Applying the NixOS config requires root -- that's not what it's about.

What I mean is that services can set other services' options, without you (the admin) having to to write such overrides manually.

Re:Avoiding Complexity with Systemd by Arnavion on Tuesday June 29, 2021 @06:13PM (#27682464)
Nothing prevents $service's package from creating /etc/systemd/system/nginx.service.d/90-restart-always.conf in a regular distro.