at 18.09-beta 2.3 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.radicale; 8 9 confFile = pkgs.writeText "radicale.conf" cfg.config; 10 11 # This enables us to default to version 2 while still not breaking configurations of people with version 1 12 defaultPackage = if versionAtLeast config.system.stateVersion "17.09" then { 13 pkg = pkgs.radicale2; 14 text = "pkgs.radicale2"; 15 } else { 16 pkg = pkgs.radicale1; 17 text = "pkgs.radicale1"; 18 }; 19in 20 21{ 22 23 options = { 24 services.radicale.enable = mkOption { 25 type = types.bool; 26 default = false; 27 description = '' 28 Enable Radicale CalDAV and CardDAV server. 29 ''; 30 }; 31 32 services.radicale.package = mkOption { 33 type = types.package; 34 default = defaultPackage.pkg; 35 defaultText = defaultPackage.text; 36 description = '' 37 Radicale package to use. This defaults to version 1.x if 38 <literal>system.stateVersion &lt; 17.09</literal> and version 2.x 39 otherwise. 40 ''; 41 }; 42 43 services.radicale.config = mkOption { 44 type = types.string; 45 default = ""; 46 description = '' 47 Radicale configuration, this will set the service 48 configuration file. 49 ''; 50 }; 51 52 services.radicale.extraArgs = mkOption { 53 type = types.listOf types.string; 54 default = []; 55 description = "Extra arguments passed to the Radicale daemon."; 56 }; 57 }; 58 59 config = mkIf cfg.enable { 60 environment.systemPackages = [ cfg.package ]; 61 62 users.users = singleton 63 { name = "radicale"; 64 uid = config.ids.uids.radicale; 65 description = "radicale user"; 66 home = "/var/lib/radicale"; 67 createHome = true; 68 }; 69 70 users.groups = singleton 71 { name = "radicale"; 72 gid = config.ids.gids.radicale; 73 }; 74 75 systemd.services.radicale = { 76 description = "A Simple Calendar and Contact Server"; 77 after = [ "network.target" ]; 78 wantedBy = [ "multi-user.target" ]; 79 serviceConfig = { 80 ExecStart = concatStringsSep " " ([ 81 "${cfg.package}/bin/radicale" "-C" confFile 82 ] ++ ( 83 map escapeShellArg cfg.extraArgs 84 )); 85 User = "radicale"; 86 Group = "radicale"; 87 }; 88 }; 89 }; 90 91 meta.maintainers = with lib.maintainers; [ aneeshusa infinisil ]; 92}