1 { config, lib, pkgs, ... }:
5 cfg = config.services.bee;
6 format = pkgs.formats.yaml {};
7 configFile = format.generate "bee.yaml" cfg.settings;
11 maintainers = with maintainers; [ attila-lendvai ];
18 enable = mkEnableOption (lib.mdDoc "Ethereum Swarm Bee");
23 defaultText = literalExpression "pkgs.bee";
24 example = literalExpression "pkgs.bee-unstable";
25 description = lib.mdDoc "The package providing the bee binary for the service.";
30 description = lib.mdDoc ''
31 Ethereum Swarm Bee configuration. Refer to
32 <https://gateway.ethswarm.org/bzz/docs.swarm.eth/docs/installation/configuration/>
33 for details on supported values.
37 daemonNiceLevel = mkOption {
40 description = lib.mdDoc ''
41 Daemon process priority for bee.
42 0 is the default Unix process priority, 19 is the lowest.
49 description = lib.mdDoc ''
50 User the bee binary should execute under.
57 description = lib.mdDoc ''
58 Group the bee binary should execute under.
66 config = mkIf cfg.enable {
68 { assertion = (hasAttr "password" cfg.settings) != true;
70 `services.bee.settings.password` is insecure. Use `services.bee.settings.password-file` or `systemd.services.bee.serviceConfig.EnvironmentFile` instead.
73 { assertion = (hasAttr "swap-endpoint" cfg.settings) || (cfg.settings.swap-enable or true == false);
75 In a swap-enabled network a working Ethereum blockchain node is required. You must specify one using `services.bee.settings.swap-endpoint`, or disable `services.bee.settings.swap-enable` = false.
80 warnings = optional (! config.services.bee-clef.enable) "The bee service requires an external signer. Consider setting `config.services.bee-clef.enable` = true";
82 services.bee.settings = {
83 data-dir = lib.mkDefault "/var/lib/bee";
84 password-file = lib.mkDefault "/var/lib/bee/password";
85 clef-signer-enable = lib.mkDefault true;
86 clef-signer-endpoint = lib.mkDefault "/var/lib/bee-clef/clef.ipc";
87 swap-endpoint = lib.mkDefault "https://rpc.slock.it/goerli";
90 systemd.packages = [ cfg.package ]; # include the upstream bee.service file
92 systemd.tmpfiles.rules = [
93 "d '${cfg.settings.data-dir}' 0750 ${cfg.user} ${cfg.group}"
96 systemd.services.bee = {
97 requires = optional config.services.bee-clef.enable
100 wantedBy = [ "multi-user.target" ];
103 Nice = cfg.daemonNiceLevel;
107 "" # this hides/overrides what's in the original entry
108 "${cfg.package}/bin/bee --config=${configFile} start"
112 preStart = with cfg.settings; ''
113 if ! test -f ${password-file}; then
114 < /dev/urandom tr -dc _A-Z-a-z-0-9 2> /dev/null | head -c32 > ${password-file}
115 chmod 0600 ${password-file}
116 echo "Initialized ${password-file} from /dev/urandom"
118 if [ ! -f ${data-dir}/keys/libp2p.key ]; then
119 ${cfg.package}/bin/bee init --config=${configFile} >/dev/null
121 Logs: journalctl -f -u bee.service
123 Bee has SWAP enabled by default and it needs ethereum endpoint to operate.
124 It is recommended to use external signer with bee.
125 Check documentation for more info:
126 - SWAP https://docs.ethswarm.org/docs/installation/manual#swap-bandwidth-incentives
127 - External signer https://docs.ethswarm.org/docs/installation/bee-clef
129 After you finish configuration run 'sudo bee-get-addr'."
134 users.users = optionalAttrs (cfg.user == "bee") {
137 home = cfg.settings.data-dir;
139 description = "Daemon user for Ethereum Swarm Bee";
140 extraGroups = optional config.services.bee-clef.enable
141 config.services.bee-clef.group;
145 users.groups = optionalAttrs (cfg.group == "bee") {