aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-05-27 11:11:42 +0530
committerAkshay Nair <phenax5@gmail.com>2025-05-27 11:11:42 +0530
commit73a49b61fddb77107cb692fa70b8dc361952e556 (patch)
tree7bc303b96de837d7efacbe6e063bb32fad834af0 /modules
parentdf5c612ed3d926c76eaeb02e16042c43c6969510 (diff)
downloadnixos-config-73a49b61fddb77107cb692fa70b8dc361952e556.tar.gz
nixos-config-73a49b61fddb77107cb692fa70b8dc361952e556.zip
Add ical2org service for calendar syncing
Diffstat (limited to 'modules')
-rw-r--r--modules/calendar.home/.gitignore1
-rw-r--r--modules/calendar.home/default.nix23
-rw-r--r--modules/calendar.home/ical2org.module.nix55
3 files changed, 79 insertions, 0 deletions
diff --git a/modules/calendar.home/.gitignore b/modules/calendar.home/.gitignore
new file mode 100644
index 0000000..a211cae
--- /dev/null
+++ b/modules/calendar.home/.gitignore
@@ -0,0 +1 @@
+private.nix
diff --git a/modules/calendar.home/default.nix b/modules/calendar.home/default.nix
new file mode 100644
index 0000000..997e2eb
--- /dev/null
+++ b/modules/calendar.home/default.nix
@@ -0,0 +1,23 @@
+{ config, ... }:
+let
+ private = import ./private.nix;
+in
+{
+ imports = [ ./ical2org.module.nix ];
+
+ services.ical2org = {
+ enable = true;
+ icalLink = private.icalLink;
+ outputPath = "${config.home.homeDirectory}/nixos/extras/notes/calendar-sync.autogen.org";
+ syncFrequency = "*:0/10";
+ settings = {
+ filetags = "calendar";
+ email = private.email;
+ title = "calendar";
+ category = "calendar";
+ startup = "showeverything";
+ past = 6; # days
+ future = 30; # days
+ };
+ };
+}
diff --git a/modules/calendar.home/ical2org.module.nix b/modules/calendar.home/ical2org.module.nix
new file mode 100644
index 0000000..7ea2c4a
--- /dev/null
+++ b/modules/calendar.home/ical2org.module.nix
@@ -0,0 +1,55 @@
+{ config, pkgs, lib, ... }:
+with lib;
+let
+ cfg = config.services.ical2org;
+
+ bunx = "${pkgs.bun}/bin/bunx";
+ curl = "${pkgs.curl}/bin/curl";
+ mktemp = "${pkgs.coreutils-full}/bin/mktemp";
+ rm = "${pkgs.coreutils-full}/bin/rm";
+
+ config-file =
+ pkgs.writeText "icsorg-config" (concatStringsSep "\n"
+ (mapAttrsToList (key: val: "${strings.toUpper key}=${toString val}") cfg.settings));
+
+ sync-script = ''
+ #!${pkgs.bash}/bin/bash
+ set -eu -o pipefail;
+
+ file=$(${mktemp} /tmp/ical2org.XXXX.ical);
+ trap "${rm} -f '$file'" EXIT;
+
+ ${curl} "${cfg.icalLink}" -o "$file";
+ ${bunx} icsorg -c "${config-file}" -i "$file" -o "${cfg.outputPath}";
+ '';
+
+ service-unit = {
+ Service = {
+ Type = "oneshot";
+ ExecStart = "${pkgs.writeScript "ical2org" sync-script}";
+ WorkingDirectory = config.home.homeDirectory;
+ };
+ };
+
+ timer-unit = {
+ Timer = {
+ OnCalendar = cfg.syncFrequency;
+ RandomizedDelaySec = 30;
+ };
+ Install.WantedBy = [ "timers.target" ];
+ };
+in {
+ options.services.ical2org = {
+ enable = mkEnableOption "ical2org sync";
+ syncFrequency = mkOption { type = types.str; default = "*:0/30"; };
+ icalLink = mkOption { type = types.str; };
+ outputPath = mkOption { type = types.str; };
+ settings = mkOption { type = types.attrs; default = {}; };
+ };
+
+ config = mkIf cfg.enable {
+ programs.lieer.enable = true;
+ systemd.user.services.ical2org = service-unit;
+ systemd.user.timers.ical2org = timer-unit;
+ };
+}