From 541377e5f0189819cfa50dacbb7569e26c06a3c0 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 21 Jul 2017 19:14:03 +0100 Subject: [PATCH] rsync service: modernize config file generation --- .../services/network-filesystems/rsyncd.nix | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/nixos/modules/services/network-filesystems/rsyncd.nix b/nixos/modules/services/network-filesystems/rsyncd.nix index 2018bfa14a57..a52fec4c4070 100644 --- a/nixos/modules/services/network-filesystems/rsyncd.nix +++ b/nixos/modules/services/network-filesystems/rsyncd.nix @@ -8,22 +8,21 @@ let motdFile = builtins.toFile "rsyncd-motd" cfg.motd; - moduleConfig = name: - let module = getAttr name cfg.modules; in - "[${name}]\n " + (toString ( - map - (key: "${key} = ${toString (getAttr key module)}\n") - (attrNames module) - )); + foreach = attrs: f: + concatStringsSep "\n" (mapAttrsToList f attrs); - cfgFile = builtins.toFile "rsyncd.conf" - '' + cfgFile = '' ${optionalString (cfg.motd != "") "motd file = ${motdFile}"} ${optionalString (cfg.address != "") "address = ${cfg.address}"} ${optionalString (cfg.port != 873) "port = ${toString cfg.port}"} ${cfg.extraConfig} - ${toString (map moduleConfig (attrNames cfg.modules))} - ''; + ${foreach cfg.modules (name: module: '' + [${name}] + ${foreach module (k: v: + "${k} = ${v}" + )} + '')} + ''; in { @@ -91,10 +90,7 @@ in config = mkIf cfg.enable { - environment.etc = singleton { - source = cfgFile; - target = "rsyncd.conf"; - }; + environment.etc."rsyncd.conf".text = cfgFile; systemd.services.rsyncd = { description = "Rsync daemon";