2020-04-24 23:36:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.rsyncd;
|
2020-10-07 09:15:18 +00:00
|
|
|
settingsFormat = pkgs.formats.ini { };
|
|
|
|
configFile = settingsFormat.generate "rsyncd.conf" cfg.settings;
|
|
|
|
in {
|
2020-04-24 23:36:52 +00:00
|
|
|
options = {
|
|
|
|
services.rsyncd = {
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "the rsync daemon";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
default = 873;
|
2020-10-07 09:15:18 +00:00
|
|
|
type = types.port;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "TCP port the daemon will listen on.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2020-10-07 09:15:18 +00:00
|
|
|
settings = mkOption {
|
|
|
|
inherit (settingsFormat) type;
|
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
global = {
|
|
|
|
uid = "nobody";
|
|
|
|
gid = "nobody";
|
|
|
|
"use chroot" = true;
|
|
|
|
"max connections" = 4;
|
|
|
|
};
|
|
|
|
ftp = {
|
|
|
|
path = "/var/ftp/./pub";
|
|
|
|
comment = "whole ftp area";
|
|
|
|
};
|
|
|
|
cvs = {
|
|
|
|
path = "/data/cvs";
|
|
|
|
comment = "CVS repository (requires authentication)";
|
|
|
|
"auth users" = [ "tridge" "susan" ];
|
|
|
|
"secrets file" = "/etc/rsyncd.secrets";
|
|
|
|
};
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-10-07 09:15:18 +00:00
|
|
|
Configuration for rsyncd. See
|
2022-08-21 13:32:41 +00:00
|
|
|
{manpage}`rsyncd.conf(5)`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
socketActivated = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "If enabled Rsync will be socket-activated rather than run persistently.";
|
2021-02-05 17:12:51 +00:00
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-10-07 09:15:18 +00:00
|
|
|
imports = (map (option:
|
|
|
|
mkRemovedOptionModule [ "services" "rsyncd" option ]
|
|
|
|
"This option was removed in favor of `services.rsyncd.settings`.") [
|
|
|
|
"address"
|
|
|
|
"extraConfig"
|
|
|
|
"motd"
|
|
|
|
"user"
|
|
|
|
"group"
|
|
|
|
]);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2020-10-07 09:15:18 +00:00
|
|
|
services.rsyncd.settings.global.port = toString cfg.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
systemd = let
|
|
|
|
serviceConfigSecurity = {
|
|
|
|
ProtectSystem = "full";
|
|
|
|
PrivateDevices = "on";
|
|
|
|
NoNewPrivileges = "on";
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
services.rsync = {
|
|
|
|
enable = !cfg.socketActivated;
|
2022-02-10 20:34:41 +00:00
|
|
|
aliases = [ "rsyncd.service" ];
|
2021-02-05 17:12:51 +00:00
|
|
|
|
|
|
|
description = "fast remote file copy program daemon";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
documentation = [ "man:rsync(1)" "man:rsyncd.conf(5)" ];
|
|
|
|
|
|
|
|
serviceConfig = serviceConfigSecurity // {
|
|
|
|
ExecStart =
|
|
|
|
"${pkgs.rsync}/bin/rsync --daemon --no-detach --config=${configFile}";
|
|
|
|
RestartSec = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
services."rsync@" = {
|
|
|
|
description = "fast remote file copy program daemon";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
|
|
|
serviceConfig = serviceConfigSecurity // {
|
|
|
|
ExecStart = "${pkgs.rsync}/bin/rsync --daemon --config=${configFile}";
|
|
|
|
StandardInput = "socket";
|
|
|
|
StandardOutput = "inherit";
|
|
|
|
StandardError = "journal";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
sockets.rsync = {
|
|
|
|
enable = cfg.socketActivated;
|
|
|
|
|
|
|
|
description = "socket for fast remote file copy program daemon";
|
|
|
|
conflicts = [ "rsync.service" ];
|
|
|
|
|
|
|
|
listenStreams = [ (toString cfg.port) ];
|
|
|
|
socketConfig.Accept = true;
|
|
|
|
|
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2021-02-05 17:12:51 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2020-10-07 09:15:18 +00:00
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ ehmry ];
|
|
|
|
|
|
|
|
# TODO: socket activated rsyncd
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|