From 73b8aa8bcc0fef5fc46561a26591ee1761bc58e5 Mon Sep 17 00:00:00 2001 From: Cornelius Mika Date: Wed, 9 May 2018 15:22:34 +0200 Subject: [PATCH] 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"; } ``` --- modules/systemd.nix | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/modules/systemd.nix b/modules/systemd.nix index ce3c2c1b..16939ad2 100644 --- a/modules/systemd.nix +++ b/modules/systemd.nix @@ -50,6 +50,10 @@ let servicesStartTimeoutMs = builtins.toString cfg.servicesStartTimeoutMs; + attrsRecursivelyMerged = types.attrs // { + merge = loc: foldl' (res: def: recursiveUpdate res def.value) {}; + }; + in { @@ -70,26 +74,38 @@ in services = mkOption { default = {}; - type = types.attrs; - description = "Definition of systemd per-user service units."; + type = attrsRecursivelyMerged; + description = '' + Definition of systemd per-user service units. Attributes are + merged recursively. + ''; }; sockets = mkOption { default = {}; - type = types.attrs; - description = "Definition of systemd per-user sockets"; + type = attrsRecursivelyMerged; + description = '' + Definition of systemd per-user sockets. Attributes are + merged recursively. + ''; }; targets = mkOption { default = {}; - type = types.attrs; - description = "Definition of systemd per-user targets"; + type = attrsRecursivelyMerged; + description = '' + Definition of systemd per-user targets. Attributes are + merged recursively. + ''; }; timers = mkOption { default = {}; - type = types.attrs; - description = "Definition of systemd per-user timers"; + type = attrsRecursivelyMerged; + description = '' + Definition of systemd per-user timers. Attributes are merged + recursively. + ''; }; startServices = mkOption {