about summary refs log tree commit diff
path: root/modules/services/rclone/default.nix
blob: cbef0c30d9ce7c7f428ebbf502e99178c8694806 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{ config, pkgs, lib, ... }:
let
  cfg = config.my.services.rclone;
  secrets = config.age.secrets;
in
{
  options.my.services.rclone = with lib; {
    enable = mkEnableOption "rclone backup service";
  };

  config = lib.mkIf cfg.enable {
    systemd = {
      packages = [ pkgs.rclone ];
      timers.rclone-sync = {
        description = "synchronize restic repository to GCS";
        wantedBy = [ "timers.target" ];
        partOf = [ "rclone-sync.service" ];
        timerConfig = { OnCalendar = "02:00"; };
      };
      services.rclone-sync = {
        description = "synchronize restic repository to GCS";
        serviceConfig =
          let
            rcloneOptions = "--config=${
              secrets."rclone/config.ini".path
            } --gcs-service-account-file=${
              secrets."rclone/gcs_service_account.json".path
            } --fast-list --verbose";
          in
          {
            Type = "oneshot";
            ExecStart = [
              "${pkgs.rclone}/bin/rclone ${rcloneOptions} sync /data/slow/backups/systems gbackup:fcuny-backups-systems"
              "${pkgs.rclone}/bin/rclone ${rcloneOptions} sync /data/slow/backups/users gbackup:fcuny-backups-users"
            ];
          };
      };
    };
  };
}