nixpkgs/nixos/modules/services/network-filesystems/rsyncd.nix
Silvan Mosberger 1d0fc9729d
nixos/treewide: Fix incorrectly rendered examples
Many options define their example to be a Nix value without using
literalExample. This sometimes gets rendered incorrectly in the manual,
causing confusion like in https://github.com/NixOS/nixpkgs/issues/25516

This fixes it by using literalExample for such options. The list of
option to fix was determined with this expression:

  let
    nixos = import ./nixos { configuration = {}; };
    lib = import ./lib;
    valid = d: {
      # escapeNixIdentifier from https://github.com/NixOS/nixpkgs/pull/82461
      set = lib.all (n: lib.strings.escapeNixIdentifier n == n) (lib.attrNames d) && lib.all (v: valid v) (lib.attrValues d);
      list = lib.all (v: valid v) d;
    }.${builtins.typeOf d} or true;

    optionList = lib.optionAttrSetToDocList nixos.options;

  in map (opt: {
    file = lib.elemAt opt.declarations 0;
    loc = lib.options.showOption opt.loc;
  }) (lib.filter (opt: if opt ? example then ! valid opt.example else false) optionList)

which when evaluated will output all options that use a Nix identifier
that would need escaping as an attribute name.
2020-04-02 07:49:25 +02:00

126 lines
3.0 KiB
Nix

{ config, pkgs, lib, ... }:
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
{
options = {
services.rsyncd = {
enable = mkOption {
default = false;
description = "Whether to enable 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;
description = "TCP port the daemon will listen on.";
};
address = mkOption {
default = "";
example = "192.168.1.2";
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 <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
config = mkIf cfg.enable {
environment.etc."rsyncd.conf".text = cfgFile;
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;
};
};
};
}