@@ -3,120 +3,76 @@
33with lib;
44
55let
6−
76 cfg = config.services.rsyncd;
8−
9− motdFile = builtins.toFile "rsyncd-motd" cfg.motd;
10−
11− foreach = attrs: f:
12− concatStringsSep "\n" (mapAttrsToList f attrs);
13−
14− cfgFile = ''
15− ${optionalString (cfg.motd != "") "motd file = ${motdFile}"}
16− ${optionalString (cfg.address != "") "address = ${cfg.address}"}
17− ${optionalString (cfg.port != 873) "port = ${toString cfg.port}"}
18− ${cfg.extraConfig}
19− ${foreach cfg.modules (name: module: ''
20− [${name}]
21− ${foreach module (k: v:
22− "${k} = ${v}"
23− )}
24− '')}
25− '';
26−in
27−
28−{
7+ settingsFormat = pkgs.formats.ini { };
8+ configFile = settingsFormat.generate "rsyncd.conf" cfg.settings;
9+in {
2910 options = {
3011 services.rsyncd = {
3112
3213 enable = mkEnableOption "the rsync daemon";
3314
34− motd = mkOption {
35− type = types.str;
36− default = "";
37− description = ''
38− Message of the day to display to clients on each connect.
39− This usually contains site information and any legal notices.
40− '';
41− };
42−
4315 port = mkOption {
4416 default = 873;
45− type = types.int;
17+ type = types.port;
4618 description = "TCP port the daemon will listen on.";
4719 };
4820
49− address = mkOption {
50− default = "";
51− example = "192.168.1.2";
52− description = ''
53− IP address the daemon will listen on; rsyncd will listen on
54− all addresses if this is not specified.
55− '';
56− };
57−
58− extraConfig = mkOption {
59− type = types.lines;
60− default = "";
61− description = ''
62− Lines of configuration to add to rsyncd globally.
63− See <command>man rsyncd.conf</command> for options.
64− '';
65− };
66−
67− modules = mkOption {
68− default = {};
69− description = ''
70− A set describing exported directories.
71− See <command>man rsyncd.conf</command> for options.
72− '';
73− type = types.attrsOf (types.attrsOf types.str);
74− example = literalExample ''
75− { srv =
76− { path = "/srv";
77− "read only" = "yes";
78− comment = "Public rsync share.";
79− };
80− }
81− '';
82− };
83−
84− user = mkOption {
85− type = types.str;
86− default = "root";
87− description = ''
88− The user to run the daemon as.
89− By default the daemon runs as root.
90− '';
91− };
92−
93− group = mkOption {
94− type = types.str;
95− default = "root";
21+ settings = mkOption {
22+ inherit (settingsFormat) type;
23+ default = { };
24+ example = {
25+ global = {
26+ uid = "nobody";
27+ gid = "nobody";
28+ "use chroot" = true;
29+ "max connections" = 4;
30+ };
31+ ftp = {
32+ path = "/var/ftp/./pub";
33+ comment = "whole ftp area";
34+ };
35+ cvs = {
36+ path = "/data/cvs";
37+ comment = "CVS repository (requires authentication)";
38+ "auth users" = [ "tridge" "susan" ];
39+ "secrets file" = "/etc/rsyncd.secrets";
40+ };
41+ };
9642 description = ''
97− The group to run the daemon as.
98− By default the daemon runs as root.
43+ Configuration for rsyncd. See
44+ <citerefentry><refentrytitle>rsyncd.conf</refentrytitle>
45+ <manvolnum>5</manvolnum></citerefentry>.
9946 '';
10047 };
10148
10249 };
10350 };
10451
105− ###### implementation
52+ imports = (map (option:
53+ mkRemovedOptionModule [ "services" "rsyncd" option ]
54+ "This option was removed in favor of `services.rsyncd.settings`.") [
55+ "address"
56+ "extraConfig"
57+ "motd"
58+ "user"
59+ "group"
60+ ]);
10661
10762 config = mkIf cfg.enable {
10863
109− environment.etc."rsyncd.conf".text = cfgFile;
64+ services.rsyncd.settings.global.port = toString cfg.port;
11065
11166 systemd.services.rsyncd = {
11267 description = "Rsync daemon";
11368 wantedBy = [ "multi-user.target" ];
114− restartTriggers = [ config.environment.etc."rsyncd.conf".source ];
115− serviceConfig = {
116− ExecStart = "${pkgs.rsync}/bin/rsync --daemon --no-detach";
117− User = cfg.user;
118− Group = cfg.group;
119− };
69+ serviceConfig.ExecStart =
70+ "${pkgs.rsync}/bin/rsync --daemon --no-detach --config=${configFile}";
12071 };
12172 };
73+
74+ meta.maintainers = with lib.maintainers; [ ehmry ];
75+
76+ # TODO: socket activated rsyncd
77+
12278}