grimm-nixos-laptop/modules/cloudsync.nix

52 lines
1.9 KiB
Nix
Raw Normal View History

{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";
2024-03-05 21:13:56 +01:00
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
2024-03-05 21:13:56 +01:00
(writeShellScriptBin "cloudsync" sync_script)
];
2024-03-05 21:13:56 +01:00
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;
};
};
}