From 0fc9241de12ebd7fc4cae8c964fa9ca175f342f9 Mon Sep 17 00:00:00 2001 From: Mikhail Volkhov Date: Wed, 23 Jul 2025 12:24:56 +0100 Subject: [PATCH 1/3] Add nix flake --- flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 51 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..5aa5658dab --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1753151930, + "narHash": "sha256-XSQy6wRKHhRe//iVY5lS/ZpI/Jn6crWI8fQzl647wCg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "83e677f31c84212343f4cc553bab85c2efcad60a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..4348b2ba8c --- /dev/null +++ b/flake.nix @@ -0,0 +1,51 @@ +{ + description = "openmina prerequisites"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, utils }: + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + devShell = pkgs.mkShell { + buildInputs = with pkgs; [ + rustup + rust-analyzer + libiconv # Needed for macOS for rustup + + openssl + jemalloc + protobuf + libpcap + + pkg-config + gcc + gnumake + + curl + git + sqlite + nodejs + + shellcheck + ]; + + # To use wasm-pack and other executables installed via `cargo install` + shellHook = '' + export PATH=$HOME/.cargo/bin:$PATH + ''; + + # Fix for tikv-jemalloc-sys compilation error on GNU platforms: + # The GNU version of strerror_r returns char* while POSIX returns int. + # Only set this flag on Linux/GNU systems, not needed on macOS. + CFLAGS = if pkgs.stdenv.isLinux then "-DJEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE" else ""; + JEMALLOC_SYS_WITH_CFLAGS = if pkgs.stdenv.isLinux then "-DJEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE" else ""; + }; + } + ); +} From 0c670e1ac40feb415b1257f3ac17c8e3a814b087 Mon Sep 17 00:00:00 2001 From: Mikhail Volkhov Date: Wed, 23 Jul 2025 16:19:55 +0100 Subject: [PATCH 2/3] Nix develop: add website instructions & CI --- .github/workflows/test-docs-scripts.yml | 46 +++++++++++++++++++ CHANGELOG.md | 9 ++++ website/docs/developers/getting-started.mdx | 36 +++++++++------ .../developers/scripts/setup/install-rust.sh | 5 +- .../scripts/setup/install-system-deps.sh | 3 ++ .../developers/scripts/setup/nix-develop.sh | 6 +++ 6 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 website/docs/developers/scripts/setup/nix-develop.sh diff --git a/.github/workflows/test-docs-scripts.yml b/.github/workflows/test-docs-scripts.yml index e47ccbe4e0..ac7df4a506 100644 --- a/.github/workflows/test-docs-scripts.yml +++ b/.github/workflows/test-docs-scripts.yml @@ -128,6 +128,52 @@ jobs: wasm-pack --version shellcheck --version + test-nix-setup: + name: Test Nix Setup (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'test-doc-scripts') + strategy: + matrix: + os: [ubuntu-22.04, ubuntu-24.04] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@v4 + + - name: Setup Nix Cache + uses: DeterminateSystems/magic-nix-cache-action@v2 + + - name: Test nix develop succeeds + run: | + nix develop + + - name: Test Rust installation + run: | + nix develop --command ./website/docs/developers/scripts/setup/install-rust.sh + + - name: Test WASM tools installation + run: | + # Source cargo environment first + source ~/.cargo/env + nix develop --command ./website/docs/developers/scripts/setup/install-wasm-tools.sh + + - name: Test specialised builds + run: | + nix develop --command ./website/docs/developers/scripts/setup/build-specialized.sh + + - name: Test format and lint + run: | + nix develop --command ./website/docs/developers/scripts/setup/format-and-lint.sh + + - name: Verify installations + run: | + echo "Verifying installed tools..." + nix develop --command bash -c "rustc --version && cargo --version && node --version && npm --version && protoc --version && sqlite3 --version && wasm-pack --version" + + docker-ubuntu: name: Test Docker Setup Script (${{ matrix.os }}) runs-on: ${{ matrix.os }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d65e0ec0a..b5dd25577c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Development tools**: Add shellcheck to the CI ([#1255](https://github.com/o1-labs/openmina/pull/1255)) + + ### Changed - **CI**: Generalized build jobs to support multiple platforms (Ubuntu 22.04, @@ -71,6 +73,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - bump itertools from 0.10.5 to 0.12.0 #1228 ([#1228](https://github.com/o1-labs/openmina/pull/1228)) +### Other + +- Added a `flake.nix` for building the project on nixos/using nix ([#1241](https://github.com/o1-labs/openmina/pull/1241)), + together with **documentation**: instructions for developers, + and test the installation commands in CI. + + ## [0.16.0] - 2025-04-04 ### Added diff --git a/website/docs/developers/getting-started.mdx b/website/docs/developers/getting-started.mdx index 5686c86ac7..1d4e433d58 100644 --- a/website/docs/developers/getting-started.mdx +++ b/website/docs/developers/getting-started.mdx @@ -18,6 +18,7 @@ import InstallWasmToolsSh from "!!raw-loader!./scripts/setup/install-wasm-tools. import CloneAndBuildSh from "!!raw-loader!./scripts/setup/clone-and-build.sh"; import BuildSpecializedSh from "!!raw-loader!./scripts/setup/build-specialized.sh"; import FormatAndLintSh from "!!raw-loader!./scripts/setup/format-and-lint.sh"; +import NixDevelop from "!!raw-loader!./scripts/setup/nix-develop.sh"; Welcome to OpenMina development! This guide will help you set up your development environment and build OpenMina from source. @@ -39,20 +40,7 @@ development environment and build OpenMina from source. ### Required Tools -#### 1. Rust Toolchain - -OpenMina requires both stable and nightly Rust toolchains, plus additional tools -for development: - -{InstallRustSh} - -This installs: - -- Rust 1.84 (stable) and nightly toolchains -- Required components: `rustfmt`, `clippy`, `rust-src` -- `taplo-cli`: TOML formatter required for `make format` - -#### 2. System Dependencies +#### 1. System Dependencies @@ -67,6 +55,19 @@ This installs: +#### 2. Rust Toolchain + +OpenMina requires both stable and nightly Rust toolchains, plus additional tools +for development: + +{InstallRustSh} + +This installs: + +- Rust 1.84 (stable) and nightly toolchains +- Required components: `rustfmt`, `clippy`, `rust-src` +- `taplo-cli`: TOML formatter required for `make format` + #### 3. Additional Development Tools **Node.js (for documentation and frontend):** @@ -103,6 +104,13 @@ This installs: {InstallWasmToolsSh} +#### 5. Using Nix to install dependencies automatically (alternative) + +If you're on NixOS or using nix, you can use the nix-flake provided in the repo +to install the dependencies automatically and enter the shell: + +{NixDevelop} + ## Clone and Build OpenMina ### 1. Clone the Repository and Build diff --git a/website/docs/developers/scripts/setup/install-rust.sh b/website/docs/developers/scripts/setup/install-rust.sh index 52e519b10a..15d1d25b37 100755 --- a/website/docs/developers/scripts/setup/install-rust.sh +++ b/website/docs/developers/scripts/setup/install-rust.sh @@ -1,6 +1,3 @@ -# Install rustup (Rust toolchain installer) -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - # Source cargo environment source ~/.cargo/env @@ -12,7 +9,7 @@ rustup default 1.84 rustup install nightly # Add required components for Rust 1.84 -rustup component add rustfmt clippy --toolchain 1.84 +rustup component add rustfmt clippy rust-src --toolchain 1.84 # Add required components for nightly rustup component add rustfmt clippy rust-src --toolchain nightly diff --git a/website/docs/developers/scripts/setup/install-system-deps.sh b/website/docs/developers/scripts/setup/install-system-deps.sh index 9654c7f86b..d90e7b26e1 100755 --- a/website/docs/developers/scripts/setup/install-system-deps.sh +++ b/website/docs/developers/scripts/setup/install-system-deps.sh @@ -8,3 +8,6 @@ sudo apt install -y \ git \ curl \ shellcheck + curl + +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y diff --git a/website/docs/developers/scripts/setup/nix-develop.sh b/website/docs/developers/scripts/setup/nix-develop.sh new file mode 100644 index 0000000000..c6cfab895d --- /dev/null +++ b/website/docs/developers/scripts/setup/nix-develop.sh @@ -0,0 +1,6 @@ +# This assumes the repository is cloned, and `flake.nix` is present +# Enter nix flake environment +echo "Entering nix develop flake..." +nix develop + +# Build your project afterwards using `make` as usual From 0061b5bb29fa88833f3d50bd7dfa8c40b6eae4f0 Mon Sep 17 00:00:00 2001 From: Mikhail Volkhov Date: Fri, 25 Jul 2025 15:19:27 +0100 Subject: [PATCH 3/3] Fix test-docs-scripts: missing steps line --- .github/workflows/test-docs-scripts.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-docs-scripts.yml b/.github/workflows/test-docs-scripts.yml index ac7df4a506..5d4a583a5a 100644 --- a/.github/workflows/test-docs-scripts.yml +++ b/.github/workflows/test-docs-scripts.yml @@ -224,7 +224,8 @@ jobs: test-update-ocaml-node-script: name: Test Update OCaml Node Script runs-on: [macos-latest, ubuntu-latest] - + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'test-doc-scripts') + steps: - name: Test update-ocaml-node script reproducibility run: | # Save the current script to use with the old commit state