Merge pull request #27993 from Nadrieril/rsync-run-as-user

rsync service: allow running as user (plus some tweaks)
This commit is contained in:
Franz Pletz 2017-08-11 19:12:46 +02:00 committed by GitHub
commit 991745046f

View File

@ -8,22 +8,21 @@ let
motdFile = builtins.toFile "rsyncd-motd" cfg.motd; motdFile = builtins.toFile "rsyncd-motd" cfg.motd;
moduleConfig = name: foreach = attrs: f:
let module = getAttr name cfg.modules; in concatStringsSep "\n" (mapAttrsToList f attrs);
"[${name}]\n " + (toString (
map
(key: "${key} = ${toString (getAttr key module)}\n")
(attrNames module)
));
cfgFile = builtins.toFile "rsyncd.conf" cfgFile = ''
''
${optionalString (cfg.motd != "") "motd file = ${motdFile}"} ${optionalString (cfg.motd != "") "motd file = ${motdFile}"}
${optionalString (cfg.address != "") "address = ${cfg.address}"} ${optionalString (cfg.address != "") "address = ${cfg.address}"}
${optionalString (cfg.port != 873) "port = ${toString cfg.port}"} ${optionalString (cfg.port != 873) "port = ${toString cfg.port}"}
${cfg.extraConfig} ${cfg.extraConfig}
${toString (map moduleConfig (attrNames cfg.modules))} ${foreach cfg.modules (name: module: ''
''; [${name}]
${foreach module (k: v:
"${k} = ${v}"
)}
'')}
'';
in in
{ {
@ -84,6 +83,24 @@ in
}; };
}; };
user = mkOption {
type = types.str;
default = "root";
description = ''
The user to run the daemon as.
By default the daemon runs as root.
'';
};
group = mkOption {
type = types.str;
default = "root";
description = ''
The group to run the daemon as.
By default the daemon runs as root.
'';
};
}; };
}; };
@ -91,16 +108,17 @@ in
config = mkIf cfg.enable { config = mkIf cfg.enable {
environment.etc = singleton { environment.etc."rsyncd.conf".text = cfgFile;
source = cfgFile;
target = "rsyncd.conf";
};
systemd.services.rsyncd = { systemd.services.rsyncd = {
description = "Rsync daemon"; description = "Rsync daemon";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStart = "${pkgs.rsync}/bin/rsync --daemon --no-detach"; restartTriggers = [ config.environment.etc."rsyncd.conf".source ];
serviceConfig = {
ExecStart = "${pkgs.rsync}/bin/rsync --daemon --no-detach";
User = cfg.user;
Group = cfg.group;
};
}; };
}; };
} }