126 lines
4.2 KiB
Nix
126 lines
4.2 KiB
Nix
{
|
|
lib,
|
|
config,
|
|
pkgs,
|
|
...
|
|
}: let
|
|
cfg = config.myConfig.programs.rclone;
|
|
in {
|
|
options.myConfig.programs.rclone = {
|
|
enable = lib.mkEnableOption "nextcloud sync using rclone";
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
sops = {
|
|
age.keyFile = "/home/max/.config/sops/age/keys.txt";
|
|
secrets = {
|
|
"cloud/url" = {
|
|
sopsFile = ../../../secrets/rclone.yaml;
|
|
};
|
|
"cloud/user" = {
|
|
sopsFile = ../../../secrets/rclone.yaml;
|
|
};
|
|
"cloud/pass" = {
|
|
sopsFile = ../../../secrets/rclone.yaml;
|
|
};
|
|
"luhbots/url" = {
|
|
sopsFile = ../../../secrets/rclone.yaml;
|
|
};
|
|
"luhbots/user" = {
|
|
sopsFile = ../../../secrets/rclone.yaml;
|
|
};
|
|
"luhbots/pass" = {
|
|
sopsFile = ../../../secrets/rclone.yaml;
|
|
};
|
|
};
|
|
|
|
templates."rclone.conf".content = ''
|
|
[cloud]
|
|
type = webdav
|
|
url = ${config.sops.placeholder."cloud/url"}
|
|
vendor = nextcloud
|
|
user = ${config.sops.placeholder."cloud/user"}
|
|
pass = ${config.sops.placeholder."cloud/pass"}
|
|
nextcloud_chunk_size = 512M
|
|
|
|
[luhbots]
|
|
type = webdav
|
|
url = ${config.sops.placeholder."luhbots/url"}
|
|
vendor = nextcloud
|
|
user = ${config.sops.placeholder."luhbots/user"}
|
|
pass = ${config.sops.placeholder."luhbots/pass"}
|
|
'';
|
|
};
|
|
|
|
home.packages = with pkgs; [rclone fuse3];
|
|
|
|
systemd.user = {
|
|
services = {
|
|
luhbots-mount = {
|
|
Unit = {
|
|
Description = "Mount the luhbots nextcloud";
|
|
After = ["network-online.target"];
|
|
};
|
|
Service = {
|
|
Type = "notify";
|
|
ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p \"%h/luhbots Nextcloud\"";
|
|
ExecStart = "${pkgs.rclone}/bin/rclone --config=${config.sops.templates."rclone.conf".path} --vfs-cache-mode full mount \"luhbots:\" \"%h/luhbots Nextcloud\"";
|
|
ExecStop = "/bin/fusermount -u \"%h/luhbots Nextcloud\"";
|
|
Environment = ["PATH=/run/wrappers/bin/:$PATH"];
|
|
};
|
|
Install.WantedBy = ["default.target"];
|
|
};
|
|
music-mount = {
|
|
Unit = {
|
|
Description = "Mount the music directory from my cloud";
|
|
After = ["network-online.target"];
|
|
};
|
|
Service = {
|
|
Type = "notify";
|
|
ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p \"%h/Music\"";
|
|
ExecStart = "${pkgs.rclone}/bin/rclone --config=${config.sops.templates."rclone.conf".path} --vfs-cache-mode full mount \"cloud:Music\" \"%h/Music\"";
|
|
ExecStop = "/bin/fusermount -u \"%h/Music\"";
|
|
Environment = ["PATH=/run/wrappers/bin/:$PATH"];
|
|
};
|
|
Install.WantedBy = ["default.target"];
|
|
};
|
|
videos-mount = {
|
|
Unit = {
|
|
Description = "Mount the videos directory from my cloud";
|
|
After = ["network-online.target"];
|
|
};
|
|
Service = {
|
|
Type = "notify";
|
|
ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p \"%h/Videos\"";
|
|
ExecStart = "${pkgs.rclone}/bin/rclone --config=${config.sops.templates."rclone.conf".path} --vfs-cache-mode full mount \"cloud:Videos\" \"%h/Videos\"";
|
|
ExecStop = "/bin/fusermount -u \"%h/Videos\"";
|
|
Environment = ["PATH=/run/wrappers/bin/:$PATH"];
|
|
};
|
|
Install.WantedBy = ["default.target"];
|
|
};
|
|
sync-Documents = {
|
|
Unit = {
|
|
Description = "Sync the Documents folder with the cloud Documents folder using bisync";
|
|
After = ["network-online.target"];
|
|
};
|
|
Service = {
|
|
Type = "oneshot";
|
|
ExecStart = "${pkgs.rclone}/bin/rclone --config=${config.sops.templates."rclone.conf".path} --resilient --recover -vv --exclude-from %h/Documents/sync-exclude.txt bisync cloud:Documents %h/Documents";
|
|
};
|
|
Install.WantedBy = ["default.target"];
|
|
};
|
|
};
|
|
timers = {
|
|
sync-Documents = {
|
|
Unit.Description = "Sync Documents folder every half hour";
|
|
Timer = {
|
|
OnBootSec = "15min";
|
|
OnUnitActiveSec = "30min";
|
|
};
|
|
Install.WantedBy = ["timers.target"];
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}
|