Merge pull request #9 from plurigrid/babashka

Cleaned up shell.nix by removing bash commands and replacing them with just recipes
This commit is contained in:
ajasibley 2023-05-26 03:11:41 -07:00 committed by GitHub
commit 3abc987f2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 280 additions and 106 deletions

View file

@ -1,7 +1,7 @@
[package] [package]
name = "nexus" name = "nexus"
version = "0.0.0" version = "0.0.0"
edition = "2033" edition = "2021"
[dependencies] [dependencies]
c2pa = "0.21.0" c2pa = "0.21.0"

126
README.md
View file

@ -1,46 +1,130 @@
Here is the complete set of instructions: # Nexus
1. Clone the Nexus repository Welcome to the Nexus! This README will guide you through setting up your development environment and getting started with the project.
## Prerequisites
Before you begin, make sure you have the following installed on your system:
- [Nix](https://nixos.org)
- [Git](https://git-scm.com/)
- [Rust](https://www.rust-lang.org/)
- wasm32-unknown-unknown target
- [OpenSSL 1.1](https://www.openssl.org/)
- [Cosmoonic](https://cosmonic.com)
## Getting Started
1. Clone the repository and navigate to the project directory:
```bash ```bash
git clone https://github.com/nexus git clone https://github.com/plurigrid/nexus.git
cd nexus
``` ```
2. Enter the Nix environment 2. Start nix shell and run the following command to install all required dependencies:
```bash ```bash
nix-shell nix-shell
make all
``` ```
This will activate the flox environment defined in the nexus/flox.nix file. This environment has all the necessary dependencies installed to build and run your project. This will automatically check for and install Rust, wasm32-unknown-unknown target, OpenSSL 1.1, and Cosmo CLI if they are not already installed on your system.
3. Run cosmo 3. Create a new actor using Cosmo CLI:
Now you can use cosmo launch your project:
```bash ```bash
cosmo cosmo new actor <your_project_name>
``` ```
**If this is your first run of cosmo**, it will automatically start the tutorial. Replace `<your_project_name>` with your desired project name.
**If not your first run**, you can start the tutorial with: 4. Navigate to your newly created project directory:
```bash ```bash
cosmo tutorial hello cd <your_project_name>
``` ```
4. Explaining the components 5. Edit `src/lib.rs` file in your favorite text editor.
- flox is a tool for managing declarative Nix-based environments. The nexus/flox.nix file defines an environment with all the dependencies for your project. The default file content looks like this:
- cosmo is a tool for building and deploying WebAssembly actors. You use it to build and launch your actor from within the flox environment.
- Nix is a purely functional package manager that is used by flox to define environments.
5. Installation (if not already completed) ```rust
use wasmbus_rpc::actor::prelude::*;
use wasmcloud_interface_httpserver::{HttpRequest, HttpResponse, HttpServer, HttpServerReceiver};
Follow the instructions to install flox and configure your system to use it. This will install the necessary tools to get started with the Nexus project. #[derive(Debug, Default, Actor, HealthResponder)]
#[services(Actor, HttpServer)]
struct <your_project_name>Actor {}
- Install Nix (if not already installed) /// Implementation of the HttpServer capability contract
- Install flox #[async_trait]
impl HttpServer for <your_project_name>Actor {
async fn handle_request(&self, _ctx: &Context, _req: &HttpRequest) -> RpcResult<HttpResponse> {
Ok(HttpResponse::ok("message"))
}
}
```
You now have all the necessary components installed and configured to build and run the Nexus project! Let me know if you have any other questions. You can modify the file to accommodate more text like this:
```rust
use wasmbus_rpc::actor::prelude::*;
use wasmcloud_interface_httpserver::{HttpRequest, HttpResponse, HttpServer, HttpServerReceiver};
#[derive(Debug, Default, Actor, HealthResponder)]
#[services(Actor, HttpServer)]
struct <your_project_name>Actor {}
/// Implementation of the HTTP server capability
#[async_trait]
impl HttpServer for <your_project_name>Actor {
async fn handle_request(&self, _ctx: &Context, _req: &HttpRequest) -> RpcResult<HttpResponse> {
let message: &str = r#"message"#;
Ok(HttpResponse::ok(message))
}
}
```
## Launching the Project
1. Login to Cosmonic:
```bash
cosmo login
```
2. Build and sign your actor:
```bash
cosmo build
```
3. Start your wasmCloud host:
```bash
cosmo up
```
4. Launch the actor using Cosmo CLI:
```bash
cosmo launch
```
5. Navigate to [Cosmonic App](https://app.cosmonic.com) and sign in with your account.
6. In the Logic view, you should see the new actor you just launched.
7. To make your actor accessible from the web, launch a new provider for an HTTP server with the following OCI URL: `cosmonic.azurecr.io/httpserver_wormhole:0.5.3`. Give the link a name, and note that the HTTP server must be launched on a Cosmonic Manager resource.
8. Once the HTTP server is launched, link it to your actor.
9. Launch a wormhole and connect it to your actor link (the HTTP server and the actor).
10. Your actor should now be accessible at the domain of the wormhole followed by `.cosmonic.app`. For example: `https://white-morning-5041.cosmonic.app`.
Now you can access your project from any web browser using the provided URL!
You're all set! You can start building your project and explore the Nexus repository. Happy coding!

41
justfile Normal file
View file

@ -0,0 +1,41 @@
scripts_dir := "scripts"
# Check if Nix is installed, if not install it based on the platform
install-nix:
. {{scripts_dir}}/install_nix.sh; \
# Check if Rust is installed, if not install it
install-rust:
@if ! command -v rustc &> /dev/null; then \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh; \
. {{scripts_dir}}/update_source.sh; \
fi
# Check if wasm32-unknown-unknown target is installed, if not install it
install-wasm-target:
@if ! rustup target list --installed | grep -q "wasm32-unknown-unknown"; then \
rustup target add wasm32-unknown-unknown; \
. {{scripts_dir}}/update_source.sh; \
fi
# Check if OpenSSL 1.1 is installed
install-openssl:
@if ! (command -v openssl &> /dev/null && openssl version | grep -q "OpenSSL 1.1"); then \
. {{scripts_dir}}/install_openssl.sh; \
. {{scripts_dir}}/update_source.sh; \
fi
# Check if cosmo is installed, if not install it
install-cosmo:
@if ! command -v cosmo &> /dev/null; then \
bash -c "$(curl -fsSL https://cosmonic.sh/install.sh)"; \
. {{scripts_dir}}/update_path.sh; \
. {{scripts_dir}}/update_source.sh; \
fi
# Print a message to restart the shell
restart-shell-message:
@echo
@echo "\033[1;33mPlease restart your shell to refresh the source before launching Cosmonic.\033[0m"
all: install-nix install-rust install-wasm-target install-openssl install-cosmo restart-shell-message

36
scripts/install_nix.sh Normal file
View file

@ -0,0 +1,36 @@
#!/bin/bash
# Check if Nix is installed
if ! command -v nix --help >/dev/null 2>&1; then
# Delete problematic backup files for bash and zsh if they exist
if [ -f "/etc/bash.bashrc.backup-before-nix" ]; then
sudo rm -f /etc/bash.bashrc.backup-before-nix
fi
if [ -f "/etc/bashrc.backup-before-nix" ]; then
sudo rm -f /etc/bashrc.backup-before-nix
fi
if [ -f "/etc/zshrc.backup-before-nix" ]; then
sudo rm -f /etc/zshrc.backup-before-nix
fi
# Determine the platform (Linux or macOS)
case `uname` in
Linux*)
echo "Error: Nix package manager is not installed. Installing Nix for Linux..."
curl -L https://nixos.org/nix/install | sh --daemon -
;;
Darwin*)
echo "Error: Nix package manager is not installed. Installing Nix for macOS..."
curl -L https://nixos.org/nix/install | sh --darwin-use-unencrypted-nix-store-volume -
;;
*)
echo "Unsupported platform for Nix installation"
exit 1;
;;
esac
else
echo "Nix package manager is already installed."
fi

View file

@ -0,0 +1,55 @@
#!/bin/bash
# Check if OpenSSL 1.1 is installed
if ! (command -v openssl &> /dev/null && openssl version | grep -q "OpenSSL 1.1"); then
# Check the architecture and install OpenSSL 1.1 if needed
if [[ $(uname -m) == "arm64" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
# MacOS M1 installation
if ! command -v brew &> /dev/null; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> "$HOME/.zprofile"
eval "$(/opt/homebrew/bin/brew shellenv)"
echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc
fi
export PATH="/opt/homebrew/bin:$PATH"
brew install openssl@1.1
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Check for Debian-based system
if grep -qi 'debian' /etc/os-release; then
# Ubuntu ARM installation
apt update && apt install curl -y
curl -s https://packagecloud.io/install/repositories/wasmcloud/core/script.deb.sh | bash
apt install wash
curl -fLO http://ftp.us.debian.org/debian/pool/main/o/openssl/libssl1.1_1.1.1n-0+deb11u4_arm64.deb
dpkg -i libssl1.1_1.1.1n-0+deb11u4_arm64.deb
else
echo "This script is designed for Debian-based systems only."
exit 1
fi
else
echo "Unsupported system type."
exit 1
fi
else
echo "This script is designed for arm64 systems only."
exit 1
fi
fi

20
scripts/update_path.sh Normal file
View file

@ -0,0 +1,20 @@
#!/bin/bash
# Get the current shell name
current_shell="$(basename "$SHELL")"
# Update the corresponding configuration file based on the current shell
if [[ "$current_shell" == "bash" ]]; then
cat >> "${HOME}/.bashrc" <<EOF
export PATH="/Users/test/.cosmo/bin:\${PATH}"
EOF
source "${HOME}/.bashrc"
elif [[ "$current_shell" == "zsh" ]]; then
cat >> "${HOME}/.zshrc" <<EOF
export PATH="/Users/test/.cosmo/bin:\${PATH}"
EOF
source "${HOME}/.zshrc"
else
echo "Unsupported shell: $current_shell"
exit 1
fi

22
scripts/update_source.sh Normal file
View file

@ -0,0 +1,22 @@
#!/bin/bash
# Detect the current shell
current_shell=$(basename "$SHELL")
# Run the appropriate command based on the detected shell
case $current_shell in
bash)
source ~/.bashrc || source ~/.bash_profile
;;
zsh)
if [ -f ~/.zshrc ]; then
source ~/.zshrc
else
touch ~/.zshrc
source ~/.zshrc
fi
;;
*)
exit 1
;;
esac

View file

@ -6,93 +6,9 @@ pkgs.mkShell {
cargo cargo
tree tree
poetry poetry
openssl_1_1
vespa-cli vespa-cli
]; ];
shellHook = '' shellHook = ''
# Check if Rust is installed, if not install it
if ! command -v rustc &> /dev/null; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
fi
# Check if wasm32-unknown-unknown target is installed, if not install it
if ! rustup target list --installed | grep -q "wasm32-unknown-unknown"; then
rustup target add wasm32-unknown-unknown
fi
# Check if OpenSSL 1.1 is installed
if ! (command -v openssl &> /dev/null && openssl version | grep -q "OpenSSL 1.1"); then
# Check the architecture and install OpenSSL 1.1 if needed
if [[ $(uname -m) == "arm64" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
# MacOS M1 installation
if ! command -v brew &> /dev/null; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
export PATH="/opt/homebrew/bin:$PATH"
brew install openssl@1.1
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Check for Debian-based system
if grep -qi 'debian' /etc/os-release; then
# Ubuntu ARM installation
apt update && apt install curl -y
curl -s https://packagecloud.io/install/repositories/wasmcloud/core/script.deb.sh | bash
apt install wash
curl -fLO http://ftp.us.debian.org/debian/pool/main/o/openssl/libssl1.1_1.1.1n-0+deb11u4_arm64.deb
dpkg -i libssl1.1_1.1.1n-0+deb11u4_arm64.deb
else
echo "This script is designed for Debian-based systems only."
exit 1
fi
else
echo "Unsupported system type."
exit 1
fi
else
echo "This script is designed for arm64 systems only."
exit 1
fi
fi
# Check if cosmo is installed, if not install it
if ! command -v cosmo &> /dev/null; then
bash -c "$(curl -fsSL https://cosmonic.sh/install.sh)"
# Get the current shell name
current_shell="$(basename ${builtins.getEnv "SHELL"})"
# Update the corresponding configuration file based on the current shell
if [[ "$current_shell" == "bash" ]]; then
cat >> "${builtins.getEnv "HOME"}/.bashrc" <<EOF
export PATH="/Users/test/.cosmo/bin:\${builtins.getEnv "PATH"}"
EOF
source "${builtins.getEnv "HOME"}/.bashrc"
elif [[ "$current_shell" == "zsh" ]]; then
cat >> "${builtins.getEnv "HOME"}/.zshrc" <<EOF
export PATH="/Users/test/.cosmo/bin:\${builtins.getEnv "PATH"}"
EOF
source "${builtins.getEnv "HOME"}/.zshrc"
else
echo "Unsupported shell: $current_shell"
exit 1
fi
fi
cat <<'EOF' cat <<'EOF'
.-. .-.
`-' `-'