From af894fbbc78c6f06237c5944df519626477f70f2 Mon Sep 17 00:00:00 2001 From: Benedikt Rips Date: Mon, 5 Jan 2026 17:16:59 +0100 Subject: [PATCH] borgmatic: remove redundant platform checks --- modules/services/borgmatic.nix | 136 ++++++++++++++++----------------- 1 file changed, 65 insertions(+), 71 deletions(-) diff --git a/modules/services/borgmatic.nix b/modules/services/borgmatic.nix index 4277d1d47..a950c93b0 100644 --- a/modules/services/borgmatic.nix +++ b/modules/services/borgmatic.nix @@ -32,78 +32,72 @@ in }; }; - config = lib.mkIf serviceConfig.enable ( - lib.mkMerge [ - (lib.mkIf pkgs.stdenv.isLinux { - systemd.user = { - services.borgmatic = { - Unit = { - Description = "borgmatic backup"; - # Prevent borgmatic from running unless the machine is - # plugged into power: - ConditionACPower = true; - }; - Service = { - Type = "oneshot"; - - # Lower CPU and I/O priority: - Nice = 19; - IOSchedulingClass = "best-effort"; - IOSchedulingPriority = 7; - IOWeight = 100; - - Restart = "no"; - LogRateLimitIntervalSec = 0; - - # Delay start to prevent backups running during boot: - ExecStartPre = "${pkgs.coreutils}/bin/sleep 3m"; - - ExecStart = '' - ${pkgs.systemd}/bin/systemd-inhibit \ - --who="borgmatic" \ - --what="sleep:shutdown" \ - --why="Prevent interrupting scheduled backup" \ - ${programConfig.package}/bin/borgmatic \ - --stats \ - --verbosity -1 \ - --list \ - --syslog-verbosity 1 - ''; - }; - }; - - timers.borgmatic = { - Unit.Description = "Run borgmatic backup"; - Timer = { - OnCalendar = serviceConfig.frequency; - Persistent = true; - RandomizedDelaySec = "10m"; - }; - Install.WantedBy = [ "timers.target" ]; - }; + config = lib.mkIf serviceConfig.enable { + systemd.user = { + services.borgmatic = { + Unit = { + Description = "borgmatic backup"; + # Prevent borgmatic from running unless the machine is + # plugged into power: + ConditionACPower = true; }; - }) + Service = { + Type = "oneshot"; - (lib.mkIf pkgs.stdenv.isDarwin { - assertions = [ - (lib.hm.darwin.assertInterval "services.borgmatic.frequency" serviceConfig.frequency pkgs) + # Lower CPU and I/O priority: + Nice = 19; + IOSchedulingClass = "best-effort"; + IOSchedulingPriority = 7; + IOWeight = 100; + + Restart = "no"; + LogRateLimitIntervalSec = 0; + + # Delay start to prevent backups running during boot: + ExecStartPre = "${pkgs.coreutils}/bin/sleep 3m"; + + ExecStart = '' + ${pkgs.systemd}/bin/systemd-inhibit \ + --who="borgmatic" \ + --what="sleep:shutdown" \ + --why="Prevent interrupting scheduled backup" \ + ${programConfig.package}/bin/borgmatic \ + --stats \ + --verbosity -1 \ + --list \ + --syslog-verbosity 1 + ''; + }; + }; + + timers.borgmatic = { + Unit.Description = "Run borgmatic backup"; + Timer = { + OnCalendar = serviceConfig.frequency; + Persistent = true; + RandomizedDelaySec = "10m"; + }; + Install.WantedBy = [ "timers.target" ]; + }; + }; + + assertions = [ + (lib.hm.darwin.assertInterval "services.borgmatic.frequency" serviceConfig.frequency pkgs) + ]; + + launchd.agents.borgmatic = { + enable = true; + config = { + ProgramArguments = [ + (lib.getExe programConfig.package) + "--stats" + "--list" ]; - - launchd.agents.borgmatic = { - enable = true; - config = { - ProgramArguments = [ - (lib.getExe programConfig.package) - "--stats" - "--list" - ]; - ProcessType = "Background"; - StartCalendarInterval = lib.hm.darwin.mkCalendarInterval serviceConfig.frequency; - StandardOutPath = "${config.home.homeDirectory}/Library/Logs/borgmatic/launchd-stdout.log"; - StandardErrorPath = "${config.home.homeDirectory}/Library/Logs/borgmatic/launchd-stderr.log"; - }; - }; - }) - ] - ); + ProcessType = "Background"; + StartCalendarInterval = lib.hm.darwin.mkCalendarInterval serviceConfig.frequency; + StandardOutPath = "${config.home.homeDirectory}/Library/Logs/borgmatic/launchd-stdout.log"; + StandardErrorPath = "${config.home.homeDirectory}/Library/Logs/borgmatic/launchd-stderr.log"; + }; + }; + }; }