aboutsummaryrefslogtreecommitdiff
path: root/modules/calendar.home/ical2org.module.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/calendar.home/ical2org.module.nix')
-rw-r--r--modules/calendar.home/ical2org.module.nix55
1 files changed, 55 insertions, 0 deletions
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;
+ };
+}