1 { config, lib, pkgs, ... }:
3 cfg = config.services.bee;
4 format = pkgs.formats.yaml {};
5 configFile = format.generate "bee.yaml" cfg.settings;
16 enable = lib.mkEnableOption "Ethereum Swarm Bee";
18 package = lib.mkPackageOption pkgs "bee" {
19 example = "bee-unstable";
22 settings = lib.mkOption {
25 Ethereum Swarm Bee configuration. Refer to
26 <https://gateway.ethswarm.org/bzz/docs.swarm.eth/docs/installation/configuration/>
27 for details on supported values.
31 daemonNiceLevel = lib.mkOption {
35 Daemon process priority for bee.
36 0 is the default Unix process priority, 19 is the lowest.
44 User the bee binary should execute under.
48 group = lib.mkOption {
52 Group the bee binary should execute under.
60 config = lib.mkIf cfg.enable {
62 { assertion = (lib.hasAttr "password" cfg.settings) != true;
64 `services.bee.settings.password` is insecure. Use `services.bee.settings.password-file` or `systemd.services.bee.serviceConfig.EnvironmentFile` instead.
67 { assertion = (lib.hasAttr "swap-endpoint" cfg.settings) || (cfg.settings.swap-enable or true == false);
69 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.
74 services.bee.settings = {
75 data-dir = lib.mkDefault "/var/lib/bee";
76 password-file = lib.mkDefault "/var/lib/bee/password";
77 clef-signer-enable = lib.mkDefault true;
78 swap-endpoint = lib.mkDefault "https://rpc.slock.it/goerli";
81 systemd.packages = [ cfg.package ]; # include the upstream bee.service file
83 systemd.tmpfiles.rules = [
84 "d '${cfg.settings.data-dir}' 0750 ${cfg.user} ${cfg.group}"
87 systemd.services.bee = {
88 wantedBy = [ "multi-user.target" ];
91 Nice = cfg.daemonNiceLevel;
95 "" # this hides/overrides what's in the original entry
96 "${cfg.package}/bin/bee --config=${configFile} start"
100 preStart = with cfg.settings; ''
101 if ! test -f ${password-file}; then
102 < /dev/urandom tr -dc _A-Z-a-z-0-9 2> /dev/null | head -c32 | install -m 600 /dev/stdin ${password-file}
103 echo "Initialized ${password-file} from /dev/urandom"
105 if [ ! -f ${data-dir}/keys/libp2p.key ]; then
106 ${cfg.package}/bin/bee init --config=${configFile} >/dev/null
108 Logs: journalctl -f -u bee.service
110 Bee has SWAP enabled by default and it needs ethereum endpoint to operate.
111 It is recommended to use external signer with bee.
112 Check documentation for more info:
113 - SWAP https://docs.ethswarm.org/docs/installation/manual#swap-bandwidth-incentives
115 After you finish configuration run 'sudo bee-get-addr'."
120 users.users = lib.optionalAttrs (cfg.user == "bee") {
123 home = cfg.settings.data-dir;
125 description = "Daemon user for Ethereum Swarm Bee";
129 users.groups = lib.optionalAttrs (cfg.group == "bee") {