diff options
| -rw-r--r-- | home.nix | 1 | ||||
| -rw-r--r-- | modules/calendar.home/.gitignore | 1 | ||||
| -rw-r--r-- | modules/calendar.home/default.nix | 23 | ||||
| -rw-r--r-- | modules/calendar.home/ical2org.module.nix | 55 |
4 files changed, 80 insertions, 0 deletions
@@ -12,6 +12,7 @@ in # ./modules/firefox.home/default.nix ./modules/newsboat.home/default.nix ./modules/email/aerc.home.nix + ./modules/calendar.home/default.nix ]; home.packages = with pkgs; [ 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; + }; +} |
