tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
ipfs: nixpkgs-fmt
happysalada
4 years ago
54dbdcbc
6f28a718
+56
-43
1 changed file
expand all
collapse all
unified
split
nixos
modules
services
network-filesystems
ipfs.nix
+56
-43
nixos/modules/services/network-filesystems/ipfs.nix
···
5
5
opt = options.services.ipfs;
6
6
7
7
ipfsFlags = toString ([
8
8
-
(optionalString cfg.autoMount "--mount")
9
9
-
(optionalString cfg.enableGC "--enable-gc")
10
10
-
(optionalString (cfg.serviceFdlimit != null) "--manage-fdlimit=false")
11
11
-
(optionalString (cfg.defaultMode == "offline") "--offline")
8
8
+
(optionalString cfg.autoMount "--mount")
9
9
+
(optionalString cfg.enableGC "--enable-gc")
10
10
+
(optionalString (cfg.serviceFdlimit != null) "--manage-fdlimit=false")
11
11
+
(optionalString (cfg.defaultMode == "offline") "--offline")
12
12
(optionalString (cfg.defaultMode == "norouting") "--routing=none")
13
13
] ++ cfg.extraFlags);
14
14
15
15
splitMulitaddr = addrRaw: lib.tail (lib.splitString "/" addrRaw);
16
16
17
17
-
multiaddrToListenStream = addrRaw: let
17
17
+
multiaddrToListenStream = addrRaw:
18
18
+
let
18
19
addr = splitMulitaddr addrRaw;
19
20
s = builtins.elemAt addr;
20
20
-
in if s 0 == "ip4" && s 2 == "tcp"
21
21
-
then "${s 1}:${s 3}"
21
21
+
in
22
22
+
if s 0 == "ip4" && s 2 == "tcp"
23
23
+
then "${s 1}:${s 3}"
22
24
else if s 0 == "ip6" && s 2 == "tcp"
23
23
-
then "[${s 1}]:${s 3}"
25
25
+
then "[${s 1}]:${s 3}"
24
26
else if s 0 == "unix"
25
25
-
then "/${lib.concatStringsSep "/" (lib.tail addr)}"
27
27
+
then "/${lib.concatStringsSep "/" (lib.tail addr)}"
26
28
else null; # not valid for listen stream, skip
27
29
28
28
-
multiaddrToListenDatagram = addrRaw: let
30
30
+
multiaddrToListenDatagram = addrRaw:
31
31
+
let
29
32
addr = splitMulitaddr addrRaw;
30
33
s = builtins.elemAt addr;
31
31
-
in if s 0 == "ip4" && s 2 == "udp"
32
32
-
then "${s 1}:${s 3}"
34
34
+
in
35
35
+
if s 0 == "ip4" && s 2 == "udp"
36
36
+
then "${s 1}:${s 3}"
33
37
else if s 0 == "ip6" && s 2 == "udp"
34
34
-
then "[${s 1}]:${s 3}"
38
38
+
then "[${s 1}]:${s 3}"
35
39
else null; # not valid for listen datagram, skip
36
40
37
37
-
in {
41
41
+
in
42
42
+
{
38
43
39
44
###### interface
40
45
···
65
70
66
71
dataDir = mkOption {
67
72
type = types.str;
68
68
-
default = if versionAtLeast config.system.stateVersion "17.09"
69
69
-
then "/var/lib/ipfs"
70
70
-
else "/var/lib/ipfs/.ipfs";
73
73
+
default =
74
74
+
if versionAtLeast config.system.stateVersion "17.09"
75
75
+
then "/var/lib/ipfs"
76
76
+
else "/var/lib/ipfs/.ipfs";
71
77
description = "The data dir for IPFS";
72
78
};
73
79
···
137
143
These are applied last, so may override configuration set by other options in this module.
138
144
Keep in mind that this configuration is stateful; i.e., unsetting anything in here does not reset the value to the default!
139
145
'';
140
140
-
default = {};
146
146
+
default = { };
141
147
example = {
142
148
Datastore.StorageMax = "100GB";
143
149
Discovery.MDNS.Enabled = false;
···
153
159
extraFlags = mkOption {
154
160
type = types.listOf types.str;
155
161
description = "Extra flags passed to the IPFS daemon";
156
156
-
default = [];
162
162
+
default = [ ];
157
163
};
158
164
159
165
localDiscovery = mkOption {
···
168
174
type = types.nullOr types.int;
169
175
default = null;
170
176
description = "The fdlimit for the IPFS systemd unit or <literal>null</literal> to have the daemon attempt to manage it";
171
171
-
example = 64*1024;
177
177
+
example = 64 * 1024;
172
178
};
173
179
174
180
startWhenNeeded = mkOption {
···
235
241
ipfs --offline config Mounts.IPFS ${cfg.ipfsMountDir}
236
242
ipfs --offline config Mounts.IPNS ${cfg.ipnsMountDir}
237
243
'' + concatStringsSep "\n" (collect
238
238
-
isString
239
239
-
(mapAttrsRecursive
240
240
-
(path: value:
241
241
-
# Using heredoc below so that the value is never improperly quoted
242
242
-
''
243
243
-
read value <<EOF
244
244
-
${builtins.toJSON value}
245
245
-
EOF
246
246
-
ipfs --offline config --json "${concatStringsSep "." path}" "$value"
247
247
-
'')
248
248
-
({ Addresses.API = cfg.apiAddress;
249
249
-
Addresses.Gateway = cfg.gatewayAddress;
250
250
-
Addresses.Swarm = cfg.swarmAddress;
251
251
-
} //
252
252
-
cfg.extraConfig))
253
253
-
);
244
244
+
isString
245
245
+
(mapAttrsRecursive
246
246
+
(path: value:
247
247
+
# Using heredoc below so that the value is never improperly quoted
248
248
+
''
249
249
+
read value <<EOF
250
250
+
${builtins.toJSON value}
251
251
+
EOF
252
252
+
ipfs --offline config --json "${concatStringsSep "." path}" "$value"
253
253
+
'')
254
254
+
({
255
255
+
Addresses.API = cfg.apiAddress;
256
256
+
Addresses.Gateway = cfg.gatewayAddress;
257
257
+
Addresses.Swarm = cfg.swarmAddress;
258
258
+
} //
259
259
+
cfg.extraConfig))
260
260
+
);
254
261
serviceConfig = {
255
255
-
ExecStart = ["" "${cfg.package}/bin/ipfs daemon ${ipfsFlags}"];
262
262
+
ExecStart = [ "" "${cfg.package}/bin/ipfs daemon ${ipfsFlags}" ];
256
263
User = cfg.user;
257
264
Group = cfg.group;
258
265
} // optionalAttrs (cfg.serviceFdlimit != null) { LimitNOFILE = cfg.serviceFdlimit; };
···
263
270
systemd.sockets.ipfs-gateway = {
264
271
wantedBy = [ "sockets.target" ];
265
272
socketConfig = {
266
266
-
ListenStream = let
273
273
+
ListenStream =
274
274
+
let
267
275
fromCfg = multiaddrToListenStream cfg.gatewayAddress;
268
268
-
in [ "" ] ++ lib.optional (fromCfg != null) fromCfg;
269
269
-
ListenDatagram = let
276
276
+
in
277
277
+
[ "" ] ++ lib.optional (fromCfg != null) fromCfg;
278
278
+
ListenDatagram =
279
279
+
let
270
280
fromCfg = multiaddrToListenDatagram cfg.gatewayAddress;
271
271
-
in [ "" ] ++ lib.optional (fromCfg != null) fromCfg;
281
281
+
in
282
282
+
[ "" ] ++ lib.optional (fromCfg != null) fromCfg;
272
283
};
273
284
};
274
285
···
276
287
wantedBy = [ "sockets.target" ];
277
288
# We also include "%t/ipfs.sock" because there is no way to put the "%t"
278
289
# in the multiaddr.
279
279
-
socketConfig.ListenStream = let
290
290
+
socketConfig.ListenStream =
291
291
+
let
280
292
fromCfg = multiaddrToListenStream cfg.apiAddress;
281
281
-
in [ "" "%t/ipfs.sock" ] ++ lib.optional (fromCfg != null) fromCfg;
293
293
+
in
294
294
+
[ "" "%t/ipfs.sock" ] ++ lib.optional (fromCfg != null) fromCfg;
282
295
};
283
296
284
297
};