at 23.11-pre 2.0 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 lib.mdDoc '' 27 Whether to enable the Tox DHT bootstrap daemon. 28 ''; 29 }; 30 31 port = mkOption { 32 type = types.port; 33 default = 33445; 34 description = lib.mdDoc "Listening port (UDP)."; 35 }; 36 37 keysFile = mkOption { 38 type = types.str; 39 default = "${WorkingDirectory}/keys"; 40 description = lib.mdDoc "Node key file."; 41 }; 42 43 extraConfig = mkOption { 44 type = types.lines; 45 default = ""; 46 description = 47 lib.mdDoc '' 48 Configuration for bootstrap daemon. 49 See <https://github.com/irungentoo/toxcore/blob/master/other/bootstrap_daemon/tox-bootstrapd.conf> 50 and <http://wiki.tox.im/Nodes>. 51 ''; 52 }; 53 }; 54 55 }; 56 57 config = mkIf config.services.toxBootstrapd.enable { 58 59 systemd.services.tox-bootstrapd = { 60 description = "Tox DHT bootstrap daemon"; 61 after = [ "network.target" ]; 62 wantedBy = [ "multi-user.target" ]; 63 serviceConfig = 64 { ExecStart = "${pkg}/bin/tox-bootstrapd --config=${cfgFile}"; 65 Type = "forking"; 66 inherit PIDFile WorkingDirectory; 67 AmbientCapabilities = ["CAP_NET_BIND_SERVICE"]; 68 DynamicUser = true; 69 StateDirectory = "tox-bootstrapd"; 70 }; 71 }; 72 73 }; 74}