fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6serviceConfig = config . services . borgmatic ; 7programConfig = config . programs . borgmatic ; 8in { 9meta . maintainers = [ maintainers . DamienCassou ]; 10 11options = { 12services . borgmatic = { 13enable = mkEnableOption "Borgmatic service" ; 14 15frequency = mkOption { 16type = types . str ; 17default = "hourly" ; 18description = '' 19How often to run borgmatic when 20`services.borgmatic.enable = true`. 21This value is passed to the systemd timer configuration as 22the onCalendar option. See 23{manpage}`systemd.time(7)` 24for more information about the format. 25'' ; 26}; 27}; 28}; 29 30config = mkIf serviceConfig . enable { 31assertions = [ 32( lib . hm . assertions . assertPlatform "services.borgmatic" pkgs 33lib . platforms . linux ) 34]; 35 36systemd . user = { 37services . borgmatic = { 38Unit = { 39Description = "borgmatic backup" ; 40# Prevent borgmatic from running unless the machine is 41# plugged into power: 42ConditionACPower = true ; 43}; 44Service = { 45Type = "oneshot" ; 46 47# Lower CPU and I/O priority: 48Nice = 19 ; 49CPUSchedulingPolicy = "batch" ; 50IOSchedulingClass = "best-effort" ; 51IOSchedulingPriority = 7 ; 52IOWeight = 100 ; 53 54Restart = "no" ; 55LogRateLimitIntervalSec = 0 ; 56 57# Delay start to prevent backups running during boot: 58ExecStartPre = " ${ pkgs . coreutils } /bin/sleep 3m" ; 59 60ExecStart = '' 61${ pkgs . systemd } /bin/systemd-inhibit \ 62--who="borgmatic" \ 63--what="sleep:shutdown" \ 64--why="Prevent interrupting scheduled backup" \ 65${ programConfig . package } /bin/borgmatic \ 66--stats \ 67--verbosity -1 \ 68--list \ 69--syslog-verbosity 1 70'' ; 71}; 72}; 73 74timers . borgmatic = { 75Unit . Description = "Run borgmatic backup" ; 76Timer = { 77OnCalendar = serviceConfig . frequency ; 78Persistent = true ; 79RandomizedDelaySec = "10m" ; 80}; 81Install . WantedBy = [ "timers.target" ]; 82}; 83}; 84}; 85}