diff options
| author | Akshay Nair <phenax5@gmail.com> | 2026-03-21 22:59:10 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2026-03-21 22:59:10 +0530 |
| commit | c5d02e0c371ca71a9a668bc15dfc63aaf5dc28f9 (patch) | |
| tree | ecc7a6fed9d52593a37514cae058e199bb8c04ff | |
| parent | a254feb6191d9a20ddd6790229bc55e396cec25d (diff) | |
| download | homeserver-nixos-config-c5d02e0c371ca71a9a668bc15dfc63aaf5dc28f9.tar.gz homeserver-nixos-config-c5d02e0c371ca71a9a668bc15dfc63aaf5dc28f9.zip | |
Caldav server + ical sync service
| -rw-r--r-- | modules/calendar/default.nix | 7 | ||||
| -rw-r--r-- | modules/calendar/ical-sync.nix | 14 | ||||
| -rw-r--r-- | modules/calendar/radicale.nix | 31 | ||||
| -rw-r--r-- | modules/config.nix | 1 | ||||
| -rw-r--r-- | modules/network/default.nix | 2 | ||||
| -rw-r--r-- | services/icaldav.service.nix | 32 | ||||
| -rw-r--r-- | settings.nix | 1 |
7 files changed, 88 insertions, 0 deletions
diff --git a/modules/calendar/default.nix b/modules/calendar/default.nix new file mode 100644 index 0000000..5728da5 --- /dev/null +++ b/modules/calendar/default.nix @@ -0,0 +1,7 @@ +{ ... }: +{ + imports = [ + ./radicale.nix + ./ical-sync.nix + ]; +} diff --git a/modules/calendar/ical-sync.nix b/modules/calendar/ical-sync.nix new file mode 100644 index 0000000..a318334 --- /dev/null +++ b/modules/calendar/ical-sync.nix @@ -0,0 +1,14 @@ +{ settings, ... }: +{ + imports = [ ../../services/icaldav.service.nix ]; + + services.icaldavsync = { + enable = true; + syncFrequency = "*:0/30"; + icalLink = settings.calendar.icalLink; + caldavServerUrl = "http://127.0.0.1:${toString settings.network.ports.caldav}"; + password = "pass"; + user = "joe"; + calendar = "Work"; + }; +} diff --git a/modules/calendar/radicale.nix b/modules/calendar/radicale.nix new file mode 100644 index 0000000..cb2aa1f --- /dev/null +++ b/modules/calendar/radicale.nix @@ -0,0 +1,31 @@ +{ settings, ... }: +let + radicaleDir = "/var/lib/radicale/collections"; + radicalePort = settings.network.ports.caldav; +in +{ + systemd.tmpfiles.rules = [ + "d ${radicaleDir} 0755 - radicale - -" + ]; + + services.radicale = { + enable = true; + settings = { + server = { + hosts = [ + "0.0.0.0:${toString radicalePort}" + "[::]:${toString radicalePort}" + ]; + }; + auth = { + type = "none"; + }; + web = { + type = "internal"; + }; + storage = { + filesystem_folder = radicaleDir; + }; + }; + }; +} diff --git a/modules/config.nix b/modules/config.nix index 54108fe..5ca3cdc 100644 --- a/modules/config.nix +++ b/modules/config.nix @@ -10,6 +10,7 @@ ./notifications # ./monitoring ./rss + ./calendar ./packages.nix ]; diff --git a/modules/network/default.nix b/modules/network/default.nix index 78aea9d..25cd5aa 100644 --- a/modules/network/default.nix +++ b/modules/network/default.nix @@ -16,6 +16,7 @@ in firewall.enable = true; }; + # Service mappings (dns + nginx) services.service-router = { enable = true; routes = { @@ -34,6 +35,7 @@ in "news.local" = { inherit host; port = ports.yarr; }; # "librarian.local" = { inherit host; port = ports.lazylibrarian; }; "paperless.local" = { inherit host; port = ports.paperless; configureNginx = true; }; + "calendar.local" = { inherit host; port = ports.caldav; }; }; }; diff --git a/services/icaldav.service.nix b/services/icaldav.service.nix new file mode 100644 index 0000000..0945251 --- /dev/null +++ b/services/icaldav.service.nix @@ -0,0 +1,32 @@ +{ config, pkgs, lib, ... }: +with lib; +let + cfg = config.services.icaldavsync; + curl = "${pkgs.curl}/bin/curl"; + updateApiUrl = "${cfg.caldavServerUrl}/${cfg.user}/${cfg.calendar}"; +in +{ + options.services.icaldavsync = { + enable = mkEnableOption "ical caldav sync"; + syncFrequency = mkOption { type = types.str; default = "*:0/30"; }; + icalLink = mkOption { type = types.str; }; + caldavServerUrl = mkOption { type = types.str; }; + user = mkOption { type = types.str; }; + password = mkOption { type = types.str; }; + calendar = mkOption { type = types.str; }; + }; + + config = mkIf cfg.enable { + systemd.user.services.icaldavsync = { + enable = true; + script = '' + set -eu -o pipefail; + ${curl} '${cfg.icalLink}' | ${curl} -X PUT '${updateApiUrl}' -u '${cfg.user}:${cfg.password}' --data-binary @-; + ''; + serviceConfig = { + Type = "oneshot"; + }; + startAt = cfg.syncFrequency; + }; + }; +} diff --git a/settings.nix b/settings.nix index 741a6f3..da2ae5d 100644 --- a/settings.nix +++ b/settings.nix @@ -23,6 +23,7 @@ in lib.recursiveUpdate privateSettings rec { yarr = 7070; lazylibrarian = 5299; paperless = 28981; + caldav = 9314; }; exposeTransmissionRPC = false; }; |
