at 23.11-pre 2.7 kB view raw
1{ lib, pkgs, config, ... }: 2 3with lib; 4 5let 6 pkg = pkgs.tox-node; 7 cfg = config.services.tox-node; 8 homeDir = "/var/lib/tox-node"; 9 10 configFile = let 11 src = "${pkg.src}/tox_node/dpkg/config.yml"; 12 confJSON = pkgs.writeText "config.json" ( 13 builtins.toJSON { 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; 21 motd = cfg.motd; 22 } 23 ); 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 27 ''; 28 29in { 30 options.services.tox-node = { 31 enable = mkEnableOption (lib.mdDoc "Tox Node service"); 32 33 logType = mkOption { 34 type = types.enum [ "Stderr" "Stdout" "Syslog" "None" ]; 35 default = "Stderr"; 36 description = lib.mdDoc "Logging implementation."; 37 }; 38 keysFile = mkOption { 39 type = types.str; 40 default = "${homeDir}/keys"; 41 description = lib.mdDoc "Path to the file where DHT keys are stored."; 42 }; 43 udpAddress = mkOption { 44 type = types.str; 45 default = "0.0.0.0:33445"; 46 description = lib.mdDoc "UDP address to run DHT node."; 47 }; 48 tcpAddresses = mkOption { 49 type = types.listOf types.str; 50 default = [ "0.0.0.0:33445" ]; 51 description = lib.mdDoc "TCP addresses to run TCP relay."; 52 }; 53 tcpConnectionLimit = mkOption { 54 type = types.int; 55 default = 8192; 56 description = lib.mdDoc "Maximum number of active TCP connections relay can hold"; 57 }; 58 lanDiscovery = mkOption { 59 type = types.bool; 60 default = true; 61 description = lib.mdDoc "Enable local network discovery."; 62 }; 63 threads = mkOption { 64 type = types.int; 65 default = 1; 66 description = lib.mdDoc "Number of threads for execution"; 67 }; 68 motd = mkOption { 69 type = types.str; 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 = lib.mdDoc "Message of the day"; 72 }; 73 }; 74 75 config = lib.mkIf cfg.enable { 76 systemd.services.tox-node = { 77 description = "Tox Node"; 78 79 after = [ "network.target" ]; 80 wantedBy = [ "multi-user.target" ]; 81 82 serviceConfig = { 83 ExecStart = "${pkg}/bin/tox-node config ${configFile}"; 84 StateDirectory = "tox-node"; 85 DynamicUser = true; 86 Restart = "always"; 87 }; 88 }; 89 }; 90}