nixpkgs/nixos/modules/services/networking/tox-node.nix
Silvan Mosberger 374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00

104 lines
2.7 KiB
Nix

{
lib,
pkgs,
config,
...
}:
with lib;
let
pkg = pkgs.tox-node;
cfg = config.services.tox-node;
homeDir = "/var/lib/tox-node";
configFile =
let
src = "${pkg.src}/tox_node/dpkg/config.yml";
confJSON = pkgs.writeText "config.json" (
builtins.toJSON {
log-type = cfg.logType;
keys-file = cfg.keysFile;
udp-address = cfg.udpAddress;
tcp-addresses = cfg.tcpAddresses;
tcp-connections-limit = cfg.tcpConnectionLimit;
lan-discovery = cfg.lanDiscovery;
threads = cfg.threads;
motd = cfg.motd;
}
);
in
with pkgs;
runCommand "config.yml" { } ''
${remarshal}/bin/remarshal -if yaml -of json ${src} -o src.json
${jq}/bin/jq -s '(.[0] | with_entries( select(.key == "bootstrap-nodes"))) * .[1]' src.json ${confJSON} > $out
'';
in
{
options.services.tox-node = {
enable = mkEnableOption "Tox Node service";
logType = mkOption {
type = types.enum [
"Stderr"
"Stdout"
"Syslog"
"None"
];
default = "Stderr";
description = "Logging implementation.";
};
keysFile = mkOption {
type = types.str;
default = "${homeDir}/keys";
description = "Path to the file where DHT keys are stored.";
};
udpAddress = mkOption {
type = types.str;
default = "0.0.0.0:33445";
description = "UDP address to run DHT node.";
};
tcpAddresses = mkOption {
type = types.listOf types.str;
default = [ "0.0.0.0:33445" ];
description = "TCP addresses to run TCP relay.";
};
tcpConnectionLimit = mkOption {
type = types.int;
default = 8192;
description = "Maximum number of active TCP connections relay can hold";
};
lanDiscovery = mkOption {
type = types.bool;
default = true;
description = "Enable local network discovery.";
};
threads = mkOption {
type = types.int;
default = 1;
description = "Number of threads for execution";
};
motd = mkOption {
type = types.str;
default = "Hi from tox-rs! I'm up {{uptime}}. TCP: incoming {{tcp_packets_in}}, outgoing {{tcp_packets_out}}, UDP: incoming {{udp_packets_in}}, outgoing {{udp_packets_out}}";
description = "Message of the day";
};
};
config = lib.mkIf cfg.enable {
systemd.services.tox-node = {
description = "Tox Node";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${pkg}/bin/tox-node config ${configFile}";
StateDirectory = "tox-node";
DynamicUser = true;
Restart = "always";
};
};
};
}