anchor.diff:          transmission-remote, the WebUI (http://127.0.0.1:9091/ by default),
           or other clients like stig or tremc.
   
  -        Torrents are downloaded to ${homeDir}/${downloadsDir} by default and are
  +        Torrents are downloaded to <xref linkend="opt-services.transmission.home"/>/${downloadsDir} by default and are
           accessible to users in the "transmission" group'';
   
  -      settings = mkOption rec {
  -        # TODO: switch to types.config.json as prescribed by RFC0042 once it's implemented
  -        type = types.attrs;
  -        apply = recursiveUpdate default;
  -        default =
  -          {
  -            download-dir = "${cfg.home}/${downloadsDir}";
  -            incomplete-dir = "${cfg.home}/${incompleteDir}";
  -            incomplete-dir-enabled = true;
  -            watch-dir = "${cfg.home}/${watchDir}";
  -            watch-dir-enabled = false;
  -            message-level = 1;
  -            peer-port = 51413;
  -            peer-port-random-high = 65535;
  -            peer-port-random-low = 49152;
  -            peer-port-random-on-start = false;
  -            rpc-bind-address = "127.0.0.1";
  -            rpc-port = 9091;
  -            script-torrent-done-enabled = false;
  -            script-torrent-done-filename = "";
  -            umask = 2; # 0o002 in decimal as expected by Transmission
  -            utp-enabled = true;
  -          };
  -        example =
  -          {
  -            download-dir = "/srv/torrents/";
  -            incomplete-dir = "/srv/torrents/.incomplete/";
  -            incomplete-dir-enabled = true;
  -            rpc-whitelist = "127.0.0.1,192.168.*.*";
  -          };
  +      settings = mkOption {
           description = ''
  -          Attribute set whose fields overwrites fields in
  +          Settings whose options overwrite fields in
             <literal>.config/transmission-daemon/settings.json</literal>
  -          (each time the service starts). String values must be quoted, integer and
  -          boolean values must not.
  +          (each time the service starts).
   
             See <link xlink:href="https://github.com/transmission/transmission/wiki/Editing-Configuration-Files">Transmission's Wiki</link>
  -          for documentation.
  +          for documentation of settings not explicitely covered by this module.
           '';
  +        default = {};
  +        type = types.submodule {
  +          freeformType = settingsFormat.type;
  +          options.download-dir = mkOption {
  +            type = types.path;
  +            default = "${cfg.home}/${downloadsDir}";
  +            description = "Directory where to download torrents.";
  +          };
  +          options.incomplete-dir = mkOption {
  +            type = types.path;
  +            default = "${cfg.home}/${incompleteDir}";
  +            description = ''
  +              When enabled with
  +              services.transmission.home
  +              <xref linkend="opt-services.transmission.settings.incomplete-dir-enabled"/>,
  +              new torrents will download the files to this directory.
  +              When complete, the files will be moved to download-dir
  +              <xref linkend="opt-services.transmission.settings.download-dir"/>.
  +            '';
  +          };
  +          options.incomplete-dir-enabled = mkOption {
  +            type = types.bool;
  +            default = true;
  +            description = "";
  +          };
  +          options.message-level = mkOption {
  +            type = types.ints.between 0 2;
  +            default = 2;
  +            description = "Set verbosity of transmission messages.";
  +          };
  +          options.peer-port = mkOption {
  +            type = types.port;
  +            default = 51413;
  +            description = "The peer port to listen for incoming connections.";
  +          };
  +          options.peer-port-random-high = mkOption {
  +            type = types.port;
  +            default = 65535;
  +            description = ''
  +              The maximum peer port to listen to for incoming connections
  +              when <xref linkend="opt-services.transmission.settings.peer-port-random-on-start"/> is enabled.
  +            '';
  +          };
  +          options.peer-port-random-low = mkOption {
  +            type = types.port;
  +            default = 65535;
  +            description = ''
  +              The minimal peer port to listen to for incoming connections
  +              when <xref linkend="opt-services.transmission.settings.peer-port-random-on-start"/> is enabled.
  +            '';
  +          };
  +          options.peer-port-random-on-start = mkOption {
  +            type = types.bool;
  +            default = false;
  +            description = "Randomize the peer port.";
  +          };
  +          options.rpc-bind-address = mkOption {
  +            type = types.str;
  +            default = "127.0.0.1";
  +            example = "0.0.0.0";
  +            description = ''
  +              Where to listen for RPC connections.
  +              Use \"0.0.0.0\" to listen on all interfaces.
  +            '';
  +          };
  +          options.rpc-port = mkOption {
  +            type = types.port;
  +            default = 9091;
  +            description = "The RPC port to listen to.";
  +          };
  +          options.script-torrent-done-enabled = mkOption {
  +            type = types.bool;
  +            default = false;
  +            description = ''
  +              Whether to run
  +              <xref linkend="opt-services.transmission.settings.script-torrent-done-filename"/>
  +              at torrent completion.
  +            '';
  +          };
  +          options.script-torrent-done-filename = mkOption {
  +            type = types.nullOr types.path;
  +            default = null;
  +            description = "Executable to be run at torrent completion.";
  +          };
  +          options.umask = mkOption {
  +            type = types.int;
  +            default = 2;
  +            description = ''
  +              Sets transmission's file mode creation mask.
  +              See the umask(2) manpage for more information.
  +              Users who want their saved torrents to be world-writable
  +              may want to set this value to 0.
  +              Bear in mind that the json markup language only accepts numbers in base 10,
  +              so the standard umask(2) octal notation "022" is written in settings.json as 18.
  +            '';
  +          };
  +          options.utp-enabled = mkOption {
  +            type = types.bool;
  +            default = true;
  +            description = ''
  +              Whether to enable <link xlink:href="http://en.wikipedia.org/wiki/Micro_Transport_Protocol">Micro Transport Protocol (µTP)</link>.
  +            '';
  +          };
  +          options.watch-dir = mkOption {
  +            type = types.path;
  +            default = "${cfg.home}/${watchDir}";
  +            description = "Watch a directory for torrent files and add them to transmission.";
  +          };
  +          options.watch-dir-enabled = mkOption {
  +            type = types.bool;
  +            default = false;
  +            description = ''Whether to enable the
  +              <xref linkend="opt-services.transmission.settings.watch-dir"/>.
  +            '';
  +          };
  +          options.trash-original-torrent-files = mkOption {
  +            type = types.bool;
  +            default = false;
  +            description = ''Whether to delete torrents added from the
  +              <xref linkend="opt-services.transmission.settings.watch-dir"/>.
  +            '';
  +          };
  +        };
         };
   
         downloadDirPermissions = mkOption {
  
positive.code:       };
      });
  
      networking.firewall = mkIf cfg.openFirewall (
        if cfg.settings.peer-port-random-on-start
        then
          { allowedTCPPortRanges =
              [ { from = cfg.settings.peer-port-random-low;
                  to   = cfg.settings.peer-port-random-high;
                }
              ];
            allowedUDPPortRanges =
              [ { from = cfg.settings.peer-port-random-low;
                  to   = cfg.settings.peer-port-random-high;
                }
              ];
          }
        else
          { allowedTCPPorts = [ cfg.settings.peer-port ];
            allowedUDPPorts = [ cfg.settings.peer-port ];
          }
      );
  
      boot.kernel.sysctl = mkMerge [
        # Transmission uses a single UDP socket in order to implement multiple uTP sockets,
  
negative.code:       '' + optionalString cfg.settings.watch-dir-enabled ''
        install -d -m '${cfg.downloadDirPermissions}' -o '${cfg.user}' -g '${cfg.group}' '${cfg.settings.watch-dir}'
        '';
  
      systemd.services.transmission = {
        description = "Transmission BitTorrent Service";
  