From dd69b17a01f8df46d17c52a6424292cb83618381 Mon Sep 17 00:00:00 2001 From: LordGrimmauld Date: Tue, 5 Mar 2024 21:13:56 +0100 Subject: [PATCH] systemd sync service --- modules/cloudsync.nix | 40 ++++++++++++++++++++++++++++++++++------ modules/toolchains.nix | 1 + 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/modules/cloudsync.nix b/modules/cloudsync.nix index 25caace..8fdd175 100644 --- a/modules/cloudsync.nix +++ b/modules/cloudsync.nix @@ -4,6 +4,14 @@ sync_user_remote = "Grimmauld"; sync_server = "cloud.grimmauld.de"; # cloud_cmd = "${pkgs.nextcloud-client}/bin/nextcloudcmd -u ${sync_user_remote} -p -h -n --path"; + 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; @@ -15,11 +23,31 @@ in { 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" '' - ${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} - '') + (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.UID = 1000; + 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; + }; + }; } diff --git a/modules/toolchains.nix b/modules/toolchains.nix index d48168f..f232a97 100644 --- a/modules/toolchains.nix +++ b/modules/toolchains.nix @@ -19,6 +19,7 @@ in { pass libsecret tea + acpi (writeShellScriptBin "passw" "pass $@") # nodejs_21 # ugh.... somehow nvim needs node now?!? ];