about summary refs log tree commit diff
path: root/modules/services/rclone/default.nix
blob: 1ccf5dfe9546fc154d2b8ab46533cbe55438fe11 (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;
in {
  options.my.services.rclone = with lib; {
    enable = mkEnableOption "rclone backup service";
  };

  config = lib.mkIf cfg.enable {
    age.secrets.rclone-gcs-sa.file =
      ../../../secrets/rclone/gcs_service_account.json.age;

    age.secrets.rclone-config.file = ../../../secrets/rclone/config.ini.age;

    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=${config.age.secrets.rclone-config.path} --gcs-service-account-file=${config.age.secrets.rclone-gcs-sa.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"
          ];
        };
      };
    };
  };
}