fork/home-manager
git clone https://git.julia.blue/fork/home-manager
4a26e210
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . accounts . calendar ; 8 9localModule = name : 10types . submodule { 11options = { 12path = mkOption { 13type = types . str ; 14default = " ${ cfg . basePath } / ${ name } " ; 15defaultText = "‹accounts.calendar.basePath›/‹name›" ; 16description = "The path of the storage." ; 17}; 18 19type = mkOption { 20type = types . enum [ "filesystem" "singlefile" ]; 21description = "The type of the storage." ; 22}; 23 24fileExt = mkOption { 25type = types . nullOr types . str ; 26default = null ; 27description = "The file extension to use." ; 28}; 29 30encoding = mkOption { 31type = types . nullOr types . str ; 32default = null ; 33description = '' 34File encoding for items, both content and file name. 35Defaults to UTF-8. 36'' ; 37}; 38}; 39}; 40 41remoteModule = types . submodule { 42options = { 43type = mkOption { 44type = types . enum [ "caldav" "http" "google_calendar" ]; 45description = "The type of the storage." ; 46}; 47 48url = mkOption { 49type = types . nullOr types . str ; 50default = null ; 51description = "The URL of the storage." ; 52}; 53 54userName = mkOption { 55type = types . nullOr types . str ; 56default = null ; 57description = "User name for authentication." ; 58}; 59 60# userNameCommand = mkOption { 61# type = types.nullOr (types.listOf types.str); 62# default = null; 63# example = [ "~/get-username.sh" ]; 64# description = '' 65# A command that prints the user name to standard output. 66# ''; 67# }; 68 69passwordCommand = mkOption { 70type = types . nullOr ( types . listOf types . str ); 71default = null ; 72example = [ "pass" "caldav" ]; 73description = '' 74A command that prints the password to standard output. 75'' ; 76}; 77}; 78}; 79 80calendarOpts = { name , config , ...} :{ 81options = { 82name = mkOption { 83type = types . str ; 84readOnly = true ; 85description = '' 86Unique identifier of the calendar. This is set to the 87attribute name of the calendar configuration. 88'' ; 89}; 90 91primary = mkOption { 92type = types . bool ; 93default = false ; 94description = '' 95Whether this is the primary account. Only one account may be 96set as primary. 97'' ; 98}; 99 100primaryCollection = mkOption { 101type = types . str ; 102description = '' 103The primary collection of the account. Required when an 104account has multiple collections. 105'' ; 106}; 107 108local = mkOption { 109type = types . nullOr ( localModule name ); 110default = null ; 111description = '' 112Local configuration for the calendar. 113'' ; 114}; 115 116remote = mkOption { 117type = types . nullOr remoteModule ; 118default = null ; 119description = '' 120Remote configuration for the calendar. 121'' ; 122}; 123}; 124 125config = { name = name ; }; 126}; 127 128in { 129options . accounts . calendar = { 130basePath = mkOption { 131type = types . str ; 132apply = p : 133if hasPrefix "/" p then p else " ${ config . home . homeDirectory } / ${ p } " ; 134description = '' 135The base directory in which to save calendars. May be a 136relative path, in which case it is relative the home 137directory. 138'' ; 139}; 140 141accounts = mkOption { 142type = types . attrsOf ( types . submodule [ 143calendarOpts 144( import ../programs/vdirsyncer-accounts.nix ) 145( import ../programs/khal-accounts.nix ) 146( import ../programs/khal-calendar-accounts.nix ) 147]); 148default = { }; 149description = "List of calendars." ; 150}; 151}; 152config = mkIf ( cfg . accounts != { }) { 153assertions = let 154primaries = 155catAttrs "name" ( filter ( a :a . primary ) ( attrValues cfg . accounts )); 156in [{ 157assertion = length primaries <= 1 ; 158message = "Must have at most one primary calendar account but found " 159+ toString ( length primaries ) + ", namely " 160+ concatStringsSep ", " primaries ; 161}]; 162}; 163}