about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorFranz Pletz <fpletz@fnordicwalking.de>2017-08-11 19:12:46 +0200
committerGitHub <noreply@github.com>2017-08-11 19:12:46 +0200
commit991745046f51d95411436b02822e0daabf5246cc (patch)
tree15d87f84efda7c6a3b239a448d4d7816b8c6526b /nixos
parent7f9ac0eca9ab13127d1000e8da26a38de7fa657d (diff)
parenta4d07290cba3208a2ff930c8cfb594ff809ec7ad (diff)
downloadnixlib-991745046f51d95411436b02822e0daabf5246cc.tar
nixlib-991745046f51d95411436b02822e0daabf5246cc.tar.gz
nixlib-991745046f51d95411436b02822e0daabf5246cc.tar.bz2
nixlib-991745046f51d95411436b02822e0daabf5246cc.tar.lz
nixlib-991745046f51d95411436b02822e0daabf5246cc.tar.xz
nixlib-991745046f51d95411436b02822e0daabf5246cc.tar.zst
nixlib-991745046f51d95411436b02822e0daabf5246cc.zip
Merge pull request #27993 from Nadrieril/rsync-run-as-user
rsync service: allow running as user (plus some tweaks)
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/network-filesystems/rsyncd.nix54
1 files changed, 36 insertions, 18 deletions
diff --git a/nixos/modules/services/network-filesystems/rsyncd.nix b/nixos/modules/services/network-filesystems/rsyncd.nix
index 2018bfa14a57..054057d52ab1 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)
-    ));
-
-  cfgFile = builtins.toFile "rsyncd.conf"
-    ''
+  foreach = attrs: f:
+    concatStringsSep "\n" (mapAttrsToList f attrs);
+
+  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
 
 {
@@ -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 {
 
-    environment.etc = singleton {
-      source = cfgFile;
-      target = "rsyncd.conf";
-    };
+    environment.etc."rsyncd.conf".text = cfgFile;
 
     systemd.services.rsyncd = {
       description = "Rsync daemon";
       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;
+      };
     };
-
   };
 }