fork/home-manager
git clone https://git.julia.blue/fork/home-manager
a7eab56b
master
1# khal config loader is sensitive to leading space ! 2{ config , lib , pkgs , ...} : 3 4with lib ; 5 6let 7 8cfg = config . programs . khal ; 9 10iniFormat = pkgs . formats . ini { }; 11 12khalCalendarAccounts = 13filterAttrs ( _ :a :a . khal . enable ) config . accounts . calendar . accounts ; 14 15khalContactAccounts = mapAttrs ( _ :v :v // { type = "birthdays" ; }) 16( filterAttrs ( _ :a :a . khal . enable ) config . accounts . contact . accounts ); 17 18khalAccounts = khalCalendarAccounts // khalContactAccounts ; 19 20primaryAccount = findSingle ( a :a . primary ) null null 21( mapAttrsToList ( n :v :v // { name = n ; }) khalAccounts ); 22 23definedAttrs = filterAttrs ( _ :v :! isNull v ); 24 25toKeyValueIfDefined = attrs :generators . toKeyValue { } ( definedAttrs attrs ); 26 27genCalendarStr = name :value : 28concatStringsSep "\n" ([ 29"[[ ${ name } ]]" 30"path = ${ 31value . local . path + "/" 32+ ( optionalString ( value . khal . type == "discover" ) value . khal . glob ) 33} " 34] ++ optional ( value . khal . readOnly ) "readonly = True" ++ [ 35( toKeyValueIfDefined ( getAttrs [ "type" "color" "priority" ] value . khal )) 36] ++ [ "\n" ]); 37 38localeFormatOptions = let 39T = lib . types ; 40suffix = '' 41Format strings are for Python `strftime`, similarly to 42{manpage}`strftime(3)`. 43'' ; 44in { 45dateformat = mkOption { 46type = T . str ; 47default = "%x" ; 48description = '' 49khal will display and understand all dates in this format. 50 51${ suffix } 52'' ; 53}; 54 55timeformat = mkOption { 56type = T . str ; 57default = "%X" ; 58description = '' 59khal will display and understand all times in this format. 60 61${ suffix } 62'' ; 63}; 64 65datetimeformat = mkOption { 66type = T . str ; 67default = "%c" ; 68description = '' 69khal will display and understand all datetimes in this format. 70 71${ suffix } 72'' ; 73}; 74 75longdateformat = mkOption { 76type = T . str ; 77default = "%x" ; 78description = '' 79khal will display and understand all dates in this format. 80It should contain a year (e.g. `%Y`). 81 82${ suffix } 83'' ; 84}; 85 86longdatetimeformat = mkOption { 87type = T . str ; 88default = "%c" ; 89description = '' 90khal will display and understand all datetimes in this format. 91It should contain a year (e.g. `%Y`). 92 93${ suffix } 94'' ; 95}; 96}; 97 98localeOptions = let T = lib . types ; 99in localeFormatOptions // { 100unicode_symbols = mkOption { 101type = T . bool ; 102default = true ; 103description = '' 104By default khal uses some Unicode symbols (as in "non-ASCII") as 105indicators for things like repeating events. 106If your font, encoding etc. does not support those symbols, set this 107to false (this will enable ASCII-based replacements). 108'' ; 109}; 110 111default_timezone = mkOption { 112type = T . nullOr T . str ; 113default = null ; 114description = '' 115Default for new events or if khal does not understand the timezone 116in an ical file. 117If `null`, the timezone of your computer will be used. 118'' ; 119}; 120 121local_timezone = mkOption { 122type = T . nullOr T . str ; 123default = null ; 124description = '' 125khal will show all times in this timezone. 126If `null`, the timezone of your computer will be used. 127'' ; 128}; 129 130firstweekday = mkOption { 131type = T . ints . between 0 6 ; 132default = 0 ; 133description = '' 134The first day of the week, where Monday is 0 and Sunday is 6. 135'' ; 136}; 137 138weeknumbers = mkOption { 139type = T . enum [ "off" "left" "right" ]; 140default = "off" ; 141description = '' 142Enable week numbers in calendar and interactive (ikhal) mode. 143As those are ISO week numbers, they only work properly if 144{option}`firstweekday` is set to 0. 145'' ; 146}; 147}; 148 149in { 150options . programs . khal = { 151enable = mkEnableOption "khal, a CLI calendar application" ; 152 153locale = mkOption { 154type = lib . types . submodule { options = localeOptions ; }; 155description = '' 156khal locale settings. 157'' ; 158default = { }; 159}; 160 161settings = mkOption { 162type = iniFormat . type ; 163default = { }; 164example = literalExpression '' 165{ 166default = { 167default_calendar = "Calendar"; 168timedelta = "5d"; 169}; 170view = { 171agenda_event_format = 172"{calendar-color}{cancelled}{start-end-time-style} {title}{repeat-symbol}{reset}"; 173}; 174}'' ; 175description = '' 176Configuration options to add to the various sections in the configuration file. 177'' ; 178}; 179}; 180 181config = mkIf cfg . enable { 182home . packages = [ pkgs . khal ]; 183 184xdg . configFile . "khal/config" . text = concatStringsSep "\n" ([ "[calendars]" ] 185++ mapAttrsToList genCalendarStr khalAccounts ++ [ 186( generators . toINI { } ( recursiveUpdate cfg . settings { 187locale = definedAttrs ( cfg . locale // { _module = null ; }); 188 189default = optionalAttrs ( ! isNull primaryAccount ) { 190highlight_event_days = true ; 191default_calendar = if isNull primaryAccount . primaryCollection then 192primaryAccount . name 193else 194primaryAccount . primaryCollection ; 195}; 196})) 197]); 198}; 199}