summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2025-04-22 12:03:08 -0400
committerBen Sima <ben@bensima.com>2025-04-23 11:35:18 -0400
commit95eefa6435f996f534f04c64cdc788d268dd87b9 (patch)
tree0fb7e1c57451d19fe0883293056d4ed5f77ee002 /lib
parent85f1a26ea610ff210c4828ad6cdb92622f68c2e2 (diff)
pair ben-shared and scheduling
this means i don't have to manually copy my main calendar events onto the 'scheduling' calendar. i can also use thie method to merge my work calendar with personal calendar (eventually)
Diffstat (limited to 'lib')
-rw-r--r--lib/calendars.nix103
1 files changed, 62 insertions, 41 deletions
diff --git a/lib/calendars.nix b/lib/calendars.nix
index 71ce616..112dad6 100644
--- a/lib/calendars.nix
+++ b/lib/calendars.nix
@@ -1,5 +1,17 @@
-{...}:
+{lib, config, ...}:
let
+ # names mapped to unique identifiers of calendars
+ calendars = {
+ unschedule = "3e40534f-bfb9-b973-f615-f958a6361e95";
+ ymca-open-swim = "066441A6-B48F-439B-9BD0-5D0FA8F4CB6F";
+ scheduling = "8fd24d42-2294-9bc3-cece-3922c7cd4d09";
+ fasting-schedule = "e2ad2353-f91e-76c9-fb0f-2c8722ed9d2a";
+ ben-shared = "ben";
+ kate = "0962a74ab76a97543b485d2a583caa271042baab9d64437ae6c3bc8a50df1f08";
+ };
+
+ getCals = ls: lib.attrsets.attrVals ls calendars;
+
common = {
vdirsyncer = {
enable = true;
@@ -15,48 +27,46 @@ let
end = "datetime.now() + timedelta(days=365)";
};
};
+
+ radicale = {
+ passwordCommand = ["pass" "cal.bensima.com"];
+ type = "caldav";
+ url = "https://cal.bensima.com";
+ userName = "ben";
+ };
+ khal = {
+ enable = true;
+ type = "discover";
+ };
};
in {
accounts.calendar.basePath = "Calendars";
accounts.calendar.accounts = {
"bensima_personal" = {
primaryCollection = "Unschedule";
- remote = {
- passwordCommand = ["pass" "cal.bensima.com"];
- type = "caldav";
- url = "https://cal.bensima.com";
- userName = "ben";
+ remote = common.radicale;
+ vdirsyncer = common.vdirsyncer // {
+ collections = getCals ["unschedule" "ymca-open-swim" "fasting-schedule"];
};
- vdirsyncer = {
- inherit (common.vdirsyncer) metadata timeRange enable auth conflictResolution;
- collections = [
- "3e40534f-bfb9-b973-f615-f958a6361e95" # private
- "066441A6-B48F-439B-9BD0-5D0FA8F4CB6F" # ymca open swim
- "8fd24d42-2294-9bc3-cece-3922c7cd4d09" # cal.com scheduling
- "e2ad2353-f91e-76c9-fb0f-2c8722ed9d2a" # fasting schedule
- ];
- };
- khal = {
- enable = true;
+ khal = common.khal // {
addresses = ["ben@bensima.com" "ben@bsima.me"];
color = "#800080";
- type = "discover";
};
};
- "bensima_shared" = {
- remote = {
- passwordCommand = ["pass" "cal.bensima.com"];
- type = "caldav";
- url = "https://cal.bensima.com/shared/ben";
- userName = "ben";
- };
- vdirsyncer = common.vdirsyncer;
- khal = {
- enable = true;
- color = "#097969";
- type = "calendar";
+ "bensima_scheduling" = {
+ primaryCollection = "Scheduling";
+ remote = common.radicale;
+ vdirsyncer = common.vdirsyncer // {
+ collections = getCals ["scheduling"];
};
+ # no khal, just sync this in the background
+ };
+
+ "bensima_shared" = {
+ remote = common.radicale // {url = "https://cal.bensima.com/shared/ben";};
+ vdirsyncer = common.vdirsyncer // {collections = getCals ["ben-shared"];};
+ khal = common.khal // {color = "#097969";};
};
"icloud" = {
@@ -66,17 +76,8 @@ in {
url = "https://caldav.icloud.com";
userName = "bsima@icloud.com";
};
- vdirsyncer = {
- inherit (common.vdirsyncer) metadata timeRange enable auth conflictResolution;
- collections = [
- "0962a74ab76a97543b485d2a583caa271042baab9d64437ae6c3bc8a50df1f08"
- ];
- };
- khal = {
- enable = true;
- color = "#FAA0A0";
- type = "discover";
- };
+ vdirsyncer = common.vdirsyncer // {collections = getCals ["kate"];};
+ khal = common.khal // {color = "#FAA0A0";};
};
};
@@ -95,4 +96,24 @@ in {
programs.vdirsyncer.enable = true;
services.vdirsyncer.enable = true;
+
+ # autosync ben-shared and scheduling, this must be hand-written and appended
+ # to the generated config file
+ services.vdirsyncer.configFile = "${config.xdg.configHome}/vdirsyncer/merged.conf";
+ xdg.configFile."vdirsyncer/merged.conf".text = let
+ wrap = s: ''"${s}"'';
+ join = l: lib.strings.concatStringsSep ", " l;
+ pair = pre: cals: "[${wrap pre}, ${join (map wrap (getCals cals))}]";
+ generatedConfig = builtins.readFile "${config.xdg.configFile."vdirsyncer/config".source}";
+ in ''
+ ${generatedConfig}
+
+ ### Manual Pairings
+
+ [pair shared_to_scheduling]
+ a = "calendar_bensima_shared_remote"
+ b = "calendar_bensima_scheduling_remote"
+ collections = [${pair "a_to_b" ["ben-shared" "scheduling"]}]
+ conflict_resolution = "a wins"
+ '';
}