From a7eab56be526bb0c052ffe187177268efabc4808 Mon Sep 17 00:00:00 2001 From: arjan-s Date: Wed, 30 Aug 2023 11:57:47 +0200 Subject: [PATCH] programs.khal: add `settings` option (#4375) --- modules/programs/khal.nix | 26 +++++++++++++++++-- tests/modules/programs/khal/config.nix | 14 ++++++++-- .../programs/khal/khal-config-expected | 26 +++++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 tests/modules/programs/khal/khal-config-expected diff --git a/modules/programs/khal.nix b/modules/programs/khal.nix index 56a7d389f..8fc0e0892 100644 --- a/modules/programs/khal.nix +++ b/modules/programs/khal.nix @@ -7,6 +7,8 @@ let cfg = config.programs.khal; + iniFormat = pkgs.formats.ini { }; + khalCalendarAccounts = filterAttrs (_: a: a.khal.enable) config.accounts.calendar.accounts; @@ -147,6 +149,7 @@ let in { options.programs.khal = { enable = mkEnableOption "khal, a CLI calendar application"; + locale = mkOption { type = lib.types.submodule { options = localeOptions; }; description = '' @@ -154,6 +157,25 @@ in { ''; default = { }; }; + + settings = mkOption { + type = iniFormat.type; + default = { }; + example = literalExpression '' + { + default = { + default_calendar = "Calendar"; + timedelta = "5d"; + }; + view = { + agenda_event_format = + "{calendar-color}{cancelled}{start-end-time-style} {title}{repeat-symbol}{reset}"; + }; + }''; + description = '' + Configuration options to add to the various sections in the configuration file. + ''; + }; }; config = mkIf cfg.enable { @@ -161,7 +183,7 @@ in { xdg.configFile."khal/config".text = concatStringsSep "\n" ([ "[calendars]" ] ++ mapAttrsToList genCalendarStr khalAccounts ++ [ - (generators.toINI { } { + (generators.toINI { } (recursiveUpdate cfg.settings { locale = definedAttrs (cfg.locale // { _module = null; }); default = optionalAttrs (!isNull primaryAccount) { @@ -171,7 +193,7 @@ in { else primaryAccount.primaryCollection; }; - }) + })) ]); }; } diff --git a/tests/modules/programs/khal/config.nix b/tests/modules/programs/khal/config.nix index 1633d132b..a2eb8bf13 100644 --- a/tests/modules/programs/khal/config.nix +++ b/tests/modules/programs/khal/config.nix @@ -1,7 +1,15 @@ { ... }: { - programs.khal.enable = true; + programs.khal = { + enable = true; + settings = { + default.timedelta = "5d"; + view.agenda_event_format = + "{calendar-color}{cancelled}{start-end-time-style} {title}{repeat-symbol}{reset}"; + }; + + }; accounts.calendar = { basePath = "$XDG_CONFIG_HOME/cal"; accounts = { @@ -27,6 +35,8 @@ test.stubs = { khal = { }; }; nmt.script = '' - assertFileExists home-files/.config/khal/config + configFile=home-files/.config/khal/config + assertFileExists $configFile + assertFileContent $configFile ${./khal-config-expected} ''; } diff --git a/tests/modules/programs/khal/khal-config-expected b/tests/modules/programs/khal/khal-config-expected new file mode 100644 index 000000000..361db2d68 --- /dev/null +++ b/tests/modules/programs/khal/khal-config-expected @@ -0,0 +1,26 @@ +[calendars] +[[test]] +path = /home/hm-user/$XDG_CONFIG_HOME/cal/test/ +readonly = True +priority=10 +type=calendar + + + +[default] +default_calendar=test +highlight_event_days=true +timedelta=5d + +[locale] +dateformat=%x +datetimeformat=%c +firstweekday=0 +longdateformat=%x +longdatetimeformat=%c +timeformat=%X +unicode_symbols=true +weeknumbers=off + +[view] +agenda_event_format={calendar-color}{cancelled}{start-end-time-style} {title}{repeat-symbol}{reset}