@@ -46,6 +46,13 @@ in {
4646 '';
4747 };
4848
49+ socketActivated = mkOption {
50+ default = false;
51+ type = types.bool;
52+ description =
53+ "If enabled Rsync will be socket-activated rather than run persistently.";
54+ };
55+
4956 };
5057 };
5158
@@ -63,12 +70,55 @@ in {
6370
6471 services.rsyncd.settings.global.port = toString cfg.port;
6572
66− systemd.services.rsyncd = {
67− description = "Rsync daemon";
68− wantedBy = [ "multi-user.target" ];
69− serviceConfig.ExecStart =
70− "${pkgs.rsync}/bin/rsync --daemon --no-detach --config=${configFile}";
73+ systemd = let
74+ serviceConfigSecurity = {
75+ ProtectSystem = "full";
76+ PrivateDevices = "on";
77+ NoNewPrivileges = "on";
78+ };
79+ in {
80+ services.rsync = {
81+ enable = !cfg.socketActivated;
82+ aliases = [ "rsyncd" ];
83+
84+ description = "fast remote file copy program daemon";
85+ after = [ "network.target" ];
86+ documentation = [ "man:rsync(1)" "man:rsyncd.conf(5)" ];
87+
88+ serviceConfig = serviceConfigSecurity // {
89+ ExecStart =
90+ "${pkgs.rsync}/bin/rsync --daemon --no-detach --config=${configFile}";
91+ RestartSec = 1;
92+ };
93+
94+ wantedBy = [ "multi-user.target" ];
95+ };
96+
97+ services."rsync@" = {
98+ description = "fast remote file copy program daemon";
99+ after = [ "network.target" ];
100+
101+ serviceConfig = serviceConfigSecurity // {
102+ ExecStart = "${pkgs.rsync}/bin/rsync --daemon --config=${configFile}";
103+ StandardInput = "socket";
104+ StandardOutput = "inherit";
105+ StandardError = "journal";
106+ };
107+ };
108+
109+ sockets.rsync = {
110+ enable = cfg.socketActivated;
111+
112+ description = "socket for fast remote file copy program daemon";
113+ conflicts = [ "rsync.service" ];
114+
115+ listenStreams = [ (toString cfg.port) ];
116+ socketConfig.Accept = true;
117+
118+ wantedBy = [ "sockets.target" ];
119+ };
71120 };
121+
72122 };
73123
74124 meta.maintainers = with lib.maintainers; [ ehmry ];