1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.gnunet;
8
9 homeDir = "/var/lib/gnunet";
10
11 configFile = with cfg; pkgs.writeText "gnunetd.conf"
12 ''
13 [PATHS]
14 SERVICEHOME = ${homeDir}
15
16 [ats]
17 WAN_QUOTA_IN = ${toString load.maxNetDownBandwidth} b
18 WAN_QUOTA_OUT = ${toString load.maxNetUpBandwidth} b
19
20 [datastore]
21 QUOTA = ${toString fileSharing.quota} MB
22
23 [transport-udp]
24 PORT = ${toString udp.port}
25 ADVERTISED_PORT = ${toString udp.port}
26
27 [transport-tcp]
28 PORT = ${toString tcp.port}
29 ADVERTISED_PORT = ${toString tcp.port}
30
31 ${extraOptions}
32 '';
33
34in
35
36{
37
38 ###### interface
39
40 options = {
41
42 services.gnunet = {
43
44 enable = mkOption {
45 default = false;
46 description = ''
47 Whether to run the GNUnet daemon. GNUnet is GNU's anonymous
48 peer-to-peer communication and file sharing framework.
49 '';
50 };
51
52 fileSharing = {
53 quota = mkOption {
54 default = 1024;
55 description = ''
56 Maximum file system usage (in MiB) for file sharing.
57 '';
58 };
59 };
60
61 udp = {
62 port = mkOption {
63 default = 2086; # assigned by IANA
64 description = ''
65 The UDP port for use by GNUnet.
66 '';
67 };
68 };
69
70 tcp = {
71 port = mkOption {
72 default = 2086; # assigned by IANA
73 description = ''
74 The TCP port for use by GNUnet.
75 '';
76 };
77 };
78
79 load = {
80 maxNetDownBandwidth = mkOption {
81 default = 50000;
82 description = ''
83 Maximum bandwidth usage (in bits per second) for GNUnet
84 when downloading data.
85 '';
86 };
87
88 maxNetUpBandwidth = mkOption {
89 default = 50000;
90 description = ''
91 Maximum bandwidth usage (in bits per second) for GNUnet
92 when downloading data.
93 '';
94 };
95
96 hardNetUpBandwidth = mkOption {
97 default = 0;
98 description = ''
99 Hard bandwidth limit (in bits per second) when uploading
100 data.
101 '';
102 };
103 };
104
105 extraOptions = mkOption {
106 default = "";
107 description = ''
108 Additional options that will be copied verbatim in `gnunet.conf'.
109 See `gnunet.conf(5)' for details.
110 '';
111 };
112 };
113
114 };
115
116
117 ###### implementation
118
119 config = mkIf config.services.gnunet.enable {
120
121 users.extraUsers.gnunet = {
122 group = "gnunet";
123 description = "GNUnet User";
124 home = homeDir;
125 createHome = true;
126 uid = config.ids.uids.gnunet;
127 };
128
129 users.extraGroups.gnunet.gid = config.ids.gids.gnunet;
130
131 # The user tools that talk to `gnunetd' should come from the same source,
132 # so install them globally.
133 environment.systemPackages = [ pkgs.gnunet ];
134
135 systemd.services.gnunet = {
136 description = "GNUnet";
137 after = [ "network.target" ];
138 wantedBy = [ "multi-user.target" ];
139 path = [ pkgs.gnunet pkgs.miniupnpc ];
140 serviceConfig.ExecStart = "${pkgs.gnunet}/lib/gnunet/libexec/gnunet-service-arm -c ${configFile}";
141 serviceConfig.User = "gnunet";
142 serviceConfig.UMask = "0007";
143 serviceConfig.WorkingDirectory = homeDir;
144 };
145
146 };
147
148}