Skip to content

Commit

Permalink
feat(nix): configure treefmt for nix fmt
Browse files Browse the repository at this point in the history
This commit configures rustfmt, alejandra, prettier, and shfmt.
  • Loading branch information
johnyob committed Aug 22, 2024
1 parent 6e104d8 commit 0e4da48
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 290 deletions.
154 changes: 77 additions & 77 deletions crates/jstz_rollup/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mkdir -p "$JSTZ_ROLLUP_OCTEZ_CLIENT_DIR"
export JSTZ_ROLLUP_OCTEZ_ROLLUP_NODE_DIR="/root/.octez-smart-rollup-node"
mkdir -p "$JSTZ_ROLLUP_OCTEZ_ROLLUP_NODE_DIR"

# shellcheck disable=SC2034
# shellcheck disable=SC2034
# JSTZ_ROLLUP_OCTEZ_NODE_ENDPOINT is used in the jstz-rollup command
export JSTZ_ROLLUP_OCTEZ_NODE_ENDPOINT="https://rpc.$NETWORK.teztnets.com/"

Expand All @@ -16,96 +16,96 @@ installer_dir="root/installer"
logs_dir="root/logs"

if [ ! -f "$JSTZ_ROLLUP_OCTEZ_CLIENT_DIR/secret_keys" ]; then
echo "Importing operator secret key..."
if [ -z "$OPERATOR_SK" ]; then
echo "OPERATOR_SK is not set"
exit 1
fi
jstz-rollup operator import-keys --secret-key "$OPERATOR_SK"
echo "Importing operator secret key..."
if [ -z "$OPERATOR_SK" ]; then
echo "OPERATOR_SK is not set"
exit 1
fi
jstz-rollup operator import-keys --secret-key "$OPERATOR_SK"
fi

make-installer() {
jstz-rollup make-installer \
--kernel "$kernel_path" \
--bridge "$JSTZ_ROLLUP_BRIDGE_ADDRESS" \
--output "$installer_dir"
# Check the exit status of the last command
if [ $? -eq 0 ]; then
echo "Installer created successfully in $installer_dir."
else
echo "Failed to create installer. Please check the parameters and try again."
exit 1
fi
jstz-rollup make-installer \
--kernel "$kernel_path" \
--bridge "$JSTZ_ROLLUP_BRIDGE_ADDRESS" \
--output "$installer_dir"

# Check the exit status of the last command
if [ $? -eq 0 ]; then
echo "Installer created successfully in $installer_dir."
else
echo "Failed to create installer. Please check the parameters and try again."
exit 1
fi
}

deploy-bridge() {
jstz-rollup deploy-bridge \
--operator "$OPERATOR_ADDRESS"
jstz-rollup deploy-bridge \
--operator "$OPERATOR_ADDRESS"
}

deploy-installer() {
jstz-rollup deploy-installer \
--installer "$installer_dir/installer.wasm" \
--bridge "$JSTZ_ROLLUP_BRIDGE_ADDRESS"
jstz-rollup deploy-installer \
--installer "$installer_dir/installer.wasm" \
--bridge "$JSTZ_ROLLUP_BRIDGE_ADDRESS"
}

run() {
if [ -z "$(ls -A $installer_dir)" ]; then
make-installer
fi

mkdir -p "$logs_dir"

jstz-rollup run \
--preimages "$installer_dir/preimages" \
--rollup "$JSTZ_ROLLUP_ADDRESS" \
--logs "$logs_dir" \
--addr "0.0.0.0"
exit_status=$?

if [ $exit_status -eq 0 ]; then
echo "jstz-rollup node started successfully."
else
echo "Failed to start jstz-rollup node. Exit status: $exit_status"
exit $exit_status
fi
if [ -z "$(ls -A $installer_dir)" ]; then
make-installer
fi

mkdir -p "$logs_dir"

jstz-rollup run \
--preimages "$installer_dir/preimages" \
--rollup "$JSTZ_ROLLUP_ADDRESS" \
--logs "$logs_dir" \
--addr "0.0.0.0"

exit_status=$?

if [ $exit_status -eq 0 ]; then
echo "jstz-rollup node started successfully."
else
echo "Failed to start jstz-rollup node. Exit status: $exit_status"
exit $exit_status
fi
}

deploy() {
JSTZ_ROLLUP_BRIDGE_ADDRESS=$(deploy-bridge | grep -oE 'KT1[a-zA-Z0-9]{33}' | uniq | tr -d '\n')
echo "Bridge address: $JSTZ_ROLLUP_BRIDGE_ADDRESS"

jstz-rollup deploy \
--kernel "$kernel_path" \
--bridge "$JSTZ_ROLLUP_BRIDGE_ADDRESS" \
--output "$installer_dir" \
--operator "$OPERATOR_ADDRESS"
JSTZ_ROLLUP_BRIDGE_ADDRESS=$(deploy-bridge | grep -oE 'KT1[a-zA-Z0-9]{33}' | uniq | tr -d '\n')
echo "Bridge address: $JSTZ_ROLLUP_BRIDGE_ADDRESS"

jstz-rollup deploy \
--kernel "$kernel_path" \
--bridge "$JSTZ_ROLLUP_BRIDGE_ADDRESS" \
--output "$installer_dir" \
--operator "$OPERATOR_ADDRESS"
}

main() {
command="$1"
shift 1

case $command in
"run")
run
;;
"deploy")
deploy
;;
"deploy-bridge")
deploy-bridge
;;
"deploy-installer")
deploy-installer
;;
"make-installer")
make-installer
;;
*)
cat <<EOF
command="$1"
shift 1

case $command in
"run")
run
;;
"deploy")
deploy
;;
"deploy-bridge")
deploy-bridge
;;
"deploy-installer")
deploy-installer
;;
"make-installer")
make-installer
;;
*)
cat <<EOF
Usage: $0 <COMMAND>
Commands:
Expand All @@ -115,11 +115,11 @@ Commands:
deploy-installer
make-installer
EOF
exit 1
;;
esac
exit 1
;;
esac
}

if [ "$0" == "${BASH_SOURCE[0]}" ]; then
main "$@"
main "$@"
fi
23 changes: 22 additions & 1 deletion flake.lock

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

25 changes: 24 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
treefmt = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};

# Rust support
rust-overlay = {
Expand Down Expand Up @@ -54,9 +58,28 @@
rust-toolchain = pkgs.callPackage ./nix/rust-toolchain.nix {};
crates = pkgs.callPackage ./nix/crates.nix {inherit crane rust-toolchain;};
js-packages = pkgs.callPackage ./nix/js-packages.nix {};

fmt = treefmt.lib.evalModule pkgs {
projectRootFile = "flake.nix";

programs.rustfmt.enable = true;
programs.alejandra.enable = true;
programs.prettier.enable = true;
programs.shfmt.enable = true;

# TODO(https://linear.app/tezos/issue/JSTZ-64)
# Configure shellcheck for shell scripts
# programs.shellcheck.enable = true;

# TODO(https://linear.app/tezos/issue/JSTZ-63)
# Configure formatter for LIGO contracts
settings.global.excludes = ["target" "result" "node_modules/**" ".github" ".direnv" "contracts/**" "Dockerfile" "*.toml"];
};
in {
packages = crates.packages // js-packages.packages // {default = self.packages.${system}.jstz_kernel;};
checks = crates.checks;
checks = crates.checks // {formatting = fmt.config.build.check self;};

formatter = fmt.config.build.wrapper;

# Rust dev environment
devShells.default = pkgs.mkShell {
Expand Down
Loading

0 comments on commit 0e4da48

Please sign in to comment.