From a68fcd87e5fa0281d477692f19528cebf452d6d9 Mon Sep 17 00:00:00 2001 From: Samuel Leathers Date: Thu, 18 Jun 2020 02:38:41 -0400 Subject: [PATCH] supervisord-cluster: initial setup add supervisord-cluster to shell.nix supervisord cluster: map service accross numBft and numPools Build pools setup transaction (transfer, register, delegate). Ignore supervisord.pid cluster improvements iohk-nix: back to master stylistic changes Fix dockerImage attr in default.nix --- .gitignore | 3 +- Makefile | 2 +- default.nix | 18 +- nix/pkgs.nix | 10 + nix/sources.json | 6 +- nix/supervisord-cluster/base-env.nix | 23 ++ nix/supervisord-cluster/default.nix | 283 ++++++++++++++++++++++ nix/supervisord-cluster/genesis-utxo.skey | 4 + nix/supervisord-cluster/genesis-utxo.vkey | 4 + nix/supervisord-cluster/initial-funds.nix | 10 + release.nix | 2 +- shell.nix | 17 +- 12 files changed, 361 insertions(+), 21 deletions(-) create mode 100644 nix/supervisord-cluster/base-env.nix create mode 100644 nix/supervisord-cluster/default.nix create mode 100644 nix/supervisord-cluster/genesis-utxo.skey create mode 100644 nix/supervisord-cluster/genesis-utxo.vkey create mode 100644 nix/supervisord-cluster/initial-funds.nix diff --git a/.gitignore b/.gitignore index 44db21849b..b94e13b4d7 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ dist/ \.#* *.swp .dir-locals.el -/result* +result* /launch-* stack.yaml.lock @@ -28,6 +28,7 @@ stack.yaml.lock *.stats /cluster /cluster.* +supervisord.pid tags /config diff --git a/Makefile b/Makefile index 300fb1b584..1726e00eb7 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ stylish-haskell: ## Apply stylish-haskell on all *.hs files @find . -type f -name "*.hs" -not -path '.git' -not -path '*.stack-work*' -print0 | xargs -0 stylish-haskell -i cabal-hashes: - $$(nix-build default.nix -A checkCabalProject --no-out-link) + $$(nix-build ./nix -A iohkNix.checkCabalProject --no-out-link) ghci: ## Run repl @stack ghci $(PROJECT_NAME):lib --haddock-deps --ghci-options=-fobject-code --nix diff --git a/default.nix b/default.nix index c8aa948623..fcf4ee13c1 100644 --- a/default.nix +++ b/default.nix @@ -36,7 +36,7 @@ let }; customConfig' = defaultConfig // customConfig; in pkgs.callPackage ./nix/docker.nix { - inherit (self) cardano-node; + inherit (packages) cardano-node; scripts = callPackage ./nix/scripts.nix { customConfig = customConfig'; }; }; @@ -54,19 +54,13 @@ let $STRIP $out/bin/* '' else p; - self = { - inherit haskellPackages scripts nixosTests environments dockerImage; + packages = { + inherit haskellPackages cardano-node cardano-cli chairman db-converter + scripts nixosTests environments dockerImage; inherit (haskellPackages.cardano-node.identifier) version; - # Grab the executable component of our package. - inherit (haskellPackages.cardano-node.components.exes) cardano-node; - cardano-node-profiled = cardanoNodeProfiledHaskellPackages.cardano-node.components.exes.cardano-node; - inherit (haskellPackages.cardano-cli.components.exes) cardano-cli; - inherit (haskellPackages.cardano-node.components.exes) chairman; - # expose the db-converter from the ouroboros-network we depend on - inherit (cardanoNodeHaskellPackages.ouroboros-consensus-byron.components.exes) db-converter; - inherit (pkgs.iohkNix) checkCabalProject; + cluster = mkCluster customConfig; exes = mapAttrsRecursiveCond (as: !(isDerivation as)) rewrite-static (collectComponents' "exes" haskellPackages); @@ -85,4 +79,4 @@ let withHoogle = true; }; }; -in self +in packages diff --git a/nix/pkgs.nix b/nix/pkgs.nix index b5edc2c91b..0892125711 100644 --- a/nix/pkgs.nix +++ b/nix/pkgs.nix @@ -19,4 +19,14 @@ pkgs: _: with pkgs; { ; profiling = true; }; + + #Grab the executable component of our package. + inherit (cardanoNodeHaskellPackages.cardano-node.components.exes) cardano-node chairman; + inherit (cardanoNodeHaskellPackages.cardano-cli.components.exes) cardano-cli; + cardano-node-profiled = cardanoNodeProfiledHaskellPackages.cardano-node.components.exes.cardano-node; + + # expose the db-converter from the ouroboros-network we depend on + inherit (cardanoNodeHaskellPackages.ouroboros-consensus-byron.components.exes) db-converter; + + mkCluster = callPackage ./supervisord-cluster; } diff --git a/nix/sources.json b/nix/sources.json index 561a4094c5..bf7a75a415 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -41,10 +41,10 @@ "homepage": null, "owner": "input-output-hk", "repo": "iohk-nix", - "rev": "a3eae81cbae000bbfdc2bc1880528512747a3a9c", - "sha256": "1jairn2vp43z36j0b1fi2nmnfpadff217dqv5bjjxm5v099g0gsw", + "rev": "ccad0bf9ceb3a68a837886f8032da0e70529d183", + "sha256": "0hyzqbws8j1bvkb4m0ngck7mgs41p2wp9gy6ncvx1pf2svwz9916", "type": "tarball", - "url": "https://github.com/input-output-hk/iohk-nix/archive/a3eae81cbae000bbfdc2bc1880528512747a3a9c.tar.gz", + "url": "https://github.com/input-output-hk/iohk-nix/archive/ccad0bf9ceb3a68a837886f8032da0e70529d183.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/nix/supervisord-cluster/base-env.nix b/nix/supervisord-cluster/base-env.nix new file mode 100644 index 0000000000..567e187e37 --- /dev/null +++ b/nix/supervisord-cluster/base-env.nix @@ -0,0 +1,23 @@ +{ + defaultLogConfig +, stateDir +}: + +rec { + inherit stateDir; + useByronWallet = true; + relaysNew = "127.0.0.1"; + edgePort = 3001; + confKey = "local"; + private = false; + networkConfig = { + GenesisFile = "keys/genesis.json"; + Protocol = "TPraos"; + RequiresNetworkMagic = "RequiresMagic"; + LastKnownBlockVersion-Major = 0; + LastKnownBlockVersion-Minor = 0; + LastKnownBlockVersion-Alt = 0; + }; + nodeConfig = networkConfig // defaultLogConfig; + consensusProtocol = networkConfig.Protocol; +} diff --git a/nix/supervisord-cluster/default.nix b/nix/supervisord-cluster/default.nix new file mode 100644 index 0000000000..1f796ddd92 --- /dev/null +++ b/nix/supervisord-cluster/default.nix @@ -0,0 +1,283 @@ +{ + pkgs +, lib +, cardano-cli +, numBft ? 1 +, numPools ? 2 +, d ? "0.5" +, basePort ? 30000 +, stateDir ? "./state-cluster" +, initialFunds ? import ./initial-funds.nix +}: +let + baseEnvConfig = pkgs.callPackage ./base-env.nix { inherit (pkgs.commonLib.cardanoLib) defaultLogConfig; inherit stateDir; }; + mkStartScript = envConfig: let + systemdCompat.options = { + systemd.services = lib.mkOption {}; + users = lib.mkOption {}; + assertions = lib.mkOption {}; + }; + eval = let + extra = { + services.cardano-node = { + enable = true; + inherit (envConfig) operationalCertificate kesKey vrfKey topology nodeConfig nodeConfigFile port dbPrefix socketPath; + inherit stateDir; + }; + }; + in lib.evalModules { + prefix = []; + modules = import ../nixos/module-list.nix ++ [ systemdCompat extra ]; + args = { inherit pkgs; }; + }; + in pkgs.writeScript "cardano-node" '' + #!${pkgs.stdenv.shell} + ${eval.config.services.cardano-node.script} + ''; + topologyFile = selfPort: { + Producers = map (p: + { + addr = "127.0.0.1"; + port = p; + valency = 1; + }) (lib.filter (p: p != selfPort) (lib.genList (i: basePort + i + 1) (numBft + numPools))); + }; + supervisorConfig = pkgs.writeText "supervisor.conf" (pkgs.commonLib.supervisord.writeSupervisorConfig ({ + supervisord = { + logfile = "${stateDir}/supervisord.log"; + pidfile = "${stateDir}/supervisord.pid"; + }; + supervisorctl = {}; + inet_http_server = { + port = "127.0.0.1:9001"; + }; + "rpcinterface:supervisor" = { + "supervisor.rpcinterface_factory" = "supervisor.rpcinterface:make_main_rpcinterface"; + }; + } // lib.listToAttrs (map (i: + lib.nameValuePair "program:bft${toString i}" { + command = let + envConfig = baseEnvConfig // rec { + operationalCertificate = "${stateDir}/keys/node-bft${toString i}/op.cert"; + kesKey = "${stateDir}/keys/node-bft${toString i}/kes.skey"; + vrfKey = "${stateDir}/keys/node-bft${toString i}/vrf.skey"; + topology = __toFile "topology.yaml" (__toJSON (topologyFile port)); + socketPath = "${stateDir}/bft${toString i}.socket"; + dbPrefix = "db-bft${toString i}"; + port = basePort + i; + nodeConfigFile = "${stateDir}/config.json"; + }; + script = mkStartScript envConfig; + in "${script}"; + stdout_logfile = "${stateDir}/bft${toString i}.stdout"; + stderr_logfile = "${stateDir}/bft${toString i}.stderr"; + } + ) (lib.genList (i: i + 1) numBft)) + // lib.listToAttrs (map (i: + lib.nameValuePair "program:pool${toString i}" { + command = let + envConfig = baseEnvConfig // rec { + operationalCertificate = "${stateDir}/keys/node-pool${toString i}/op.cert"; + kesKey = "${stateDir}/keys/node-pool${toString i}/kes.skey"; + vrfKey = "${stateDir}/keys/node-pool${toString i}/vrf.skey"; + topology = __toFile "topology.yaml" (__toJSON (topologyFile port)); + socketPath = "${stateDir}/pool${toString i}.socket"; + dbPrefix = "db-pool${toString i}"; + port = basePort + numBft + i; + nodeConfigFile = "${stateDir}/config.json"; + }; + script = mkStartScript envConfig; + in "${script}"; + stdout_logfile = "${stateDir}/pool${toString i}.stdout"; + stderr_logfile = "${stateDir}/pool${toString i}.stderr"; + } + ) (lib.genList (i: i + 1) numPools)) + // { + "program:webserver" = { + command = "${pkgs.python3}/bin/python -m http.server ${toString basePort}"; + directory = "${stateDir}/webserver"; + }; + + })); + path = lib.makeBinPath [ cardano-cli pkgs.jq pkgs.gnused pkgs.coreutils pkgs.bash pkgs.moreutils ]; + genFiles = '' + PATH=${path} + rm -rf ${stateDir} + mkdir -p ${stateDir}/{keys,webserver} + cp ${__toFile "node.json" (__toJSON baseEnvConfig.nodeConfig)} ${stateDir}/config.json + cardano-cli shelley genesis create --testnet-magic 42 \ + --genesis-dir ${stateDir}/keys \ + --gen-genesis-keys ${toString numBft} \ + --gen-utxo-keys 1 + jq -r --arg slotLength 0.2 \ + --arg activeSlotsCoeff 0.1 \ + --arg securityParam 10 \ + --arg epochLength 1500 \ + --arg maxLovelaceSupply 45000000000000000 \ + --arg decentralisationParam ${toString d} \ + --arg updateQuorum ${toString numBft} \ + --arg systemStart $(date --utc +"%Y-%m-%dT%H:%M:%SZ" --date="5 seconds") \ + '. + { + systemStart: $systemStart, + slotLength: $slotLength|tonumber, + activeSlotsCoeff: $activeSlotsCoeff|tonumber, + securityParam: $securityParam|tonumber, + epochLength: $epochLength|tonumber, + maxLovelaceSupply: $maxLovelaceSupply|tonumber, + decentralisationParam: $decentralisationParam|tonumber, + updateQuorum: $updateQuorum|tonumber, + initialFunds: ${__toJSON initialFunds} + }' \ + ${stateDir}/keys/genesis.json | sponge ${stateDir}/keys/genesis.json + for i in {1..${toString numBft}} + do + mkdir -p "${stateDir}/keys/node-bft$i" + ln -s "../delegate-keys/delegate$i.vrf.skey" "${stateDir}/keys/node-bft$i/vrf.skey" + ln -s "../delegate-keys/delegate$i.vrf.vkey" "${stateDir}/keys/node-bft$i/vrf.vkey" + cardano-cli shelley node key-gen-KES \ + --verification-key-file "${stateDir}/keys/node-bft$i/kes.vkey" \ + --signing-key-file "${stateDir}/keys/node-bft$i/kes.skey" + cardano-cli shelley node issue-op-cert \ + --kes-period 0 \ + --cold-signing-key-file "${stateDir}/keys/delegate-keys/delegate$i.skey" \ + --kes-verification-key-file "${stateDir}/keys/node-bft$i/kes.vkey" \ + --operational-certificate-issue-counter-file "${stateDir}/keys/delegate-keys/delegate$i.counter" \ + --out-file "${stateDir}/keys/node-bft$i/op.cert" + BFT_PORT=$(("${toString basePort}" + $i)) + echo "$BFT_PORT" > "${stateDir}/keys/node-bft$i/port" + done + for i in {1..${toString numPools}} + do + mkdir -p "${stateDir}/keys/node-pool$i" + echo "Generating Pool $i Secrets" + cardano-cli shelley address key-gen \ + --signing-key-file "${stateDir}/keys/node-pool$i/owner-utxo.skey" \ + --verification-key-file "${stateDir}/keys/node-pool$i/owner-utxo.vkey" + cardano-cli shelley stake-address key-gen \ + --signing-key-file "${stateDir}/keys/node-pool$i/owner-stake.skey" \ + --verification-key-file "${stateDir}/keys/node-pool$i/owner-stake.vkey" + # Payment addresses + cardano-cli shelley address build \ + --payment-verification-key-file "${stateDir}/keys/node-pool$i/owner-utxo.vkey" \ + --stake-verification-key-file "${stateDir}/keys/node-pool$i/owner-stake.vkey" \ + --testnet-magic 42 \ + --out-file "${stateDir}/keys/node-pool$i/owner.addr" + # Stake addresses + cardano-cli shelley stake-address build \ + --stake-verification-key-file "${stateDir}/keys/node-pool$i/owner-stake.vkey" \ + --testnet-magic 42 \ + --out-file "${stateDir}/keys/node-pool$i/owner-stake.addr" + # Stake addresses registration certs + cardano-cli shelley stake-address registration-certificate \ + --stake-verification-key-file "${stateDir}/keys/node-pool$i/owner-stake.vkey" \ + --out-file "${stateDir}/keys/node-pool$i/stake.reg.cert" + + cardano-cli shelley stake-address key-gen \ + --signing-key-file "${stateDir}/keys/node-pool$i/reward.skey" \ + --verification-key-file "${stateDir}/keys/node-pool$i/reward.vkey" + cardano-cli shelley node key-gen \ + --cold-verification-key-file "${stateDir}/keys/node-pool$i/cold.vkey" \ + --cold-signing-key-file "${stateDir}/keys/node-pool$i/cold.skey" \ + --operational-certificate-issue-counter-file "${stateDir}/keys/node-pool$i/cold.counter" + cardano-cli shelley node key-gen-KES \ + --verification-key-file "${stateDir}/keys/node-pool$i/kes.vkey" \ + --signing-key-file "${stateDir}/keys/node-pool$i/kes.skey" + cardano-cli shelley node key-gen-VRF \ + --verification-key-file "${stateDir}/keys/node-pool$i/vrf.vkey" \ + --signing-key-file "${stateDir}/keys/node-pool$i/vrf.skey" + + # Stake address delegation certs + cardano-cli shelley stake-address delegation-certificate \ + --stake-verification-key-file "${stateDir}/keys/node-pool$i/owner-stake.vkey" \ + --cold-verification-key-file "${stateDir}/keys/node-pool$i/cold.vkey" \ + --out-file "${stateDir}/keys/node-pool$i/owner-stake.deleg.cert" + + cardano-cli shelley node issue-op-cert \ + --kes-period 0 \ + --cold-signing-key-file "${stateDir}/keys/node-pool$i/cold.skey" \ + --kes-verification-key-file "${stateDir}/keys/node-pool$i/kes.vkey" \ + --operational-certificate-issue-counter-file "${stateDir}/keys/node-pool$i/cold.counter" \ + --out-file "${stateDir}/keys/node-pool$i/op.cert" + + echo "Generating Pool $i Metadata" + jq -n \ + --arg name "CoolPool$i" \ + --arg description "Cool Pool $i" \ + --arg ticker "COOL$i" \ + --arg homepage "http://localhost:${toString basePort}/pool$i.html" \ + '{"name": $name, "description": $description, "ticker": $ticker, "homepage": $homepage}' > "${stateDir}/webserver/pool$i.json" + + METADATA_URL="http://localhost:${toString basePort}/pool$i.json" + METADATA_HASH=$(cardano-cli shelley stake-pool metadata-hash --pool-metadata-file "${stateDir}/webserver/pool$i.json") + POOL_IP="127.0.0.1" + POOL_PORT=$(("${toString basePort}" + "${toString numBft}" + $i)) + echo "$POOL_PORT" > "${stateDir}/keys/node-pool$i/port" + POOL_PLEDGE=$(( $RANDOM % 1000000000 + 1000000000000)) + echo $POOL_PLEDGE > "${stateDir}/keys/node-pool$i/pledge" + POOL_MARGIN_NUM=$(( $RANDOM % 10 + 1)) + + cardano-cli shelley stake-pool registration-certificate \ + --cold-verification-key-file "${stateDir}/keys/node-pool$i/cold.vkey" \ + --vrf-verification-key-file "${stateDir}/keys/node-pool$i/vrf.vkey" \ + --pool-pledge "$POOL_PLEDGE" \ + --pool-margin "$(jq -n $POOL_MARGIN_NUM/10)" \ + --pool-cost "$(($RANDOM % 100000000))" \ + --pool-reward-account-verification-key-file "${stateDir}/keys/node-pool$i/reward.vkey" \ + --pool-owner-stake-verification-key-file "${stateDir}/keys/node-pool$i/owner-stake.vkey" \ + --metadata-url "$METADATA_URL" \ + --metadata-hash "$METADATA_HASH" \ + --testnet-magic 42 \ + --out-file "${stateDir}/keys/node-pool$i/register.cert" + + done + + # Tranfer funds, register pools and delegations, all in one big transaction: + cardano-cli shelley transaction build-raw \ + --ttl 1000 \ + --fee ${toString (lib.mod 1000000000000000 numPools)} \ + --tx-in $(cardano-cli shelley genesis initial-txin \ + --testnet-magic 42 \ + --verification-key-file ${./genesis-utxo.vkey}) \ + ${lib.concatMapStringsSep "" (i: '' + --tx-out $(cat "${stateDir}/keys/node-pool${toString i}/owner.addr")+${toString (1000000000000000 / numPools)} \ + --certificate-file "${stateDir}/keys/node-pool${toString i}/stake.reg.cert" \ + --certificate-file "${stateDir}/keys/node-pool${toString i}/register.cert" \ + --certificate-file "${stateDir}/keys/node-pool${toString i}/owner-stake.deleg.cert" \'') (lib.genList (i: i + 1) numPools)} + --out-file "${stateDir}/keys/transfer-register-delegate-tx.txbody" + + cardano-cli shelley transaction sign \ + --signing-key-file ${./genesis-utxo.skey} \ + ${lib.concatMapStringsSep "" (i: '' + --signing-key-file "${stateDir}/keys/node-pool${toString i}/owner-stake.skey" \ + --signing-key-file "${stateDir}/keys/node-pool${toString i}/reward.skey" \ + --signing-key-file "${stateDir}/keys/node-pool${toString i}/cold.skey" \'') (lib.genList (i: i + 1) numPools)} + --testnet-magic 42 \ + --tx-body-file "${stateDir}/keys/transfer-register-delegate-tx.txbody" \ + --out-file "${stateDir}/keys/transfer-register-delegate-tx.tx" + + ''; + + start = pkgs.writeScriptBin "start-cluster" '' + set -euo pipefail + ${genFiles} + ${pkgs.python3Packages.supervisor}/bin/supervisord --config ${supervisorConfig} $@ + while [ ! -S $CARDANO_NODE_SOCKET_PATH ]; do echo "Waiting 10 seconds for bft node to start"; sleep 10; done + echo "Transfering genesis funds to pool owners, register pools and delegations" + cardano-cli shelley transaction submit \ + --tx-file ${stateDir}/keys/transfer-register-delegate-tx.tx \ + --testnet-magic 42 + echo 'Cluster started. Run `stop-cluster` to stop' + ''; + stop = pkgs.writeScriptBin "stop-cluster" '' + set -euo pipefail + ${pkgs.python3Packages.supervisor}/bin/supervisorctl stop all + if [ -f ${stateDir}/supervisord.pid ] + then + kill $(<${stateDir}/supervisord.pid) + echo "Cluster terminated!" + else + echo "Cluster is not running!" + fi + ''; + +in { inherit baseEnvConfig start stop; } diff --git a/nix/supervisord-cluster/genesis-utxo.skey b/nix/supervisord-cluster/genesis-utxo.skey new file mode 100644 index 0000000000..3eeb7cff43 --- /dev/null +++ b/nix/supervisord-cluster/genesis-utxo.skey @@ -0,0 +1,4 @@ +type: Genesis UTxO signing key +title: Genesis Initial UTxO Signing Key +cbor-hex: + 58201f0655ba7500f4e923cac3741e730a325b7f2df549f949a19f7f7995de021964 diff --git a/nix/supervisord-cluster/genesis-utxo.vkey b/nix/supervisord-cluster/genesis-utxo.vkey new file mode 100644 index 0000000000..51c6d5f678 --- /dev/null +++ b/nix/supervisord-cluster/genesis-utxo.vkey @@ -0,0 +1,4 @@ +type: Genesis UTxO verification key +title: Genesis Initial UTxO Verification Key +cbor-hex: + 582055d24618feb099af69a9588cb6beb2e103f451a4f3869949576b7765aaef7c7a diff --git a/nix/supervisord-cluster/initial-funds.nix b/nix/supervisord-cluster/initial-funds.nix new file mode 100644 index 0000000000..9475f1c592 --- /dev/null +++ b/nix/supervisord-cluster/initial-funds.nix @@ -0,0 +1,10 @@ +{ + # genesis-utxo (used for pool owner funds and paying fees for startup scripts) + "60be70ba6650981b1e369caf6e66f36527797668f5c796d209fe42a6599af9ef95" = 1000000000000000; + # flee three produce crush token where quantum vessel seek include dance reject urge awesome lonely + "00da45b43746dec67dfe3647f3dfee9fb8bf0723883e40ca14b51234c8e62cf6242003415534e919acb2c07132a588827fb8e6b968861b1e5d807b756fe72d6e28" = 100000000000000; + "0036af4eaf83f34348829c0b88515238e3bbe7c7b69a5b3659bc3155521da98aa12003415534e919acb2c07132a588827fb8e6b968861b1e5d807b756fe72d6e28" = 100000000000000; + "00bee681d5f0dbd1b047c0311ab1211640f5f862c614d5db9e21fc08ddb163aba02003415534e919acb2c07132a588827fb8e6b968861b1e5d807b756fe72d6e28" = 100000000000000; + "00b84e9b8980d61ade5167f3e697641acae5e6eec546fcdbc5c03149a02595d4202003415534e919acb2c07132a588827fb8e6b968861b1e5d807b756fe72d6e28" = 100000000000000; + "000b04a2d5dc696f845a7bbe7ead094ac12e8dbbf82eedeabe9cb2fe8c07f1624c2003415534e919acb2c07132a588827fb8e6b968861b1e5d807b756fe72d6e28" = 100000000000000; +} diff --git a/release.nix b/release.nix index 8d53d2e954..43e0868cfe 100644 --- a/release.nix +++ b/release.nix @@ -100,7 +100,7 @@ let ) ds); # Remove build jobs for which cross compiling does not make sense. - filterJobsCross = filterAttrs (n: _: n != "dockerImage" && n != "shell" && n != "checkCabalProject"); + filterJobsCross = filterAttrs (n: _: n != "dockerImage" && n != "shell" && n != "cluster"); inherit (systems.examples) mingwW64 musl64; diff --git a/shell.nix b/shell.nix index 6bdcbd8993..483598f90b 100644 --- a/shell.nix +++ b/shell.nix @@ -44,12 +44,18 @@ let inherit withHoogle; }; - devops = pkgs.stdenv.mkDerivation { + devops = let + cluster = mkCluster customConfig; + in + stdenv.mkDerivation { name = "devops-shell"; buildInputs = [ niv - cardanoNodeHaskellPackages.cardano-cli.components.exes.cardano-cli - cardanoNodeHaskellPackages.cardano-node.components.exes.cardano-node + cardano-cli + cardano-node + python3Packages.supervisor + cluster.start + cluster.stop ]; shellHook = '' echo "DevOps Tools" \ @@ -59,6 +65,9 @@ let source <(cardano-cli --bash-completion-script cardano-cli) source <(cardano-node --bash-completion-script cardano-node) + # Socket path default to first BFT node launched by "start-cluster": + export CARDANO_NODE_SOCKET_PATH=$PWD/${cluster.baseEnvConfig.stateDir}/bft1.socket + # Unless using specific network: ${lib.optionalString (__hasAttr "network" customConfig) '' export CARDANO_NODE_SOCKET_PATH="$PWD/state-node-${customConfig.network}/node.socket" ${lib.optionalString (__hasAttr "utxo" pkgs.commonLib.cardanoLib.environments.${customConfig.network}) '' @@ -74,6 +83,8 @@ let echo "Commands: * niv update - update package * cardano-cli - used for key generation and other operations tasks + * start-cluster - start a local development cluster + * stop-cluster - stop a local development cluster " '';