Skip to content

Commit

Permalink
Merge pull request #43 from cspr-rad/nixify-2.0
Browse files Browse the repository at this point in the history
LGTM
  • Loading branch information
asladeofgreen authored Aug 13, 2024
2 parents 03687b5 + fbad730 commit 2da83ec
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 23 deletions.
93 changes: 89 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion overlay.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
final: prev: {
cctl = final.callPackage ./package.nix { };
cctl = final.callPackage ./package.nix { casper-node = final.casper-node_2; };
}
65 changes: 49 additions & 16 deletions package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
, casper-node
, casper-node-launcher
, casper-node-contracts
, casper-sidecar
, coreutils
, python3
, writeShellScriptBin
Expand All @@ -10,6 +11,7 @@
, less
, lsof
, jq
, runCommand
}:
let
python = python3.withPackages (ps: with ps; [ supervisor tomlkit toml ]);
Expand All @@ -20,13 +22,32 @@ let
casper-node
casper-node-launcher
casper-node-contracts
casper-sidecar
];
};
casperResources = runCommand "casper-resources" { } ''
create_symlinks() {
local resource_dir="$1"
local target_dir="$2"
mkdir -p "$target_dir"
for nested_dir in "$resource_dir"/*/; do
echo $nested_dir
if [ -d "$nested_dir" ]; then
# Get the base name of the directory
base_name=$(basename "$nested_dir")
# Create a symlink in the target directory
ln -s "$nested_dir" "$target_dir/$base_name"
fi
done
}
create_symlinks "${casper-node.src}/resources" "$out/casper-node"
create_symlinks "${casper-sidecar.src}/resources" "$out/casper-sidecar"
'';
src = ./.;
mkCctlCommand = commandName: commandPath: writeShellScriptBin "cctl-${commandName}" ''
export CCTL=${src}
export CCTL_ASSETS=''${CCTL_ASSETS:-./assets}
export CSPR_PATH_TO_RESOURCES=${casper-node.src}/resources
export CSPR_PATH_TO_RESOURCES=${casperResources}
export CSPR_PATH_TO_BIN=${cspr-bins}/bin
${builtins.readFile "${src}/cmds/${commandPath}.sh"}
'';
Expand All @@ -42,17 +63,19 @@ symlinkJoin {
jq
# Infrastructure Commands:
# ... network
(mkCctlCommand "infra-net-setup" "infra/net/setup")
(mkCctlCommand "infra-net-start" "infra/net/start")
(mkCctlCommand "infra-net-status" "infra/net/status")
(mkCctlCommand "infra-net-stop" "infra/net/stop")
(mkCctlCommand "infra-net-teardown" "infra/net/teardown")
(mkCctlCommand "infra-net-setup" "infra/net/ctl_setup")
(mkCctlCommand "infra-net-start" "infra/net/ctl_start")
(mkCctlCommand "infra-net-status" "infra/net/view_status")
(mkCctlCommand "infra-net-stop" "infra/net/ctl_stop")
(mkCctlCommand "infra-net-teardown" "infra/net/ctl_teardown")
(mkCctlCommand "infra-net-view-paths" "infra/net/view_paths")
(mkCctlCommand "infra-net-view-status" "infra/net/view_status")

# ... node control
(mkCctlCommand "infra-node-clean" "infra/node/clean")
(mkCctlCommand "infra-node-stop" "infra/node/stop")
(mkCctlCommand "infra-node-restart" "infra/node/restart")
(mkCctlCommand "infra-node-clean" "infra/node/ctl_clean")
(mkCctlCommand "infra-node-restart" "infra/node/ctl_restart")
(mkCctlCommand "infra-node-start" "infra/node/ctl_start")
(mkCctlCommand "infra-node-stop" "infra/node/ctl_stop")

# ... node views
(mkCctlCommand "infra-node-view-config" "infra/node/view_config")
Expand All @@ -63,11 +86,24 @@ symlinkJoin {
(mkCctlCommand "infra-node-view-peer-count" "infra/node/view_peer_count")
(mkCctlCommand "infra-node-view-paths" "infra/node/view_paths")
(mkCctlCommand "infra-node-view-ports" "infra/node/view_ports")
(mkCctlCommand "infra-node-view-rpc-endpoint" "infra/node/view_rpc_endpoint")
(mkCctlCommand "infra-node-view-rpc-schema" "infra/node/view_rpc_schema")
(mkCctlCommand "infra-node-view-reactor-state" "infra/node/view_reactor_state")
(mkCctlCommand "infra-node-view-status" "infra/node/view_status")
(mkCctlCommand "infra-node-view-storage" "infra/node/view_storage")
(mkCctlCommand "infra-node-write-rpc-schema" "infra/node/write_rpc_schema")

# ... sidecar control
(mkCctlCommand "infra-sidecar-start" "infra/sidecar/ctl_start")
(mkCctlCommand "infra-sidecar-stop" "infra/sidecar/ctl_stop")
(mkCctlCommand "infra-sidecar-clean" "infra/sidecar/ctl_clean")

# ... sidecar views
(mkCctlCommand "infra-sidecar-view-config" "infra/sidecar/view_config")
(mkCctlCommand "infra-sidecar-view-error-log" "infra/sidecar/view_log_stderr")
(mkCctlCommand "infra-sidecar-view-log" "infra/sidecar/view_log_stdout")
(mkCctlCommand "infra-sidecar-view-paths" "infra/sidecar/view_paths")
(mkCctlCommand "infra-sidecar-view-ports" "infra/sidecar/view_ports")
(mkCctlCommand "infra-sidecar-view-rpc-endpoint" "infra/sidecar/view_rpc_endpoint")
(mkCctlCommand "infra-sidecar-view-rpc-schema" "infra/sidecar/view_rpc_schema")
(mkCctlCommand "infra-sidecar-write-rpc-schema" "infra/sidecar/write_rpc_schema")

# Chain commands:
# ... awaiting
Expand All @@ -78,23 +114,20 @@ symlinkJoin {

# ... views
(mkCctlCommand "chain-view-account" "chain/query/view_account")
(mkCctlCommand "chain-view-account-address" "chain/query/view_account_address")
(mkCctlCommand "chain-view-account-balance" "chain/query/view_account_balance")
(mkCctlCommand "chain-view-account-balances" "chain/query/view_account_balances")
(mkCctlCommand "chain-view-account-of-faucet" "chain/query/view_account_of_faucet")
(mkCctlCommand "chain-view-account-of-user" "chain/query/view_account_of_user")
(mkCctlCommand "chain-view-account-of-validator" "chain/query/view_account_of_validator")
(mkCctlCommand "chain-view-auction-info" "chain/query/view_auction_info")
(mkCctlCommand "chain-view-block" "chain/query/view_block")
(mkCctlCommand "chain-view-block-transfers" "chain/query/view_block_transfers")
(mkCctlCommand "chain-view-deploy" "chain/query/view_deploy")
(mkCctlCommand "chain-view-era" "chain/query/view_era")
(mkCctlCommand "chain-view-era-summary" "chain/query/view_era_summary")
(mkCctlCommand "chain-view-genesis-accounts" "chain/query/view_genesis_accounts")
(mkCctlCommand "chain-view-genesis-chainspec" "chain/query/view_genesis_chainspec")
(mkCctlCommand "chain-view-height" "chain/query/view_height")
(mkCctlCommand "chain-view-last-finalized-block" "chain/query/view_last_finalized_block")
(mkCctlCommand "chain-view-state-root-hash" "chain/query/view_state_root_hash")
(mkCctlCommand "chain-view-view-tx" "chain/query/view_tx")
(mkCctlCommand "chain-view-view-tip-info" "chain/query/view_tip_info")
(mkCctlCommand "chain-view-view-validator-changes" "chain/query/view_validator_changes")

Expand Down
4 changes: 2 additions & 2 deletions utils/paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function get_path_to_assets()
function get_path_to_config_templates_of_node()
{
if ((${#CSPR_PATH_TO_RESOURCES[@]})); then
echo $CSPR_PATH_TO_RESOURCES
echo $CSPR_PATH_TO_RESOURCES/casper-node
else
echo $(get_path_to_working_directory)/casper-node/resources
fi
Expand All @@ -32,7 +32,7 @@ function get_path_to_config_templates_of_node()
function get_path_to_config_templates_of_sidecar()
{
if ((${#CSPR_PATH_TO_RESOURCES[@]})); then
echo $CSPR_PATH_TO_RESOURCES
echo $CSPR_PATH_TO_RESOURCES/casper-sidecar
else
echo $(get_path_to_working_directory)/casper-sidecar/resources
fi
Expand Down

0 comments on commit 2da83ec

Please sign in to comment.