at 24.11-pre 1.9 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 WorkingDirectory = "/var/lib/tox-bootstrapd"; 7 PIDFile = "${WorkingDirectory}/pid"; 8 9 pkg = pkgs.libtoxcore; 10 cfg = config.services.toxBootstrapd; 11 cfgFile = builtins.toFile "tox-bootstrapd.conf" 12 '' 13 port = ${toString cfg.port} 14 keys_file_path = "${WorkingDirectory}/keys" 15 pid_file_path = "${PIDFile}" 16 ${cfg.extraConfig} 17 ''; 18in 19{ 20 options = 21 { services.toxBootstrapd = 22 { enable = mkOption { 23 type = types.bool; 24 default = false; 25 description = '' 26 Whether to enable the Tox DHT bootstrap daemon. 27 ''; 28 }; 29 30 port = mkOption { 31 type = types.port; 32 default = 33445; 33 description = "Listening port (UDP)."; 34 }; 35 36 keysFile = mkOption { 37 type = types.str; 38 default = "${WorkingDirectory}/keys"; 39 description = "Node key file."; 40 }; 41 42 extraConfig = mkOption { 43 type = types.lines; 44 default = ""; 45 description = '' 46 Configuration for bootstrap daemon. 47 See <https://github.com/irungentoo/toxcore/blob/master/other/bootstrap_daemon/tox-bootstrapd.conf> 48 and <https://wiki.tox.chat/users/nodes>. 49 ''; 50 }; 51 }; 52 53 }; 54 55 config = mkIf config.services.toxBootstrapd.enable { 56 57 systemd.services.tox-bootstrapd = { 58 description = "Tox DHT bootstrap daemon"; 59 after = [ "network.target" ]; 60 wantedBy = [ "multi-user.target" ]; 61 serviceConfig = 62 { ExecStart = "${pkg}/bin/tox-bootstrapd --config=${cfgFile}"; 63 Type = "forking"; 64 inherit PIDFile WorkingDirectory; 65 AmbientCapabilities = ["CAP_NET_BIND_SERVICE"]; 66 DynamicUser = true; 67 StateDirectory = "tox-bootstrapd"; 68 }; 69 }; 70 71 }; 72}