Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services/vdirsyncer: init #3912

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ let
./services/udiskie.nix
./services/unclutter.nix
./services/unison.nix
./services/vdirsyncer.nix
./services/volnoti.nix
./services/window-managers/awesome.nix
./services/window-managers/bspwm/default.nix
Expand Down
70 changes: 70 additions & 0 deletions modules/services/vdirsyncer.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{ pkgs, lib, config, ... }:
with lib;
let
cfg = config.services.vdirsyncer;
formatToUnknownFormat = settings:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the format they use is basically INI but with JSON values... https://github.com/pimutils/vdirsyncer/blob/079a156bf82fe86173d0d05ec0937703b5c6a735/vdirsyncer/cli/config.py#L151

So like,

settingsFormat = {
  type = types.attrsOf (types.attrsOf (pkgs.formats.json {}).type);
  generate = name: value: pkgs.writeText name (lib.generators.toINI {
    mkKeyValue = lib.generators.mkKeyValueDefault {
      mkValueString = builtins.toJSON;
    } " = ";
  } value);
};

let
quoteStr = s: ''"${s}"'';
mkKeyValue = name: value: "${name} = ${mkValue value}";
mkValue = value:
if builtins.isList value then
"[${concatStringsSep ", " (map mkValue value)}]"
else if builtins.isString value then
quoteStr value
else
(toString value);
mkSection = title: val: ''
[${title}]
${concatStringsSep "\n" (mapAttrsToList mkKeyValue val)}
'';
in concatStringsSep "\n" (mapAttrsToList mkSection settings);
cfgFile =
pkgs.writeText "vdirsyncer.conf" (formatToUnknownFormat cfg.settings);
in {
options.services.vdirsyncer = {
enable = mkEnableOption "synchronization of calendars";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enable = mkEnableOption "synchronization of calendars";
enable = mkEnableOption "synchronization of calendars via vdirsyncer";

settings = mkOption { type = types.attrs; };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a description, default value and better type (see above)

configFile = mkOption {
type = types.path;
default = cfgFile;
};
onBootSec = mkOption {
type = types.str;
default = "15min";
};
onUnitActiveSec = mkOption {
type = types.str;
default = "30min";
};
Comment on lines +27 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need descriptions. I'd also get rid of configFile for now, unless there's a good reason to have it.

};

config = mkIf cfg.enable {
systemd.user.timers.vdirsyncer = {
Unit = { Description = "Timer to synchronize calendars"; };

Timer = {
OnBootSec = cfg.onBootSec;
OnUnitActiveSec = cfg.onUnitActiveSec;
};

Install.WantedBy = [ "timers.target" ];
};

systemd.user.services.vdirsyncer = {
Unit = {
Description = "Synchronize your calendars";
After = [ "network-online.target" ];
Wants = [ "network-online.target" ];
};

Install.WantedBy = [ "default.target" ];

Service = {
ExecStart = "${pkgs.vdirsyncer}/bin/vdirsyncer -c ${cfgFile} sync";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to do metasync as well as sync.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned here: #3982 (comment)

we should probably do vdirsyncer discover before sync and metasync

Restart = "on-failure";
Type = "oneshot";
RestartSec = 30;
};
};
};
}