at 21.11-pre 2.0 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 home = "/var/lib/tox-bootstrapd"; 7 PIDFile = "${home}/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 = "${home}/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 '' 27 Whether to enable the Tox DHT bootstrap daemon. 28 ''; 29 }; 30 31 port = mkOption { 32 type = types.int; 33 default = 33445; 34 description = "Listening port (UDP)."; 35 }; 36 37 keysFile = mkOption { 38 type = types.str; 39 default = "${home}/keys"; 40 description = "Node key file."; 41 }; 42 43 extraConfig = mkOption { 44 type = types.lines; 45 default = ""; 46 description = 47 '' 48 Configuration for bootstrap daemon. 49 See <link xlink:href="https://github.com/irungentoo/toxcore/blob/master/other/bootstrap_daemon/tox-bootstrapd.conf"/> 50 and <link xlink:href="http://wiki.tox.im/Nodes"/>. 51 ''; 52 }; 53 }; 54 55 }; 56 57 config = mkIf config.services.toxBootstrapd.enable { 58 59 users.users.tox-bootstrapd = 60 { uid = config.ids.uids.tox-bootstrapd; 61 description = "Tox bootstrap daemon user"; 62 inherit home; 63 createHome = true; 64 }; 65 66 systemd.services.tox-bootstrapd = { 67 description = "Tox DHT bootstrap daemon"; 68 after = [ "network.target" ]; 69 wantedBy = [ "multi-user.target" ]; 70 serviceConfig = 71 { ExecStart = "${pkg}/bin/tox-bootstrapd --config=${cfgFile}"; 72 Type = "forking"; 73 inherit PIDFile; 74 User = "tox-bootstrapd"; 75 }; 76 }; 77 78 }; 79}