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.extraUsers = singleton
60 { name = "tox-bootstrapd";
61 uid = config.ids.uids.tox-bootstrapd;
62 description = "Tox bootstrap daemon user";
63 inherit home;
64 createHome = true;
65 };
66
67 systemd.services.tox-bootstrapd = {
68 description = "Tox DHT bootstrap daemon";
69 after = [ "network.target" ];
70 wantedBy = [ "multi-user.target" ];
71 serviceConfig =
72 { ExecStart = "${pkg}/bin/tox-bootstrapd ${cfgFile}";
73 Type = "forking";
74 inherit PIDFile;
75 User = "tox-bootstrapd";
76 };
77 };
78
79 };
80}