From f4fb3d47e765608dc9edec91281d7a2c90c442be Mon Sep 17 00:00:00 2001 From: Ryan Horiguchi Date: Sun, 22 Dec 2024 20:33:18 +0100 Subject: [PATCH] Add random delay to infomaniak updater --- modules/default/infomaniak.nix | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/modules/default/infomaniak.nix b/modules/default/infomaniak.nix index e34c0190..a2e60d5b 100644 --- a/modules/default/infomaniak.nix +++ b/modules/default/infomaniak.nix @@ -28,18 +28,28 @@ in { } ]; - systemd.services = lib.listToAttrs (map (hostname: - lib.nameValuePair "infomaniak-${lib.replaceStrings [ "." ] [ "-" ] hostname}" { - after = [ "network.target" ]; + systemd = { + services = lib.listToAttrs (map (hostname: + lib.nameValuePair "infomaniak-${lib.replaceStrings [ "." ] [ "-" ] hostname}" { + after = [ "network.target" ]; - script = ''${pkgs.curl}/bin/curl -s "https://${cfg.username}:${cfg.password}@infomaniak.com/nic/update?hostname=${hostname}"''; + script = ''${pkgs.curl}/bin/curl -s "https://${cfg.username}:${cfg.password}@infomaniak.com/nic/update?hostname=${hostname}"''; - startAt = "*:*:0/5"; + serviceConfig = { + DynamicUser = true; + Restart = "on-abort"; + }; + }) cfg.hostnames); - serviceConfig = { - DynamicUser = true; - Restart = "on-abort"; - }; - }) cfg.hostnames); + timers = lib.listToAttrs (map (hostname: + lib.nameValuePair "infomaniak-${lib.replaceStrings [ "." ] [ "-" ] hostname}" { + wantedBy = [ "timers.target" ]; + + timerConfig = { + OnCalendar = "*:0/5"; + RandomizedDelaySec = 60; + }; + }) cfg.hostnames); + }; }; }