2019-07-22 22:15:45 +00:00
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
|
|
# Documentation was partially copied from the muchsync manual.
|
|
|
|
|
# See http://www.muchsync.org/muchsync.html
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
cfg = config.services.muchsync;
|
|
|
|
|
syncOptions = {
|
|
|
|
|
options = {
|
|
|
|
|
frequency = mkOption {
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = "*:0/5";
|
2023-07-01 23:45:18 +00:00
|
|
|
|
description = ''
|
2023-06-30 23:30:13 +00:00
|
|
|
|
How often to run {command}`muchsync`. This
|
2019-07-22 22:15:45 +00:00
|
|
|
|
value is passed to the systemd timer configuration as the
|
2023-06-30 23:30:13 +00:00
|
|
|
|
`OnCalendar` option. See
|
|
|
|
|
{manpage}`systemd.time(7)`
|
2019-07-22 22:15:45 +00:00
|
|
|
|
for more information about the format.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sshCommand = mkOption {
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = "${pkgs.openssh}/bin/ssh -CTaxq";
|
|
|
|
|
defaultText = "ssh -CTaxq";
|
2023-07-01 23:45:18 +00:00
|
|
|
|
description = ''
|
2023-06-30 23:30:13 +00:00
|
|
|
|
Specifies a command line to pass to {command}`/bin/sh`
|
2019-07-22 22:15:45 +00:00
|
|
|
|
to execute a command on another machine.
|
2023-06-30 23:30:13 +00:00
|
|
|
|
|
2019-07-22 22:15:45 +00:00
|
|
|
|
Note that because this string is passed to the shell,
|
|
|
|
|
special characters including spaces may need to be escaped.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
upload = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
2023-07-01 23:45:18 +00:00
|
|
|
|
description = ''
|
2019-07-22 22:15:45 +00:00
|
|
|
|
Whether to propagate local changes to the remote.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
local = {
|
|
|
|
|
checkForModifiedFiles = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
2023-07-01 23:45:18 +00:00
|
|
|
|
description = ''
|
2019-07-22 22:15:45 +00:00
|
|
|
|
Check for locally modified files.
|
|
|
|
|
Without this option, muchsync assumes that files in a maildir are
|
|
|
|
|
never edited.
|
2023-06-30 23:30:13 +00:00
|
|
|
|
|
|
|
|
|
{option}`checkForModifiedFiles` disables certain
|
2019-07-22 22:15:45 +00:00
|
|
|
|
optimizations so as to make muchsync at least check the timestamp on
|
|
|
|
|
every file, which will detect modified files at the cost of a longer
|
|
|
|
|
startup time.
|
2023-06-30 23:30:13 +00:00
|
|
|
|
|
2019-07-22 22:15:45 +00:00
|
|
|
|
This option is useful if your software regularly modifies the
|
|
|
|
|
contents of mail files (e.g., because you are running offlineimap
|
|
|
|
|
with "synclabels = yes").
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
importNew = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
2023-07-01 23:45:18 +00:00
|
|
|
|
description = ''
|
2019-07-22 22:15:45 +00:00
|
|
|
|
Whether to begin the synchronisation by running
|
2023-06-30 23:30:13 +00:00
|
|
|
|
{command}`notmuch new` locally.
|
2019-07-22 22:15:45 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
remote = {
|
|
|
|
|
host = mkOption {
|
|
|
|
|
type = types.str;
|
2023-07-01 23:45:18 +00:00
|
|
|
|
description = ''
|
2019-07-22 22:15:45 +00:00
|
|
|
|
Remote SSH host to synchronize with.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
muchsyncPath = mkOption {
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = "";
|
|
|
|
|
defaultText = "$PATH/muchsync";
|
2023-07-01 23:45:18 +00:00
|
|
|
|
description = ''
|
2019-07-22 22:15:45 +00:00
|
|
|
|
Specifies the path to muchsync on the server.
|
|
|
|
|
Ordinarily, muchsync should be in the default PATH on the server
|
|
|
|
|
so this option is not required.
|
|
|
|
|
However, this option is useful if you have to install muchsync in
|
|
|
|
|
a non-standard place or wish to test development versions of the
|
|
|
|
|
code.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
checkForModifiedFiles = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
2023-07-01 23:45:18 +00:00
|
|
|
|
description = ''
|
2019-07-22 22:15:45 +00:00
|
|
|
|
Check for modified files on the remote side.
|
|
|
|
|
Without this option, muchsync assumes that files in a maildir are
|
|
|
|
|
never edited.
|
2023-06-30 23:30:13 +00:00
|
|
|
|
|
|
|
|
|
{option}`checkForModifiedFiles` disables certain
|
2019-07-22 22:15:45 +00:00
|
|
|
|
optimizations so as to make muchsync at least check the timestamp on
|
|
|
|
|
every file, which will detect modified files at the cost of a longer
|
|
|
|
|
startup time.
|
2023-06-30 23:30:13 +00:00
|
|
|
|
|
2019-07-22 22:15:45 +00:00
|
|
|
|
This option is useful if your software regularly modifies the
|
|
|
|
|
contents of mail files (e.g., because you are running offlineimap
|
|
|
|
|
with "synclabels = yes").
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
importNew = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
2023-07-01 23:45:18 +00:00
|
|
|
|
description = ''
|
2019-07-22 22:15:45 +00:00
|
|
|
|
Whether to begin the synchronisation by running
|
2023-06-30 23:30:13 +00:00
|
|
|
|
{command}`notmuch new` on the remote side.
|
2019-07-22 22:15:45 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
meta.maintainers = with maintainers; [ pacien ];
|
|
|
|
|
|
|
|
|
|
options.services.muchsync = {
|
|
|
|
|
remotes = mkOption {
|
|
|
|
|
type = with types; attrsOf (submodule syncOptions);
|
|
|
|
|
default = { };
|
2021-10-09 09:14:08 +00:00
|
|
|
|
example = literalExpression ''
|
2019-07-22 22:15:45 +00:00
|
|
|
|
{
|
|
|
|
|
server = {
|
|
|
|
|
frequency = "*:0/10";
|
|
|
|
|
remote.host = "server.tld";
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
'';
|
2023-07-01 23:45:18 +00:00
|
|
|
|
description = ''
|
2019-07-22 22:15:45 +00:00
|
|
|
|
Muchsync remotes to synchronise with.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = let
|
2020-02-01 23:39:17 +00:00
|
|
|
|
mapRemotes = gen:
|
|
|
|
|
with attrsets;
|
|
|
|
|
mapAttrs'
|
2019-07-22 22:15:45 +00:00
|
|
|
|
(name: remoteCfg: nameValuePair "muchsync-${name}" (gen name remoteCfg))
|
|
|
|
|
cfg.remotes;
|
|
|
|
|
in mkIf (cfg.remotes != { }) {
|
2021-07-07 21:24:27 +00:00
|
|
|
|
assertions = [
|
|
|
|
|
(hm.assertions.assertPlatform "services.muchsync" pkgs platforms.linux)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
assertion = config.programs.notmuch.enable;
|
|
|
|
|
message = ''
|
|
|
|
|
The muchsync module requires 'programs.notmuch.enable = true'.
|
|
|
|
|
'';
|
|
|
|
|
}
|
|
|
|
|
];
|
2019-07-22 22:15:45 +00:00
|
|
|
|
|
|
|
|
|
systemd.user.services = mapRemotes (name: remoteCfg: {
|
2020-02-01 23:39:17 +00:00
|
|
|
|
Unit = { Description = "muchsync sync service (${name})"; };
|
2019-07-22 22:15:45 +00:00
|
|
|
|
Service = {
|
|
|
|
|
CPUSchedulingPolicy = "idle";
|
|
|
|
|
IOSchedulingClass = "idle";
|
|
|
|
|
Environment = [
|
|
|
|
|
''"PATH=${pkgs.notmuch}/bin"''
|
|
|
|
|
''"NOTMUCH_CONFIG=${config.home.sessionVariables.NOTMUCH_CONFIG}"''
|
|
|
|
|
''"NMBGIT=${config.home.sessionVariables.NMBGIT}"''
|
|
|
|
|
];
|
2020-02-01 23:39:17 +00:00
|
|
|
|
ExecStart = concatStringsSep " " ([ "${pkgs.muchsync}/bin/muchsync" ]
|
2019-07-22 22:15:45 +00:00
|
|
|
|
++ [ "-s ${escapeShellArg remoteCfg.sshCommand}" ]
|
|
|
|
|
++ optional (!remoteCfg.upload) "--noup"
|
|
|
|
|
|
|
|
|
|
# local configuration
|
|
|
|
|
++ optional remoteCfg.local.checkForModifiedFiles "-F"
|
|
|
|
|
++ optional (!remoteCfg.local.importNew) "--nonew"
|
|
|
|
|
|
|
|
|
|
# remote configuration
|
|
|
|
|
++ [ (escapeShellArg remoteCfg.remote.host) ]
|
|
|
|
|
++ optional (remoteCfg.remote.muchsyncPath != "")
|
2020-02-01 23:39:17 +00:00
|
|
|
|
"-r ${escapeShellArg remoteCfg.remote.muchsyncPath}"
|
2019-07-22 22:15:45 +00:00
|
|
|
|
++ optional remoteCfg.remote.checkForModifiedFiles "-F"
|
2020-02-01 23:39:17 +00:00
|
|
|
|
++ optional (!remoteCfg.remote.importNew) "--nonew");
|
2019-07-22 22:15:45 +00:00
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
systemd.user.timers = mapRemotes (name: remoteCfg: {
|
2020-02-01 23:39:17 +00:00
|
|
|
|
Unit = { Description = "muchsync periodic sync (${name})"; };
|
2019-07-22 22:15:45 +00:00
|
|
|
|
Timer = {
|
|
|
|
|
Unit = "muchsync-${name}.service";
|
|
|
|
|
OnCalendar = remoteCfg.frequency;
|
|
|
|
|
Persistent = true;
|
|
|
|
|
};
|
2020-02-01 23:39:17 +00:00
|
|
|
|
Install = { WantedBy = [ "timers.target" ]; };
|
2019-07-22 22:15:45 +00:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|