42 lines
1.7 KiB
Nix
42 lines
1.7 KiB
Nix
{pkgs, config, lib, ... }: let
|
|
cfg = config.grimmShared;
|
|
in {
|
|
config = with cfg; lib.mkIf (enable && cloudSync.enable) (let
|
|
cloud_cmd = ''${pkgs.nextcloud-client}/bin/nextcloudcmd -u ${config.grimmShared.cloudSync.username} -p "$(cat ${config.grimmShared.cloudSync.passwordFile})" -h -n --path'';
|
|
sync_server = "https://${config.grimmShared.cloudSync.server}";
|
|
in {
|
|
environment.systemPackages = with pkgs; [
|
|
(writeShellScriptBin "cloudsync-cmd" (cloud_cmd + " $@ " + sync_server))
|
|
nextcloud-client
|
|
];
|
|
|
|
systemd = lib.mkMerge (lib.mapAttrsToList (local_user: paths: let
|
|
sync_script = lib.strings.concatLines (map ({local, remote}: let
|
|
remote_clean = lib.strings.concatStrings (builtins.match "/*(.+)" remote);
|
|
in "${cloud_cmd} /${remote_clean} ${local} ${sync_server}" ) paths);
|
|
in { # user-specific sync jobs
|
|
services."nextcloud-autosync-${local_user}" = {
|
|
description = "Auto sync Nextcloud";
|
|
after = [ "network-online.target" ];
|
|
wants = [ "network-online.target" ];
|
|
serviceConfig.Type = "simple";
|
|
serviceConfig.User = local_user;
|
|
serviceConfig.Group= "users";
|
|
script= sync_script;
|
|
# TimeoutStopSec = "180";
|
|
# KillMode = "process";
|
|
# KillSignal = "SIGINT";
|
|
wantedBy = ["multi-user.target"];
|
|
enable=true;
|
|
};
|
|
timers."nextcloud-autosync-${local_user}" = {
|
|
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;
|
|
};
|
|
}) cfg.cloudSync.paths );
|
|
});
|
|
}
|