systemd: merge unit definitions recursively

This removes the need for monolithic unit definitions and allows
users to modify existing units.

Example:
```
{
  systemd.user.services.owncloud-client.Unit.OnFailure = "my-notify-service";
}
```
This commit is contained in:
Cornelius Mika 2018-05-09 15:22:34 +02:00
parent 394045f68a
commit ab90d7154c

View file

@ -50,6 +50,10 @@ let
servicesStartTimeoutMs = builtins.toString cfg.servicesStartTimeoutMs; servicesStartTimeoutMs = builtins.toString cfg.servicesStartTimeoutMs;
attrsRecursivelyMerged = types.attrs // {
merge = loc: foldl' (res: def: recursiveUpdate res def.value) {};
};
in in
{ {
@ -70,26 +74,26 @@ in
services = mkOption { services = mkOption {
default = {}; default = {};
type = types.attrs; type = attrsRecursivelyMerged;
description = "Definition of systemd per-user service units."; description = "Definition of systemd per-user service units. Attrs are merged recursively.";
}; };
sockets = mkOption { sockets = mkOption {
default = {}; default = {};
type = types.attrs; type = attrsRecursivelyMerged;
description = "Definition of systemd per-user sockets"; description = "Definition of systemd per-user sockets. Attrs are merged recursively.";
}; };
targets = mkOption { targets = mkOption {
default = {}; default = {};
type = types.attrs; type = attrsRecursivelyMerged;
description = "Definition of systemd per-user targets"; description = "Definition of systemd per-user targets. Attrs are merged recursively.";
}; };
timers = mkOption { timers = mkOption {
default = {}; default = {};
type = types.attrs; type = attrsRecursivelyMerged;
description = "Definition of systemd per-user timers"; description = "Definition of systemd per-user timers. Attrs are merged recursively.";
}; };
startServices = mkOption { startServices = mkOption {