nixos/rsyncd: convert module to an INI generator
This commit is contained in:
parent
b3f8642587
commit
e7d0500cb3
|
@ -3,120 +3,76 @@
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
cfg = config.services.rsyncd;
|
cfg = config.services.rsyncd;
|
||||||
|
settingsFormat = pkgs.formats.ini { };
|
||||||
motdFile = builtins.toFile "rsyncd-motd" cfg.motd;
|
configFile = settingsFormat.generate "rsyncd.conf" cfg.settings;
|
||||||
|
in {
|
||||||
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
|
|
||||||
|
|
||||||
{
|
|
||||||
options = {
|
options = {
|
||||||
services.rsyncd = {
|
services.rsyncd = {
|
||||||
|
|
||||||
enable = mkEnableOption "the rsync daemon";
|
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 {
|
port = mkOption {
|
||||||
default = 873;
|
default = 873;
|
||||||
type = types.int;
|
type = types.port;
|
||||||
description = "TCP port the daemon will listen on.";
|
description = "TCP port the daemon will listen on.";
|
||||||
};
|
};
|
||||||
|
|
||||||
address = mkOption {
|
settings = mkOption {
|
||||||
default = "";
|
inherit (settingsFormat) type;
|
||||||
example = "192.168.1.2";
|
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 = ''
|
description = ''
|
||||||
IP address the daemon will listen on; rsyncd will listen on
|
Configuration for rsyncd. See
|
||||||
all addresses if this is not specified.
|
<citerefentry><refentrytitle>rsyncd.conf</refentrytitle>
|
||||||
'';
|
<manvolnum>5</manvolnum></citerefentry>.
|
||||||
};
|
|
||||||
|
|
||||||
extraConfig = mkOption {
|
|
||||||
type = types.lines;
|
|
||||||
default = "";
|
|
||||||
description = ''
|
|
||||||
Lines of configuration to add to rsyncd globally.
|
|
||||||
See <command>man rsyncd.conf</command> for options.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
modules = mkOption {
|
|
||||||
default = {};
|
|
||||||
description = ''
|
|
||||||
A set describing exported directories.
|
|
||||||
See <command>man rsyncd.conf</command> 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.
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
###### 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 {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
environment.etc."rsyncd.conf".text = cfgFile;
|
services.rsyncd.settings.global.port = toString cfg.port;
|
||||||
|
|
||||||
systemd.services.rsyncd = {
|
systemd.services.rsyncd = {
|
||||||
description = "Rsync daemon";
|
description = "Rsync daemon";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
restartTriggers = [ config.environment.etc."rsyncd.conf".source ];
|
serviceConfig.ExecStart =
|
||||||
serviceConfig = {
|
"${pkgs.rsync}/bin/rsync --daemon --no-detach --config=${configFile}";
|
||||||
ExecStart = "${pkgs.rsync}/bin/rsync --daemon --no-detach";
|
|
||||||
User = cfg.user;
|
|
||||||
Group = cfg.group;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
meta.maintainers = with lib.maintainers; [ ehmry ];
|
||||||
|
|
||||||
|
# TODO: socket activated rsyncd
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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::")
|
||||||
|
'';
|
||||||
|
})
|
|
@ -1,7 +1,6 @@
|
||||||
{ stdenv, fetchurl, perl, libiconv, zlib, popt
|
{ stdenv, fetchurl, perl, libiconv, zlib, popt
|
||||||
, enableACLs ? !(stdenv.isDarwin || stdenv.isSunOS || stdenv.isFreeBSD), acl ? null
|
, enableACLs ? !(stdenv.isDarwin || stdenv.isSunOS || stdenv.isFreeBSD)
|
||||||
, enableCopyDevicesPatch ? false
|
, acl ? null, enableCopyDevicesPatch ? false, nixosTests }:
|
||||||
}:
|
|
||||||
|
|
||||||
assert enableACLs -> acl != null;
|
assert enableACLs -> acl != null;
|
||||||
|
|
||||||
|
@ -23,6 +22,8 @@ stdenv.mkDerivation rec {
|
||||||
|
|
||||||
configureFlags = ["--with-nobody-group=nogroup"];
|
configureFlags = ["--with-nobody-group=nogroup"];
|
||||||
|
|
||||||
|
passthru.tests = { inherit (nixosTests) rsyncd; };
|
||||||
|
|
||||||
meta = base.meta // {
|
meta = base.meta // {
|
||||||
description = "A fast incremental file transfer utility";
|
description = "A fast incremental file transfer utility";
|
||||||
maintainers = with stdenv.lib.maintainers; [ peti ehmry kampfschlaefer ];
|
maintainers = with stdenv.lib.maintainers; [ peti ehmry kampfschlaefer ];
|
||||||
|
|
Loading…
Reference in New Issue