From 81fb05398a2c8251936be4bfa0ed679f0cf3825f Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Wed, 6 Apr 2022 12:42:20 -0700 Subject: refactor rclone to a module --- hosts/common/server/rclone.nix | 31 ------------------------------- hosts/profiles/nas.nix | 3 +-- modules/services/default.nix | 1 + modules/services/rclone/default.nix | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 33 deletions(-) delete mode 100644 hosts/common/server/rclone.nix create mode 100644 modules/services/rclone/default.nix diff --git a/hosts/common/server/rclone.nix b/hosts/common/server/rclone.nix deleted file mode 100644 index 549cf4d..0000000 --- a/hosts/common/server/rclone.nix +++ /dev/null @@ -1,31 +0,0 @@ -{ config, pkgs, lib, ... }: - -{ - 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" - ]; - }; - }; - }; -} diff --git a/hosts/profiles/nas.nix b/hosts/profiles/nas.nix index 112eda7..fd42eb7 100644 --- a/hosts/profiles/nas.nix +++ b/hosts/profiles/nas.nix @@ -4,8 +4,6 @@ ./server.nix ../common/server/traefik.nix ../common/server/transmission.nix - ../common/server/gitea.nix - ../common/server/rclone.nix ]; users.groups.nas.gid = 5000; @@ -31,6 +29,7 @@ enable = true; stateDir = "/var/lib/gitea"; }; + rclone = { enable = true; }; }; services.restic.backups = { diff --git a/modules/services/default.nix b/modules/services/default.nix index 94250d2..6dfc4fb 100644 --- a/modules/services/default.nix +++ b/modules/services/default.nix @@ -7,6 +7,7 @@ ./grafana ./navidrome ./prometheus + ./rclone ./samba ./ssh-server ./tailscale diff --git a/modules/services/rclone/default.nix b/modules/services/rclone/default.nix new file mode 100644 index 0000000..1ccf5df --- /dev/null +++ b/modules/services/rclone/default.nix @@ -0,0 +1,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" + ]; + }; + }; + }; + }; +} -- cgit 1.4.1