{ 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" ]; }; }; }; }; }