From 1865f6985e4bc492a5ea336702ccfde295d15689 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Sun, 14 Apr 2024 04:20:56 +0000 Subject: [PATCH] automatically fetch notes --- modules/common/repositories/notes.nix | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/common/repositories/notes.nix b/modules/common/repositories/notes.nix index 7439258..74d95c5 100644 --- a/modules/common/repositories/notes.nix +++ b/modules/common/repositories/notes.nix @@ -1,4 +1,10 @@ -{ config, ... }: { +{ + config, + pkgs, + lib, + ... +}: +{ # This is just a placeholder as I expect to interact with my notes in a # certain location @@ -9,6 +15,22 @@ NOTES_PATH = "${config.homePath}/dev/personal/notes/content"; }; + # Sync notes for Nextcloud automatically + systemd.user.timers.refresh-notes = lib.mkIf config.services.nextcloud.enable { + Timer = { + OnCalendar = "*-*-* *:0/10:50"; # Every 10 minutes + Unit = "refresh-notes.service"; + }; + }; + systemd.user.services.refresh-notes = { + Unit.Description = "Get latest notes."; + Service = { + Type = "oneshot"; + ExecStartPre = "${pkgs.git}/bin/git -C /data/git/notes reset --hard master"; + ExecStart = "${pkgs.git}/bin/git -C /data/git/notes pull"; + WorkingDirectory = config.homePath; + Environment = "PATH=${pkgs.openssh}/bin"; + }; + }; }; - }