mirror of
https://github.com/nix-community/home-manager
synced 2024-12-26 03:39:47 +01:00
9f9e277b60
These (and the `*MD` functions apart from `literalMD`) are now no-ops in nixpkgs and serve no purpose other than to add additional noise and potentially mislead people into thinking unmarked DocBook documentation will still be accepted. Note that if backporting changes including documentation to 23.05, the `mdDoc` calls will need to be re-added. To reproduce this commit, run: $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \ nix shell nixpkgs#coreutils \ -c find . -name '*.nix' \ -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \ --strip {} + $ ./format
204 lines
6.2 KiB
Nix
204 lines
6.2 KiB
Nix
{ 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";
|
||
description = ''
|
||
How often to run {command}`muchsync`. This
|
||
value is passed to the systemd timer configuration as the
|
||
`OnCalendar` option. See
|
||
{manpage}`systemd.time(7)`
|
||
for more information about the format.
|
||
'';
|
||
};
|
||
|
||
sshCommand = mkOption {
|
||
type = types.str;
|
||
default = "${pkgs.openssh}/bin/ssh -CTaxq";
|
||
defaultText = "ssh -CTaxq";
|
||
description = ''
|
||
Specifies a command line to pass to {command}`/bin/sh`
|
||
to execute a command on another machine.
|
||
|
||
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;
|
||
description = ''
|
||
Whether to propagate local changes to the remote.
|
||
'';
|
||
};
|
||
|
||
local = {
|
||
checkForModifiedFiles = mkOption {
|
||
type = types.bool;
|
||
default = false;
|
||
description = ''
|
||
Check for locally modified files.
|
||
Without this option, muchsync assumes that files in a maildir are
|
||
never edited.
|
||
|
||
{option}`checkForModifiedFiles` disables certain
|
||
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.
|
||
|
||
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;
|
||
description = ''
|
||
Whether to begin the synchronisation by running
|
||
{command}`notmuch new` locally.
|
||
'';
|
||
};
|
||
};
|
||
|
||
remote = {
|
||
host = mkOption {
|
||
type = types.str;
|
||
description = ''
|
||
Remote SSH host to synchronize with.
|
||
'';
|
||
};
|
||
|
||
muchsyncPath = mkOption {
|
||
type = types.str;
|
||
default = "";
|
||
defaultText = "$PATH/muchsync";
|
||
description = ''
|
||
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;
|
||
description = ''
|
||
Check for modified files on the remote side.
|
||
Without this option, muchsync assumes that files in a maildir are
|
||
never edited.
|
||
|
||
{option}`checkForModifiedFiles` disables certain
|
||
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.
|
||
|
||
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;
|
||
description = ''
|
||
Whether to begin the synchronisation by running
|
||
{command}`notmuch new` on the remote side.
|
||
'';
|
||
};
|
||
};
|
||
};
|
||
};
|
||
|
||
in {
|
||
meta.maintainers = with maintainers; [ pacien ];
|
||
|
||
options.services.muchsync = {
|
||
remotes = mkOption {
|
||
type = with types; attrsOf (submodule syncOptions);
|
||
default = { };
|
||
example = literalExpression ''
|
||
{
|
||
server = {
|
||
frequency = "*:0/10";
|
||
remote.host = "server.tld";
|
||
};
|
||
}
|
||
'';
|
||
description = ''
|
||
Muchsync remotes to synchronise with.
|
||
'';
|
||
};
|
||
};
|
||
|
||
config = let
|
||
mapRemotes = gen:
|
||
with attrsets;
|
||
mapAttrs'
|
||
(name: remoteCfg: nameValuePair "muchsync-${name}" (gen name remoteCfg))
|
||
cfg.remotes;
|
||
in mkIf (cfg.remotes != { }) {
|
||
assertions = [
|
||
(hm.assertions.assertPlatform "services.muchsync" pkgs platforms.linux)
|
||
|
||
{
|
||
assertion = config.programs.notmuch.enable;
|
||
message = ''
|
||
The muchsync module requires 'programs.notmuch.enable = true'.
|
||
'';
|
||
}
|
||
];
|
||
|
||
systemd.user.services = mapRemotes (name: remoteCfg: {
|
||
Unit = { Description = "muchsync sync service (${name})"; };
|
||
Service = {
|
||
CPUSchedulingPolicy = "idle";
|
||
IOSchedulingClass = "idle";
|
||
Environment = [
|
||
''"PATH=${pkgs.notmuch}/bin"''
|
||
''"NOTMUCH_CONFIG=${config.home.sessionVariables.NOTMUCH_CONFIG}"''
|
||
''"NMBGIT=${config.home.sessionVariables.NMBGIT}"''
|
||
];
|
||
ExecStart = concatStringsSep " " ([ "${pkgs.muchsync}/bin/muchsync" ]
|
||
++ [ "-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 != "")
|
||
"-r ${escapeShellArg remoteCfg.remote.muchsyncPath}"
|
||
++ optional remoteCfg.remote.checkForModifiedFiles "-F"
|
||
++ optional (!remoteCfg.remote.importNew) "--nonew");
|
||
};
|
||
});
|
||
|
||
systemd.user.timers = mapRemotes (name: remoteCfg: {
|
||
Unit = { Description = "muchsync periodic sync (${name})"; };
|
||
Timer = {
|
||
Unit = "muchsync-${name}.service";
|
||
OnCalendar = remoteCfg.frequency;
|
||
Persistent = true;
|
||
};
|
||
Install = { WantedBy = [ "timers.target" ]; };
|
||
});
|
||
};
|
||
}
|