@@ -242,9 +242,16 @@ in
242242
243243 systemd.services."tarsnap@" = {
244244 description = "Tarsnap archive '%i'";
245− requires = [ "network.target" ];
245+ requires = [ "network-online.target" ];
246+ after = [ "network-online.target" ];
246247
247− path = [ pkgs.tarsnap pkgs.coreutils ];
248+ path = [ pkgs.iputils pkgs.tarsnap pkgs.coreutils ];
249+
250+ # In order for the persistent tarsnap timer to work reliably, we have to
251+ # make sure that the tarsnap server is reachable after systemd starts up
252+ # the service - therefore we sleep in a loop until we can ping the
253+ # endpoint.
254+ preStart = "while ! ping -q -c 1 betatest-server.tarsnap.com &> /dev/null; do sleep 3; done";
248255 scriptArgs = "%i";
249256 script = ''
250257 mkdir -p -m 0755 ${dirOf cfg.cachedir}
@@ -259,11 +266,15 @@ in
259266 IOSchedulingClass = "idle";
260267 NoNewPrivileges = "true";
261268 CapabilityBoundingSet = "CAP_DAC_READ_SEARCH";
269+ PermissionsStartOnly = "true";
262270 };
263271 };
264272
273+ # Note: the timer must be Persistent=true, so that systemd will start it even
274+ # if e.g. your laptop was asleep while the latest interval occurred.
265275 systemd.timers = mapAttrs' (name: cfg: nameValuePair "tarsnap@${name}"
266276 { timerConfig.OnCalendar = cfg.period;
277+ timerConfig.Persistent = "true";
267278 wantedBy = [ "timers.target" ];
268279 }) cfg.archives;
269280