diff --git a/nixos/modules/services/network-filesystems/rsyncd.nix b/nixos/modules/services/network-filesystems/rsyncd.nix index fa29e18a939..9f1263ddff5 100644 --- a/nixos/modules/services/network-filesystems/rsyncd.nix +++ b/nixos/modules/services/network-filesystems/rsyncd.nix @@ -3,120 +3,76 @@ with lib; let - cfg = config.services.rsyncd; - - motdFile = builtins.toFile "rsyncd-motd" cfg.motd; - - 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} - ${foreach cfg.modules (name: module: '' - [${name}] - ${foreach module (k: v: - "${k} = ${v}" - )} - '')} - ''; -in - -{ + settingsFormat = pkgs.formats.ini { }; + configFile = settingsFormat.generate "rsyncd.conf" cfg.settings; +in { options = { services.rsyncd = { enable = mkEnableOption "the rsync daemon"; - motd = mkOption { - type = types.str; - default = ""; - description = '' - Message of the day to display to clients on each connect. - This usually contains site information and any legal notices. - ''; - }; - port = mkOption { default = 873; - type = types.int; + type = types.port; description = "TCP port the daemon will listen on."; }; - address = mkOption { - default = ""; - example = "192.168.1.2"; + settings = mkOption { + inherit (settingsFormat) type; + default = { }; + example = { + global = { + uid = "nobody"; + gid = "nobody"; + "use chroot" = true; + "max connections" = 4; + }; + ftp = { + path = "/var/ftp/./pub"; + comment = "whole ftp area"; + }; + cvs = { + path = "/data/cvs"; + comment = "CVS repository (requires authentication)"; + "auth users" = [ "tridge" "susan" ]; + "secrets file" = "/etc/rsyncd.secrets"; + }; + }; description = '' - IP address the daemon will listen on; rsyncd will listen on - all addresses if this is not specified. - ''; - }; - - extraConfig = mkOption { - type = types.lines; - default = ""; - description = '' - Lines of configuration to add to rsyncd globally. - See man rsyncd.conf for options. - ''; - }; - - modules = mkOption { - default = {}; - description = '' - A set describing exported directories. - See man rsyncd.conf for options. - ''; - type = types.attrsOf (types.attrsOf types.str); - example = literalExample '' - { srv = - { path = "/srv"; - "read only" = "yes"; - comment = "Public rsync share."; - }; - } - ''; - }; - - 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. + Configuration for rsyncd. See + rsyncd.conf + 5. ''; }; }; }; - ###### implementation + imports = (map (option: + mkRemovedOptionModule [ "services" "rsyncd" option ] + "This option was removed in favor of `services.rsyncd.settings`.") [ + "address" + "extraConfig" + "motd" + "user" + "group" + ]); config = mkIf cfg.enable { - environment.etc."rsyncd.conf".text = cfgFile; + services.rsyncd.settings.global.port = toString cfg.port; systemd.services.rsyncd = { description = "Rsync daemon"; wantedBy = [ "multi-user.target" ]; - restartTriggers = [ config.environment.etc."rsyncd.conf".source ]; - serviceConfig = { - ExecStart = "${pkgs.rsync}/bin/rsync --daemon --no-detach"; - User = cfg.user; - Group = cfg.group; - }; + serviceConfig.ExecStart = + "${pkgs.rsync}/bin/rsync --daemon --no-detach --config=${configFile}"; }; }; + + meta.maintainers = with lib.maintainers; [ ehmry ]; + + # TODO: socket activated rsyncd + } diff --git a/nixos/tests/rsyncd.nix b/nixos/tests/rsyncd.nix new file mode 100644 index 00000000000..3639320f645 --- /dev/null +++ b/nixos/tests/rsyncd.nix @@ -0,0 +1,25 @@ +import ./make-test-python.nix ({ pkgs, ... }: { + name = "rsyncd"; + meta.maintainers = with pkgs.lib.maintainers; [ ehmry ]; + + nodes.machine.services.rsyncd = { + enable = true; + settings = { + global = { + "reverse lookup" = false; + "forward lookup" = false; + }; + tmp = { + path = "/nix/store"; + comment = "test module"; + }; + + }; + }; + + testScript = '' + start_all() + machine.wait_for_unit("rsyncd") + machine.succeed("rsync localhost::") + ''; +}) diff --git a/pkgs/applications/networking/sync/rsync/default.nix b/pkgs/applications/networking/sync/rsync/default.nix index 4045c1f0fc5..41a2d1e0db3 100644 --- a/pkgs/applications/networking/sync/rsync/default.nix +++ b/pkgs/applications/networking/sync/rsync/default.nix @@ -1,7 +1,6 @@ { stdenv, fetchurl, perl, libiconv, zlib, popt -, enableACLs ? !(stdenv.isDarwin || stdenv.isSunOS || stdenv.isFreeBSD), acl ? null -, enableCopyDevicesPatch ? false -}: +, enableACLs ? !(stdenv.isDarwin || stdenv.isSunOS || stdenv.isFreeBSD) +, acl ? null, enableCopyDevicesPatch ? false, nixosTests }: assert enableACLs -> acl != null; @@ -23,6 +22,8 @@ stdenv.mkDerivation rec { configureFlags = ["--with-nobody-group=nogroup"]; + passthru.tests = { inherit (nixosTests) rsyncd; }; + meta = base.meta // { description = "A fast incremental file transfer utility"; maintainers = with stdenv.lib.maintainers; [ peti ehmry kampfschlaefer ];