about summary refs log tree commit diff
path: root/modules/services/rclone/default.nix
blob: 1d32aac354adfa6c86700569560a31dc2cb6e789 (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
{ 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/gcs_service_account.json".path
            } --gcs-service-account-file=${
              secrets."rclone/config.ini".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"
          ];
        };
      };
    };
  };
}