1 { lib, pkgs, config, ... }:
7 cfg = config.services.tox-node;
8 homeDir = "/var/lib/tox-node";
11 src = "${pkg.src}/tox_node/dpkg/config.yml";
12 confJSON = pkgs.writeText "config.json" (
14 log-type = cfg.logType;
15 keys-file = cfg.keysFile;
16 udp-address = cfg.udpAddress;
17 tcp-addresses = cfg.tcpAddresses;
18 tcp-connections-limit = cfg.tcpConnectionLimit;
19 lan-discovery = cfg.lanDiscovery;
20 threads = cfg.threads;
24 in with pkgs; runCommand "config.yml" {} ''
25 ${remarshal}/bin/remarshal -if yaml -of json ${src} -o src.json
26 ${jq}/bin/jq -s '(.[0] | with_entries( select(.key == "bootstrap-nodes"))) * .[1]' src.json ${confJSON} > $out
30 options.services.tox-node = {
31 enable = mkEnableOption "Tox Node service";
34 type = types.enum [ "Stderr" "Stdout" "Syslog" "None" ];
36 description = "Logging implementation.";
40 default = "${homeDir}/keys";
41 description = "Path to the file where DHT keys are stored.";
43 udpAddress = mkOption {
45 default = "0.0.0.0:33445";
46 description = "UDP address to run DHT node.";
48 tcpAddresses = mkOption {
49 type = types.listOf types.str;
50 default = [ "0.0.0.0:33445" ];
51 description = "TCP addresses to run TCP relay.";
53 tcpConnectionLimit = mkOption {
56 description = "Maximum number of active TCP connections relay can hold";
58 lanDiscovery = mkOption {
61 description = "Enable local network discovery.";
66 description = "Number of threads for execution";
70 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}}";
71 description = "Message of the day";
75 config = lib.mkIf cfg.enable {
76 systemd.services.tox-node = {
77 description = "Tox Node";
79 after = [ "network.target" ];
80 wantedBy = [ "multi-user.target" ];
83 ExecStart = "${pkg}/bin/tox-node config ${configFile}";
84 StateDirectory = "tox-node";