3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/nixos/modules/services/networking/tox-node.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
2.6 KiB
Nix
Raw Normal View History

2019-04-12 18:37:07 +01:00
{ lib, pkgs, config, ... }:
with lib;
let
pkg = pkgs.tox-node;
cfg = config.services.tox-node;
homeDir = "/var/lib/tox-node";
configFile = let
2022-03-01 18:56:17 +00:00
src = "${pkg.src}/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
'';
2019-04-12 18:37:07 +01:00
in {
options.services.tox-node = {
enable = mkEnableOption "Tox Node service";
logType = mkOption {
type = types.enum [ "Stderr" "Stdout" "Syslog" "None" ];
default = "Stderr";
description = "Logging implementation.";
2019-04-12 18:37:07 +01:00
};
keysFile = mkOption {
type = types.str;
default = "${homeDir}/keys";
description = "Path to the file where DHT keys are stored.";
2019-04-12 18:37:07 +01:00
};
udpAddress = mkOption {
type = types.str;
default = "0.0.0.0:33445";
description = "UDP address to run DHT node.";
2019-04-12 18:37:07 +01:00
};
tcpAddresses = mkOption {
type = types.listOf types.str;
default = [ "0.0.0.0:33445" ];
description = "TCP addresses to run TCP relay.";
2019-04-12 18:37:07 +01:00
};
tcpConnectionLimit = mkOption {
type = types.int;
default = 8192;
description = "Maximum number of active TCP connections relay can hold";
2019-04-12 18:37:07 +01:00
};
lanDiscovery = mkOption {
type = types.bool;
default = true;
description = "Enable local network discovery.";
2019-04-12 18:37:07 +01:00
};
threads = mkOption {
type = types.int;
default = 1;
description = "Number of threads for execution";
2019-04-12 18:37:07 +01:00
};
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";
2019-04-12 18:37:07 +01:00
};
};
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";
};
};
};
}