Commit 8db075b9930b

Vincent Demeester <vincent@sbr.pm>
2026-02-03 11:36:49
Add readwise-sync systemd service for daily org-mode sync
- Created home/common/services/readwise-sync.nix module - Configured daily timer for automatic Readwise highlights sync - Uses passage to securely retrieve API key - Enables URL archiving with monolith - Added to kyushu and aomi home configurations - Syncs to ~/desktop/org/notes by default
1 parent 5fbf61e
Changed files (3)
home
common
systems
home/common/services/readwise-sync.nix
@@ -0,0 +1,67 @@
+{
+  config,
+  lib,
+  pkgs,
+  ...
+}:
+
+with lib;
+
+let
+  cfg = config.services.readwise-sync;
+
+  readwise-sync-wrapper = pkgs.writeShellScriptBin "readwise-sync" ''
+    set -euo pipefail
+    
+    READWISE_KEY=$(${pkgs.passage}/bin/passage show readwise/key)
+    export READWISE_KEY
+    
+    ${pkgs.go-org-readwise}/bin/go-org-readwise \
+      -archiveURLs=true \
+      -targetFolder ${cfg.targetFolder}
+  '';
+in
+{
+  options.services.readwise-sync = {
+    enable = mkEnableOption "automatic Readwise to org-mode sync";
+
+    targetFolder = mkOption {
+      type = types.str;
+      default = "${config.home.homeDirectory}/desktop/org/notes";
+      description = "Target folder for synced org files";
+    };
+
+    interval = mkOption {
+      type = types.str;
+      default = "daily";
+      description = "How often to sync (systemd timer format)";
+    };
+  };
+
+  config = mkIf cfg.enable {
+    home.packages = [ readwise-sync-wrapper ];
+
+    systemd.user.services.readwise-sync = {
+      Unit = {
+        Description = "Sync Readwise highlights to org-mode files";
+      };
+      Service = {
+        Type = "oneshot";
+        ExecStart = "${readwise-sync-wrapper}/bin/readwise-sync";
+      };
+    };
+
+    systemd.user.timers.readwise-sync = {
+      Unit = {
+        Description = "Timer for syncing Readwise to org-mode";
+      };
+      Timer = {
+        OnCalendar = cfg.interval;
+        Persistent = true;
+      };
+      Install = {
+        WantedBy = [ "timers.target" ];
+      };
+    };
+  };
+}
systems/aomi/home.nix
@@ -9,6 +9,7 @@
     ../../home/common/dev/containers.nix
     ../../home/common/dev/tektoncd.nix
     ../../home/common/desktop/passage.nix
+    ../../home/common/services/readwise-sync.nix
     ../../home/common/shell/gh.nix
   ];
   systemd.user.services.syncthing.Install.WantedBy = [ "multi-user.target" ];
@@ -30,6 +31,12 @@
     lazygit
   ];
 
+  # Readwise sync to org-mode
+  services.readwise-sync = {
+    enable = true;
+    interval = "daily";
+  };
+
   # Passage update service and timer
   systemd.user.services.passage-update = {
     Unit = {
systems/kyushu/home.nix
@@ -17,6 +17,7 @@ in
     ../../home/common/services/gcal-to-org.nix
     ../../home/common/services/goimapnotify.nix
     ../../home/common/services/mail-monitor.nix
+    ../../home/common/services/readwise-sync.nix
     ../../home/common/services/redhat.nix
     ../../home/common/shell/gh.nix
   ];
@@ -99,6 +100,12 @@ in
     interval = "hourly";
   };
 
+  # Readwise sync to org-mode
+  services.readwise-sync = {
+    enable = true;
+    interval = "daily";
+  };
+
   # ntfy notification subscriber
   systemd.user.services.ntfy-subscriber = {
     Unit = {