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 package = mkOption {
106 type = types.package;
107 default = pkgs.gnunet;
108 defaultText = "pkgs.gnunet";
109 description = "Overridable attribute of the gnunet package to use.";
110 example = literalExample "pkgs.gnunet_git";
111 };
112
113 extraOptions = mkOption {
114 default = "";
115 description = ''
116 Additional options that will be copied verbatim in `gnunet.conf'.
117 See `gnunet.conf(5)' for details.
118 '';
119 };
120 };
121
122 };
123
124
125 ###### implementation
126
127 config = mkIf config.services.gnunet.enable {
128
129 users.users.gnunet = {
130 group = "gnunet";
131 description = "GNUnet User";
132 home = homeDir;
133 createHome = true;
134 uid = config.ids.uids.gnunet;
135 };
136
137 users.groups.gnunet.gid = config.ids.gids.gnunet;
138
139 # The user tools that talk to `gnunetd' should come from the same source,
140 # so install them globally.
141 environment.systemPackages = [ cfg.package ];
142
143 systemd.services.gnunet = {
144 description = "GNUnet";
145 after = [ "network.target" ];
146 wantedBy = [ "multi-user.target" ];
147 path = [ cfg.package pkgs.miniupnpc ];
148 environment.TMPDIR = "/tmp";
149 serviceConfig.PrivateTemp = true;
150 serviceConfig.ExecStart = "${cfg.package}/lib/gnunet/libexec/gnunet-service-arm -c ${configFile}";
151 serviceConfig.User = "gnunet";
152 serviceConfig.UMask = "0007";
153 serviceConfig.WorkingDirectory = homeDir;
154 };
155
156 };
157
158}