19 cfg = config.services.quorum;
20 opt = options.services.quorum;
21 dataDir = "/var/lib/quorum";
22 genesisFile = pkgs.writeText "genesis.json" (builtins.toJSON cfg.genesis);
23 staticNodesFile = pkgs.writeText "static-nodes.json" (builtins.toJSON cfg.staticNodes);
30 enable = mkEnableOption "Quorum blockchain daemon";
35 description = "The user as which to run quorum.";
41 defaultText = literalExpression "config.${opt.user}";
42 description = "The group as which to run quorum.";
48 description = "Override the default port on which to listen for connections.";
51 nodekeyFile = mkOption {
53 default = "${dataDir}/nodekey";
54 description = "Path to the nodekey.";
57 staticNodes = mkOption {
58 type = types.listOf types.str;
61 "enode://dd333ec28f0a8910c92eb4d336461eea1c20803eed9cf2c056557f986e720f8e693605bba2f4e8f289b1162e5ac7c80c914c7178130711e393ca76abc1d92f57@0.0.0.0:30303?discport=0"
63 description = "List of validator nodes.";
66 privateconfig = mkOption {
69 description = "Configuration of privacy transaction manager.";
79 description = "Blockchain sync mode.";
82 blockperiod = mkOption {
85 description = "Default minimum difference between two consecutive block's timestamps in seconds.";
88 permissioned = mkOption {
91 description = "Allow only a defined list of nodes to connect.";
98 description = "Enable RPC interface.";
104 description = "Listening address for RPC connections.";
110 description = "Override the default port on which to listen for RPC connections.";
115 default = "admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum,istanbul";
116 description = "API's offered over the HTTP-RPC interface.";
124 description = "Enable WS-RPC interface.";
130 description = "Listening address for WS-RPC connections.";
136 description = "Override the default port on which to listen for WS-RPC connections.";
141 default = "admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum,istanbul";
142 description = "API's offered over the WS-RPC interface.";
148 description = "Origins from which to accept websockets requests";
153 type = types.nullOr types.attrs;
155 example = literalExpression ''
158 a47385db68718bdcbddc2d2bb7c54018066ec111 = {
159 balance = "1000000000000000000000000000";
162 coinbase = "0x0000000000000000000000000000000000000000";
177 extraData = "0x0000000000000000000000000000000000000000000000000000000000000000f85ad59438f0508111273d8e482f49410ca4078afc86a961b8410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0";
178 gasLimit = "0x2FEFD800";
179 mixHash = "0x63746963616c2062797a616e74696e65201111756c7420746f6c6572616e6365";
181 parentHash = "0x0000000000000000000000000000000000000000000000000000000000000000";
184 description = "Blockchain genesis settings.";
189 config = mkIf cfg.enable {
190 environment.systemPackages = [ pkgs.quorum ];
191 systemd.tmpfiles.rules = [
192 "d '${dataDir}' 0770 '${cfg.user}' '${cfg.group}' - -"
194 systemd.services.quorum = {
195 description = "Quorum daemon";
196 after = [ "network.target" ];
197 wantedBy = [ "multi-user.target" ];
199 PRIVATE_CONFIG = "${cfg.privateconfig}";
202 if [ ! -d ${dataDir}/geth ]; then
203 if [ ! -d ${dataDir}/keystore ]; then
204 echo ERROR: You need to create a wallet before initializing your genesis file, run:
205 echo # su -s /bin/sh - quorum
206 echo $ geth --datadir ${dataDir} account new
207 echo and configure your genesis file accordingly.
210 ln -s ${staticNodesFile} ${dataDir}/static-nodes.json
211 ${pkgs.quorum}/bin/geth --datadir ${dataDir} init ${genesisFile}
218 ${pkgs.quorum}/bin/geth \
221 --nodekey ${cfg.nodekeyFile} \
222 --istanbul.blockperiod ${toString cfg.blockperiod} \
223 --syncmode ${cfg.syncmode} \
224 ${optionalString (cfg.permissioned) "--permissioned"} \
225 --mine --miner.threads 1 \
226 ${optionalString (cfg.rpc.enable) "--rpc --rpcaddr ${cfg.rpc.address} --rpcport ${toString cfg.rpc.port} --rpcapi ${cfg.rpc.api}"} \
227 ${optionalString (cfg.ws.enable) "--ws --ws.addr ${cfg.ws.address} --ws.port ${toString cfg.ws.port} --ws.api ${cfg.ws.api} --ws.origins ${cfg.ws.origins}"} \
229 --datadir ${dataDir} \
230 --port ${toString cfg.port}'';
231 Restart = "on-failure";
235 ProtectSystem = "full";
236 NoNewPrivileges = "true";
237 PrivateDevices = "true";
238 MemoryDenyWriteExecute = "true";
241 users.users.${cfg.user} = {
244 description = "Quorum daemon user";
248 users.groups.${cfg.group} = { };