qcal: add module

This commit is contained in:
Anton Mosich 2023-08-12 22:07:04 +02:00 committed by Robert Helgesson
parent ea59b79f31
commit 8eb8c212e5
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
11 changed files with 186 additions and 0 deletions

View file

@ -1193,6 +1193,13 @@ in
A new module is available: 'programs.pqiv'. A new module is available: 'programs.pqiv'.
''; '';
} }
{
time = "2023-08-22T16:06:52+00:00";
message = ''
A new module is available: 'programs.qcal'.
'';
}
]; ];
}; };
} }

View file

@ -173,6 +173,7 @@ let
./programs/pubs.nix ./programs/pubs.nix
./programs/pyenv.nix ./programs/pyenv.nix
./programs/pylint.nix ./programs/pylint.nix
./programs/qcal.nix
./programs/qutebrowser.nix ./programs/qutebrowser.nix
./programs/rbw.nix ./programs/rbw.nix
./programs/readline.nix ./programs/readline.nix

66
modules/programs/qcal.nix Normal file
View file

@ -0,0 +1,66 @@
{ config, lib, pkgs, ... }:
let
cfg = config.programs.qcal;
qcalAccounts = lib.attrValues
(lib.filterAttrs (_: a: a.qcal.enable) config.accounts.calendar.accounts);
rename = oldname:
builtins.getAttr oldname {
url = "Url";
userName = "Username";
passwordCommand = "PasswordCmd";
};
filteredAccounts = let
mkAccount = account:
lib.filterAttrs (_: v: v != null) (with account.remote; {
Url = url;
Username = if userName == null then null else userName;
PasswordCmd =
if passwordCommand == null then null else toString passwordCommand;
});
in map mkAccount qcalAccounts;
in {
meta.maintainers = with lib.maintainers; [ antonmosich ];
options = {
programs.qcal = {
enable = lib.mkEnableOption "qcal, a CLI calendar application";
timezone = lib.mkOption {
type = lib.types.singleLineStr;
default = "Local";
example = "Europe/Vienna";
description = "Timezone to display calendar entries in";
};
defaultNumDays = lib.mkOption {
type = lib.types.ints.positive;
default = 30;
description = "Default number of days to show calendar entries for";
};
};
accounts.calendar.accounts = lib.mkOption {
type = with lib.types;
attrsOf
(submodule { options.qcal.enable = lib.mkEnableOption "qcal access"; });
};
};
config = lib.mkIf cfg.enable {
home.packages = [ pkgs.qcal ];
xdg.configFile."qcal/config.json".source =
let jsonFormat = pkgs.formats.json { };
in jsonFormat.generate "qcal.json" {
DefaultNumDays = cfg.defaultNumDays;
Timezone = cfg.timezone;
Calendars = filteredAccounts;
};
};
}

View file

@ -120,6 +120,7 @@ import nmt {
./modules/programs/powerline-go ./modules/programs/powerline-go
./modules/programs/pubs ./modules/programs/pubs
./modules/programs/pyenv ./modules/programs/pyenv
./modules/programs/qcal
./modules/programs/qutebrowser ./modules/programs/qutebrowser
./modules/programs/readline ./modules/programs/readline
./modules/programs/ripgrep ./modules/programs/ripgrep

View file

@ -0,0 +1,5 @@
{
qcal-http = ./http-calendar.nix;
qcal-webdav = ./webdav-calendar.nix;
qcal-mixed = ./mixed.nix;
}

View file

@ -0,0 +1,9 @@
{
"Calendars": [
{
"Url": "https://example.com/events.ical"
}
],
"DefaultNumDays": 30,
"Timezone": "Local"
}

View file

@ -0,0 +1,18 @@
{ pkgs, lib, ... }:
{
programs.qcal.enable = true;
accounts.calendar.accounts.test = {
qcal.enable = true;
remote = { url = "https://example.com/events.ical"; };
};
test.stubs = { qcal = { }; };
nmt.script = ''
assertFileExists home-files/.config/qcal/config.json
assertFileContent home-files/.config/qcal/config.json ${
./http-calendar.json-expected
}
'';
}

View file

@ -0,0 +1,14 @@
{
"Calendars": [
{
"Url": "https://example.com/events.ical"
},
{
"PasswordCmd": "pass show calendar",
"Url": "https://cal.example.com/anton/work",
"Username": "anton"
}
],
"DefaultNumDays": 30,
"Timezone": "Local"
}

View file

@ -0,0 +1,28 @@
{ pkgs, lib, ... }:
{
programs.qcal.enable = true;
accounts.calendar.accounts = {
http-test = {
remote = { url = "https://example.com/events.ical"; };
qcal.enable = true;
};
webdav-test = {
remote = {
url = "https://cal.example.com/anton/work";
userName = "anton";
passwordCommand = [ "pass" "show" "calendar" ];
};
qcal.enable = true;
};
};
test.stubs = { qcal = { }; };
nmt.script = ''
assertFileExists home-files/.config/qcal/config.json
assertFileContent home-files/.config/qcal/config.json ${
./mixed.json-expected
}
'';
}

View file

@ -0,0 +1,11 @@
{
"Calendars": [
{
"PasswordCmd": "pass show calendar",
"Url": "https://cal.example.com/anton/work",
"Username": "anton"
}
],
"DefaultNumDays": 23,
"Timezone": "Europe/Berlin"
}

View file

@ -0,0 +1,26 @@
{ pkgs, lib, ... }:
{
programs.qcal = {
enable = true;
defaultNumDays = 23;
timezone = "Europe/Berlin";
};
accounts.calendar.accounts.test = {
qcal.enable = true;
remote = {
url = "https://cal.example.com/anton/work";
userName = "anton";
passwordCommand = [ "pass" "show" "calendar" ];
};
};
test.stubs = { qcal = { }; };
nmt.script = ''
assertFileExists home-files/.config/qcal/config.json
assertFileContent home-files/.config/qcal/config.json ${
./webdav-calendar.json-expected
}
'';
}