Skip to content

Commit

Permalink
fix(nix): use unified rust package including risc0
Browse files Browse the repository at this point in the history
  • Loading branch information
cfcosta committed Jul 21, 2024
1 parent 51f1c5b commit 9fdc0e8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
watch_file nix/*.nix

use flake

watch_file nix/**/*.nix
24 changes: 9 additions & 15 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ inputs: final: prev:
let
inherit (builtins)
attrNames
attrValues
elemAt
listToAttrs
match
Expand All @@ -18,17 +17,13 @@ let
}) (attrNames (readDir ./packages))
);

risc0Platform = final.makeRustPlatform {
rustc = packages.risc0-rust;
cargo = packages.risc0-rust;
};
rust = final.symlinkJoin {
inherit (final.rust-bin.nightly.latest.complete) meta;

rust = final.rust-bin.nightly.latest.complete.override {
extensions = [
"rust-src"
"clippy"
"rustfmt"
"rust-analyzer"
name = "mugraph-rustc";
paths = [
(final.rust-bin.nightly.latest.complete)
packages.risc0-rust
];
};

Expand All @@ -41,16 +36,18 @@ let
name = "mu-shell";

packages = [
rust

packages.cargo-risczero
packages.r0vm
packages.risc0-rust
packages.rustup-mock

final.cargo-nextest
final.cargo-watch
];

RISC0_DEV_MODE = 1;
RISC0_RUST_SRC = "${rust}/lib/rustlib/src/rust";
};
in
{
Expand All @@ -59,11 +56,8 @@ in
devShells
inputs
packages
risc0Platform
rust

rustPlatform

;
};
}
2 changes: 1 addition & 1 deletion nix/packages/mugraph-node.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let
inherit (lib) makeBinPath;
in
mugraph.risc0Platform.buildRustPackage {
mugraph.rustPlatform.buildRustPackage {
pname = "mugraph-node";
version = "0.0.1";
src = ../..;
Expand Down
12 changes: 5 additions & 7 deletions nix/packages/risc0-rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
let
inherit (stdenv) isDarwin mkDerivation;

tarballFile =
if isDarwin then
"rust-toolchain-aarch64-apple-darwin.tar.gz"
else
"rust-toolchain-x86_64-unknown-linux-gnu.tar.gz";
arch = if isDarwin then "aarch64-apple-darwin" else "x86_64-unknown-linux-gnu";
tarballChecksum =
if isDarwin then
"sha256:0zx3lky6jh572gzvdfb43r3f4g62iwpj4i0zfv4vw343v8wk6jxv"
Expand All @@ -22,7 +18,7 @@ let
baseUrl = "https://github.com/risc0/rust/releases/download/r0.1.78.0";

risc0-rust-tarball = fetchurl {
url = "${baseUrl}/${tarballFile}";
url = "${baseUrl}/rust-toolchain-${arch}.tar.gz";
sha256 = tarballChecksum;
};
in
Expand All @@ -39,7 +35,9 @@ mkDerivation {
mkdir -p $out
cd $out
tar xzf ${risc0-rust-tarball}
chmod +x bin/*
rm -rf bin lib/*.dylib lib/rustlib/${arch}
runHook postInstall
runHook autoPatchelfHook
'';
Expand Down
2 changes: 1 addition & 1 deletion nix/packages/rustup-mock.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ writeShellApplication {
printf "risc0\n"
elif [[ "$1" = "+risc0" ]]
then
printf "${mugraph.packages.risc0-rust}/bin/rustc"
printf "${mugraph.rust}/bin/rustc"
fi
'';
}
12 changes: 3 additions & 9 deletions node/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// These constants represent the RISC-V ELF and the image ID generated by risc0-build.
// The ELF is used for proving and the ID is used for verification.
use methods::{
CIRCUITS_ELF, CIRCUITS_ID
};
use mugraph_circuits::{CIRCUITS_ELF, CIRCUITS_ID};
use risc0_zkvm::{default_prover, ExecutorEnv};

fn main() {
Expand Down Expand Up @@ -36,9 +34,7 @@ fn main() {

// Proof information by proving the specified ELF binary.
// This struct contains the receipt along with statistics about execution of the guest
let prove_info = prover
.prove(env, CIRCUITS_ELF)
.unwrap();
let prove_info = prover.prove(env, CIRCUITS_ELF).unwrap();

// extract the receipt.
let receipt = prove_info.receipt;
Expand All @@ -50,7 +46,5 @@ fn main() {

// The receipt was verified at the end of proving, but the below code is an
// example of how someone else could verify this receipt.
receipt
.verify(CIRCUITS_ID)
.unwrap();
receipt.verify(CIRCUITS_ID).unwrap();
}

0 comments on commit 9fdc0e8

Please sign in to comment.