{pkgs, config, ... }: let # cloud_cmd = "${pkgs.nextcloud-client}/bin/nextcloudcmd -h -n --path"; sync_user = "grimmauld"; sync_user_remote = "Grimmauld"; sync_server = "cloud.grimmauld.de"; sync_script = let cloud_cmd = ''${pkgs.nextcloud-client}/bin/nextcloudcmd -u ${sync_user_remote} -p "$(cat ${config.age.secrets.nextcloud_pass.path})" -h -n --path''; in '' ${cloud_cmd} /3d /home/${sync_user}/3d https://${sync_server} ${cloud_cmd} /Pictures /home/${sync_user}/Pictures https://${sync_server} ${cloud_cmd} /Documents /home/${sync_user}/Documents https://${sync_server} ${cloud_cmd} /Videos /home/${sync_user}/Videos https://${sync_server} ''; in { age.secrets.nextcloud_pass = { file = ../secrets/nextcloud_pass.age; owner = sync_user; mode = "700"; }; environment.systemPackages = let cloud_cmd = ''${pkgs.nextcloud-client}/bin/nextcloudcmd -u ${sync_user_remote} -p "$(cat ${config.age.secrets.nextcloud_pass.path})" -h -n --path''; in with pkgs; [ nextcloud-client (writeShellScriptBin "cloudsync" sync_script) ]; systemd = { services.nextcloud-autosync = { description = "Auto sync Nextcloud"; after = [ "network-online.target" ]; wants = [ "network-online.target" ]; serviceConfig.Type = "simple"; serviceConfig.User = sync_user; serviceConfig.Group= "users"; script= sync_script; # TimeoutStopSec = "180"; # KillMode = "process"; # KillSignal = "SIGINT"; wantedBy = ["multi-user.target"]; enable=true; }; timers.nextcloud-autosync = { description = "Automatic sync files with Nextcloud when booted up after 5 minutes then rerun every 60 minutes"; timerConfig.OnBootSec = "5min"; timerConfig.OnUnitActiveSec = "60min"; wantedBy = ["multi-user.target" "timers.target"]; enable = true; }; }; }