···
1
+
{ config, pkgs, lib, ... }:
4
+
cfg = config.services.mycelium;
7
+
options.services.mycelium = {
8
+
enable = lib.mkEnableOption "mycelium network";
9
+
peers = lib.mkOption {
10
+
type = lib.types.listOf lib.types.str;
12
+
List of peers to connect to in the format quic://1.2.3.4:9651.
13
+
If addHostedPublicNodes is set to true, the hosted public nodes will be added to this list.
17
+
keyFile = lib.mkOption {
18
+
type = lib.types.nullOr lib.types.path;
21
+
optional path to a keyFile, if unset the default location (/var/lib/mycelium/key) will be used
22
+
If this key does not exist, it will be generated
25
+
openFirewall = lib.mkOption {
26
+
type = lib.types.bool;
28
+
description = "Open the firewall for mycelium";
30
+
package = lib.mkOption {
31
+
type = lib.types.package;
32
+
default = pkgs.mycelium;
33
+
defaultText = lib.literalExpression ''"''${pkgs.mycelium}"'';
34
+
description = "The mycelium package to use";
36
+
addHostedPublicNodes = lib.mkOption {
37
+
type = lib.types.bool;
40
+
add the hosted peers from https://github.com/threefoldtech/mycelium#hosted-public-nodes
44
+
config = lib.mkIf cfg.enable {
45
+
networking.firewall.allowedTCPPorts = lib.optionals cfg.openFirewall [ 9651 ];
46
+
networking.firewall.allowedUDPPorts = lib.optionals cfg.openFirewall [ 9650 9651 ];
48
+
systemd.services.mycelium = {
49
+
description = "Mycelium network";
50
+
after = [ "network.target" ];
51
+
wantedBy = [ "multi-user.target" ];
56
+
unitConfig.Documentation = "https://github.com/threefoldtech/mycelium";
61
+
StateDirectory = "mycelium";
63
+
ProtectSystem = true;
64
+
LoadCredential = lib.mkIf (cfg.keyFile != null) "keyfile:${cfg.keyFile}";
65
+
SyslogIdentifier = "mycelium";
66
+
AmbientCapabilities = [ "CAP_NET_ADMIN" ];
67
+
MemoryDenyWriteExecute = true;
68
+
ProtectControlGroups = true;
69
+
ProtectKernelModules = true;
70
+
ProtectKernelTunables = true;
71
+
RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6 AF_NETLINK";
72
+
RestrictNamespaces = true;
73
+
RestrictRealtime = true;
74
+
SystemCallArchitectures = "native";
75
+
SystemCallFilter = [ "@system-service" "~@privileged @keyring" ];
76
+
ExecStart = lib.concatStringsSep " " ([
77
+
(lib.getExe cfg.package)
78
+
(if (cfg.keyFile != null) then
79
+
"--key-file \${CREDENTIALS_DIRECTORY}/keyfile" else
80
+
"--key-file %S/mycelium/key.bin"
82
+
"--tun-name" "mycelium"
84
+
(lib.optional (cfg.addHostedPublicNodes || cfg.peers != []) "--peers")
85
+
++ cfg.peers ++ (lib.optionals cfg.addHostedPublicNodes [
86
+
"tcp://188.40.132.242:9651" # DE 01
87
+
"tcp://[2a01:4f8:221:1e0b::2]:9651"
88
+
"quic://188.40.132.242:9651"
89
+
"quic://[2a01:4f8:221:1e0b::2]:9651"
91
+
"tcp://136.243.47.186:9651" # DE 02
92
+
"tcp://[2a01:4f8:212:fa6::2]:9651"
93
+
"quic://136.243.47.186:9651"
94
+
"quic://[2a01:4f8:212:fa6::2]:9651"
96
+
"tcp://185.69.166.7:9651" # BE 03
97
+
"tcp://[2a02:1802:5e:0:8478:51ff:fee2:3331]:9651"
98
+
"quic://185.69.166.7:9651"
99
+
"quic://[2a02:1802:5e:0:8478:51ff:fee2:3331]:9651"
101
+
"tcp://185.69.166.8:9651" # BE 04
102
+
"tcp://[2a02:1802:5e:0:8c9e:7dff:fec9:f0d2]:9651"
103
+
"quic://185.69.166.8:9651"
104
+
"quic://[2a02:1802:5e:0:8c9e:7dff:fec9:f0d2]:9651"
106
+
"tcp://65.21.231.58:9651" # FI 05
107
+
"tcp://[2a01:4f9:6a:1dc5::2]:9651"
108
+
"quic://65.21.231.58:9651"
109
+
"quic://[2a01:4f9:6a:1dc5::2]:9651"
111
+
"tcp://65.109.18.113:9651" # FI 06
112
+
"tcp://[2a01:4f9:5a:1042::2]:9651"
113
+
"quic://65.109.18.113:9651"
114
+
"quic://[2a01:4f9:5a:1042::2]:9651"
116
+
Restart = "always";
118
+
TimeoutStopSec = 5;
123
+
maintainers = with lib.maintainers; [ flokli lassulus ];