rsync service: modernize config file generation
This commit is contained in:
parent
d4ef5ac0e9
commit
541377e5f0
@ -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
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -91,10 +90,7 @@ 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";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user