1 { config, pkgs, lib, utils, ... }:
4 cfg = config.services.mycelium;
7 options.services.mycelium = {
8 enable = lib.mkEnableOption "mycelium network";
10 type = lib.types.listOf lib.types.str;
12 List of peers to connect to, in the formats:
13 - `quic://[2001:0db8::1]:9651`
14 - `quic://192.0.2.1:9651`
15 - `tcp://[2001:0db8::1]:9651`
16 - `tcp://192.0.2.1:9651`
18 If addHostedPublicNodes is set to true, the hosted public nodes will also be added.
22 keyFile = lib.mkOption {
23 type = lib.types.nullOr lib.types.path;
26 Optional path to a file containing the mycelium key material.
27 If unset, the default location (`/var/lib/mycelium/key.bin`) will be used.
28 If no key exist at this location, it will be generated on startup.
31 openFirewall = lib.mkOption {
32 type = lib.types.bool;
34 description = "Open the firewall for mycelium";
36 package = lib.mkOption {
37 type = lib.types.package;
38 default = pkgs.mycelium;
39 defaultText = lib.literalExpression ''"''${pkgs.mycelium}"'';
40 description = "The mycelium package to use";
42 addHostedPublicNodes = lib.mkOption {
43 type = lib.types.bool;
46 Adds the hosted peers from https://github.com/threefoldtech/mycelium#hosted-public-nodes.
49 extraArgs = lib.mkOption {
50 type = lib.types.listOf lib.types.str;
53 Extra command-line arguments to pass to mycelium.
55 See `mycelium --help` for all available options.
59 config = lib.mkIf cfg.enable {
60 networking.firewall.allowedTCPPorts = lib.optionals cfg.openFirewall [ 9651 ];
61 networking.firewall.allowedUDPPorts = lib.optionals cfg.openFirewall [ 9650 9651 ];
63 environment.systemPackages = [ cfg.package ];
65 systemd.services.mycelium = {
66 description = "Mycelium network";
67 after = [ "network.target" ];
68 wantedBy = [ "multi-user.target" ];
73 unitConfig.Documentation = "https://github.com/threefoldtech/mycelium";
78 StateDirectory = "mycelium";
81 LoadCredential = lib.mkIf (cfg.keyFile != null) "keyfile:${cfg.keyFile}";
82 SyslogIdentifier = "mycelium";
83 AmbientCapabilities = [ "CAP_NET_ADMIN" ];
84 MemoryDenyWriteExecute = true;
85 ProtectControlGroups = true;
86 ProtectKernelModules = true;
87 ProtectKernelTunables = true;
88 RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6 AF_NETLINK";
89 RestrictNamespaces = true;
90 RestrictRealtime = true;
91 SystemCallArchitectures = "native";
92 SystemCallFilter = [ "@system-service" "~@privileged @keyring" ];
93 ExecStart = lib.concatStringsSep " " ([
94 (lib.getExe cfg.package)
95 (if (cfg.keyFile != null) then
96 "--key-file \${CREDENTIALS_DIRECTORY}/keyfile" else
97 "--key-file %S/mycelium/key.bin"
101 "${utils.escapeSystemdExecArgs cfg.extraArgs}"
103 (lib.optional (cfg.addHostedPublicNodes || cfg.peers != [ ]) "--peers")
104 ++ cfg.peers ++ (lib.optionals cfg.addHostedPublicNodes [
105 "tcp://188.40.132.242:9651" # DE 01
106 "tcp://[2a01:4f8:221:1e0b::2]:9651"
107 "quic://188.40.132.242:9651"
108 "quic://[2a01:4f8:221:1e0b::2]:9651"
110 "tcp://136.243.47.186:9651" # DE 02
111 "tcp://[2a01:4f8:212:fa6::2]:9651"
112 "quic://136.243.47.186:9651"
113 "quic://[2a01:4f8:212:fa6::2]:9651"
115 "tcp://185.69.166.7:9651" # BE 03
116 "tcp://[2a02:1802:5e:0:8478:51ff:fee2:3331]:9651"
117 "quic://185.69.166.7:9651"
118 "quic://[2a02:1802:5e:0:8478:51ff:fee2:3331]:9651"
120 "tcp://185.69.166.8:9651" # BE 04
121 "tcp://[2a02:1802:5e:0:8c9e:7dff:fec9:f0d2]:9651"
122 "quic://185.69.166.8:9651"
123 "quic://[2a02:1802:5e:0:8c9e:7dff:fec9:f0d2]:9651"
125 "tcp://65.21.231.58:9651" # FI 05
126 "tcp://[2a01:4f9:6a:1dc5::2]:9651"
127 "quic://65.21.231.58:9651"
128 "quic://[2a01:4f9:6a:1dc5::2]:9651"
130 "tcp://65.109.18.113:9651" # FI 06
131 "tcp://[2a01:4f9:5a:1042::2]:9651"
132 "quic://65.109.18.113:9651"
133 "quic://[2a01:4f9:5a:1042::2]:9651"
142 maintainers = with lib.maintainers; [ flokli lassulus ];