From 09af83576a877eda40512bfba30b47a1b13061fb Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Wed, 13 Nov 2024 20:47:40 +0100 Subject: Initial (public) commit --- module/default.nix | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 module/default.nix (limited to 'module/default.nix') diff --git a/module/default.nix b/module/default.nix new file mode 100644 index 0000000..774a361 --- /dev/null +++ b/module/default.nix @@ -0,0 +1,73 @@ +flake: { lib, config, pkgs, ... }: +with lib; +let + inherit (flake.packages.${pkgs.stdenv.hostPlatform.system}) icalproxy; + + cfg = config.services.icalproxy; +in { + options.services.icalproxy = with types; { + enable = mkEnableOption "icalproxy"; + calendarUrl = mkOption { + type = str; + }; + ignore = mkOption { + type = submodule { + options = { + locationRegexes = mkOption { + type = listOf str; + }; + summaryRegexes = mkOption { + type = listOf str; + }; + }; + }; + }; + port = mkOption { + type = str; + }; + userTokens = mkOption { + type = attrsOf (submodule { + options = { + hash = mkOption { + type = str; + }; + salt = mkOption { + type = str; + }; + }; + }); + }; + }; + + config = mkIf cfg.enable { + users.users.icalproxy = { + description = "icalproxy service user"; + isSystemUser = true; + group = "icalproxy"; + }; + + users.groups.icalproxy = {}; + + systemd.services.icalproxy = { + wants = [ "network-online.target" ]; + wantedBy = [ "multi-user.target" ]; + environment = { + CONFIG_FILE = pkgs.writeText "icalproxy-config.json" (builtins.toJSON { + calendar_url = cfg.calendarUrl; + ignore = { + location_regexes = cfg.ignore.locationRegexes; + summary_regexes = cfg.ignore.summaryRegexes; + }; + port = cfg.port; + user_tokens = cfg.userTokens; + }); + }; + serviceConfig = { + User = config.users.users.icalproxy.name; + Group = config.users.users.icalproxy.group; + Restart = "always"; + ExecStart = "${lib.getBin icalproxy}/bin/icalproxy"; + }; + }; + }; +} -- cgit v1.2.3