nixpkgs/nixos/modules/services/networking/gnunet.nix
pennae 2e751c0772 treewide: automatically md-convert option descriptions
the conversion procedure is simple:

 - find all things that look like options, ie calls to either `mkOption`
   or `lib.mkOption` that take an attrset. remember the attrset as the
   option
 - for all options, find a `description` attribute who's value is not a
   call to `mdDoc` or `lib.mdDoc`
 - textually convert the entire value of the attribute to MD with a few
   simple regexes (the set from mdize-module.sh)
 - if the change produced a change in the manual output, discard
 - if the change kept the manual unchanged, add some text to the
   description to make sure we've actually found an option. if the
   manual changes this time, keep the converted description

this procedure converts 80% of nixos options to markdown. around 2000
options remain to be inspected, but most of those fail the "does not
change the manual output check": currently the MD conversion process
does not faithfully convert docbook tags like <code> and <package>, so
any option using such tags will not be converted at all.
2022-07-30 15:16:34 +02:00

171 lines
4.1 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.gnunet;
stateDir = "/var/lib/gnunet";
configFile = with cfg;
''
[PATHS]
GNUNET_HOME = ${stateDir}
GNUNET_RUNTIME_DIR = /run/gnunet
GNUNET_USER_RUNTIME_DIR = /run/gnunet
GNUNET_DATA_HOME = ${stateDir}/data
[ats]
WAN_QUOTA_IN = ${toString load.maxNetDownBandwidth} b
WAN_QUOTA_OUT = ${toString load.maxNetUpBandwidth} b
[datastore]
QUOTA = ${toString fileSharing.quota} MB
[transport-udp]
PORT = ${toString udp.port}
ADVERTISED_PORT = ${toString udp.port}
[transport-tcp]
PORT = ${toString tcp.port}
ADVERTISED_PORT = ${toString tcp.port}
${extraOptions}
'';
in
{
###### interface
options = {
services.gnunet = {
enable = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to run the GNUnet daemon. GNUnet is GNU's anonymous
peer-to-peer communication and file sharing framework.
'';
};
fileSharing = {
quota = mkOption {
type = types.int;
default = 1024;
description = lib.mdDoc ''
Maximum file system usage (in MiB) for file sharing.
'';
};
};
udp = {
port = mkOption {
type = types.port;
default = 2086; # assigned by IANA
description = lib.mdDoc ''
The UDP port for use by GNUnet.
'';
};
};
tcp = {
port = mkOption {
type = types.port;
default = 2086; # assigned by IANA
description = lib.mdDoc ''
The TCP port for use by GNUnet.
'';
};
};
load = {
maxNetDownBandwidth = mkOption {
type = types.int;
default = 50000;
description = lib.mdDoc ''
Maximum bandwidth usage (in bits per second) for GNUnet
when downloading data.
'';
};
maxNetUpBandwidth = mkOption {
type = types.int;
default = 50000;
description = lib.mdDoc ''
Maximum bandwidth usage (in bits per second) for GNUnet
when downloading data.
'';
};
hardNetUpBandwidth = mkOption {
type = types.int;
default = 0;
description = lib.mdDoc ''
Hard bandwidth limit (in bits per second) when uploading
data.
'';
};
};
package = mkOption {
type = types.package;
default = pkgs.gnunet;
defaultText = literalExpression "pkgs.gnunet";
description = lib.mdDoc "Overridable attribute of the gnunet package to use.";
example = literalExpression "pkgs.gnunet_git";
};
extraOptions = mkOption {
type = types.lines;
default = "";
description = ''
Additional options that will be copied verbatim in `gnunet.conf'.
See `gnunet.conf(5)' for details.
'';
};
};
};
###### implementation
config = mkIf config.services.gnunet.enable {
users.users.gnunet = {
group = "gnunet";
description = "GNUnet User";
uid = config.ids.uids.gnunet;
};
users.groups.gnunet.gid = config.ids.gids.gnunet;
# The user tools that talk to `gnunetd' should come from the same source,
# so install them globally.
environment.systemPackages = [ cfg.package ];
environment.etc."gnunet.conf".text = configFile;
systemd.services.gnunet = {
description = "GNUnet";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
restartTriggers = [ configFile ];
path = [ cfg.package pkgs.miniupnpc ];
serviceConfig.ExecStart = "${cfg.package}/lib/gnunet/libexec/gnunet-service-arm -c /etc/gnunet.conf";
serviceConfig.User = "gnunet";
serviceConfig.UMask = "0007";
serviceConfig.WorkingDirectory = stateDir;
serviceConfig.RuntimeDirectory = "gnunet";
serviceConfig.StateDirectory = "gnunet";
};
};
}