Skip to content

Commit 0242e27

Browse files
authored
Merge pull request #1241 from o1-labs/volhovm/add-nix-flake
Add nix flake
2 parents 70a47c9 + 0061b5b commit 0242e27

File tree

8 files changed

+201
-19
lines changed

8 files changed

+201
-19
lines changed

.github/workflows/test-docs-scripts.yml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,52 @@ jobs:
128128
wasm-pack --version
129129
shellcheck --version
130130
131+
test-nix-setup:
132+
name: Test Nix Setup (${{ matrix.os }})
133+
runs-on: ${{ matrix.os }}
134+
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'test-doc-scripts')
135+
strategy:
136+
matrix:
137+
os: [ubuntu-22.04, ubuntu-24.04]
138+
139+
steps:
140+
- name: Checkout repository
141+
uses: actions/checkout@v4
142+
143+
- name: Install Nix
144+
uses: DeterminateSystems/nix-installer-action@v4
145+
146+
- name: Setup Nix Cache
147+
uses: DeterminateSystems/magic-nix-cache-action@v2
148+
149+
- name: Test nix develop succeeds
150+
run: |
151+
nix develop
152+
153+
- name: Test Rust installation
154+
run: |
155+
nix develop --command ./website/docs/developers/scripts/setup/install-rust.sh
156+
157+
- name: Test WASM tools installation
158+
run: |
159+
# Source cargo environment first
160+
source ~/.cargo/env
161+
nix develop --command ./website/docs/developers/scripts/setup/install-wasm-tools.sh
162+
163+
- name: Test specialised builds
164+
run: |
165+
nix develop --command ./website/docs/developers/scripts/setup/build-specialized.sh
166+
167+
- name: Test format and lint
168+
run: |
169+
nix develop --command ./website/docs/developers/scripts/setup/format-and-lint.sh
170+
171+
- name: Verify installations
172+
run: |
173+
echo "Verifying installed tools..."
174+
nix develop --command bash -c "rustc --version && cargo --version && node --version && npm --version && protoc --version && sqlite3 --version && wasm-pack --version"
175+
176+
131177
docker-ubuntu:
132178
name: Test Docker Setup Script (${{ matrix.os }})
133179
runs-on: ${{ matrix.os }}
@@ -178,7 +224,8 @@ jobs:
178224
test-update-ocaml-node-script:
179225
name: Test Update OCaml Node Script
180226
runs-on: [macos-latest, ubuntu-latest]
181-
227+
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'test-doc-scripts')
228+
steps:
182229
- name: Test update-ocaml-node script reproducibility
183230
run: |
184231
# Save the current script to use with the old commit state

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4141
- **Development tools**: Add shellcheck to the CI
4242
([#1255](https://github.com/o1-labs/openmina/pull/1255))
4343

44+
45+
4446
### Changed
4547

4648
- **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
7173
- bump itertools from 0.10.5 to 0.12.0 #1228
7274
([#1228](https://github.com/o1-labs/openmina/pull/1228))
7375

76+
### Other
77+
78+
- Added a `flake.nix` for building the project on nixos/using nix ([#1241](https://github.com/o1-labs/openmina/pull/1241)),
79+
together with **documentation**: instructions for developers,
80+
and test the installation commands in CI.
81+
82+
7483
## [0.16.0] - 2025-04-04
7584

7685
### Added

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
description = "openmina prerequisites";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6+
utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, utils }:
10+
utils.lib.eachDefaultSystem (system:
11+
let
12+
pkgs = import nixpkgs { inherit system; };
13+
in
14+
{
15+
devShell = pkgs.mkShell {
16+
buildInputs = with pkgs; [
17+
rustup
18+
rust-analyzer
19+
libiconv # Needed for macOS for rustup
20+
21+
openssl
22+
jemalloc
23+
protobuf
24+
libpcap
25+
26+
pkg-config
27+
gcc
28+
gnumake
29+
30+
curl
31+
git
32+
sqlite
33+
nodejs
34+
35+
shellcheck
36+
];
37+
38+
# To use wasm-pack and other executables installed via `cargo install`
39+
shellHook = ''
40+
export PATH=$HOME/.cargo/bin:$PATH
41+
'';
42+
43+
# Fix for tikv-jemalloc-sys compilation error on GNU platforms:
44+
# The GNU version of strerror_r returns char* while POSIX returns int.
45+
# Only set this flag on Linux/GNU systems, not needed on macOS.
46+
CFLAGS = if pkgs.stdenv.isLinux then "-DJEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE" else "";
47+
JEMALLOC_SYS_WITH_CFLAGS = if pkgs.stdenv.isLinux then "-DJEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE" else "";
48+
};
49+
}
50+
);
51+
}

website/docs/developers/getting-started.mdx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import InstallWasmToolsSh from "!!raw-loader!./scripts/setup/install-wasm-tools.
1818
import CloneAndBuildSh from "!!raw-loader!./scripts/setup/clone-and-build.sh";
1919
import BuildSpecializedSh from "!!raw-loader!./scripts/setup/build-specialized.sh";
2020
import FormatAndLintSh from "!!raw-loader!./scripts/setup/format-and-lint.sh";
21+
import NixDevelop from "!!raw-loader!./scripts/setup/nix-develop.sh";
2122

2223
Welcome to OpenMina development! This guide will help you set up your
2324
development environment and build OpenMina from source.
@@ -39,20 +40,7 @@ development environment and build OpenMina from source.
3940

4041
### Required Tools
4142

42-
#### 1. Rust Toolchain
43-
44-
OpenMina requires both stable and nightly Rust toolchains, plus additional tools
45-
for development:
46-
47-
<CodeBlock language="bash">{InstallRustSh}</CodeBlock>
48-
49-
This installs:
50-
51-
- Rust 1.84 (stable) and nightly toolchains
52-
- Required components: `rustfmt`, `clippy`, `rust-src`
53-
- `taplo-cli`: TOML formatter required for `make format`
54-
55-
#### 2. System Dependencies
43+
#### 1. System Dependencies
5644

5745
<Tabs groupId="operating-systems">
5846
<TabItem value="linux" label="Linux (Ubuntu/Debian)">
@@ -67,6 +55,19 @@ This installs:
6755
</TabItem>
6856
</Tabs>
6957

58+
#### 2. Rust Toolchain
59+
60+
OpenMina requires both stable and nightly Rust toolchains, plus additional tools
61+
for development:
62+
63+
<CodeBlock language="bash">{InstallRustSh}</CodeBlock>
64+
65+
This installs:
66+
67+
- Rust 1.84 (stable) and nightly toolchains
68+
- Required components: `rustfmt`, `clippy`, `rust-src`
69+
- `taplo-cli`: TOML formatter required for `make format`
70+
7071
#### 3. Additional Development Tools
7172

7273
**Node.js (for documentation and frontend):**
@@ -103,6 +104,13 @@ This installs:
103104

104105
<CodeBlock language="bash">{InstallWasmToolsSh}</CodeBlock>
105106

107+
#### 5. Using Nix to install dependencies automatically (alternative)
108+
109+
If you're on NixOS or using nix, you can use the nix-flake provided in the repo
110+
to install the dependencies automatically and enter the shell:
111+
112+
<CodeBlock language="bash">{NixDevelop}</CodeBlock>
113+
106114
## Clone and Build OpenMina
107115

108116
### 1. Clone the Repository and Build

website/docs/developers/scripts/setup/install-rust.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Install rustup (Rust toolchain installer)
2-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
3-
41
# Source cargo environment
52
source ~/.cargo/env
63

@@ -12,7 +9,7 @@ rustup default 1.84
129
rustup install nightly
1310

1411
# Add required components for Rust 1.84
15-
rustup component add rustfmt clippy --toolchain 1.84
12+
rustup component add rustfmt clippy rust-src --toolchain 1.84
1613

1714
# Add required components for nightly
1815
rustup component add rustfmt clippy rust-src --toolchain nightly

website/docs/developers/scripts/setup/install-system-deps.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ sudo apt install -y \
88
git \
99
curl \
1010
shellcheck
11+
curl
12+
13+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This assumes the repository is cloned, and `flake.nix` is present
2+
# Enter nix flake environment
3+
echo "Entering nix develop flake..."
4+
nix develop
5+
6+
# Build your project afterwards using `make` as usual

0 commit comments

Comments
 (0)