diff --git a/flake.nix b/flake.nix index 5a47e4c49a..750504f2ef 100644 --- a/flake.nix +++ b/flake.nix @@ -16,9 +16,9 @@ outputs = { self, nixpkgs, flake-utils, ... }@inputs: flake-utils.lib.eachDefaultSystem (system: let - pkgs= (nixpkgs.legacyPackages."${system}".extend + pkgs = (nixpkgs.legacyPackages."${system}".extend (import inputs.nixpkgs-mozilla) - ).extend inputs.mina.overlays.rust; + ).extend inputs.mina.overlays.rust; dune-nix = inputs.dune-nix.lib.${system}; describe-dune = inputs.describe-dune.defaultPackage.${system}; dune-description = pkgs.stdenv.mkDerivation { @@ -40,19 +40,22 @@ ''; }; desc = builtins.fromJSON (builtins.readFile dune-description); - allOcamlDeps_ = pkgs.lib.concatMap (duneSpec: - pkgs.lib.concatMap (unitSpec: unitSpec.deps or [ ]) - (duneSpec.units or [ ])) desc; + allOcamlDeps_ = pkgs.lib.concatMap + (duneSpec: + pkgs.lib.concatMap (unitSpec: unitSpec.deps or [ ]) + (duneSpec.units or [ ])) + desc; allOcamlDeps = builtins.map (d: builtins.head (pkgs.lib.splitString "." d)) - allOcamlDeps_; + allOcamlDeps_; mina = inputs.mina.packages."${system}"; minaDeps_ = builtins.intersectAttrs (pkgs.lib.genAttrs allOcamlDeps (_: { })) - mina.info.raw.deps.units; + mina.info.raw.deps.units; minaDeps = builtins.attrNames (builtins.foldl' (acc: pkg: acc // dune-nix.deps.packageDeps minaDeps_ "pkgs" pkg) - minaDeps_ (builtins.attrNames minaDeps_)); + minaDeps_ + (builtins.attrNames minaDeps_)); commonOverrides = { DUNE_PROFILE = "dev"; buildInputs = [ mina.base-libs ] ++ mina.external-libs @@ -61,10 +64,15 @@ info = dune-nix.info desc; allDeps = dune-nix.allDeps info; noTestSkipping = _: false; - prj_ = dune-nix.outputs' commonOverrides (pkgs.lib.fileset.toSource { - root = ./src/bindings; - fileset = ./src/bindings/ocaml; - }) allDeps info noTestSkipping prj; + prj_ = dune-nix.outputs' commonOverrides + (pkgs.lib.fileset.toSource { + root = ./src/bindings; + fileset = ./src/bindings/ocaml; + }) + allDeps + info + noTestSkipping + prj; prj = prj_ // { pkgs = prj_.pkgs // { __ocaml-js__ = prj_.pkgs.__ocaml-js__.overrideAttrs { @@ -77,48 +85,53 @@ }; rust-channel = ((pkgs.rustChannelOf - { channel = "nightly"; + { + channel = "nightly"; date = "2023-09-01"; sha256 = "sha256-zek9JAnRaoX8V0U2Y5ssXVe9tvoQ0ERGXfUCUGYdrMA="; }).rust.override - { targets = ["wasm32-unknown-unknown" "x86_64-unknown-linux-gnu" ]; - extensions = [ "rust-src" ]; - }); + { + targets = [ "wasm32-unknown-unknown" "x86_64-unknown-linux-gnu" ]; + extensions = [ "rust-src" ]; + }); rust-platform = pkgs.makeRustPlatform - { cargo = rust-channel; - rustc = rust-channel; - }; + { + cargo = rust-channel; + rustc = rust-channel; + }; bindings-pkgs = with pkgs; - [ nodejs - nodePackages.npm - typescript - nodePackages.typescript-language-server + [ + nodejs + nodePackages.npm + typescript + nodePackages.typescript-language-server - #Rustup doesn't allow local toolchains to contain 'nightly' in the name - #so the toolchain is linked with the name nix and rustup is wrapped in a shellscript - #which calls the nix toolchain instead of the nightly one - (writeShellApplication - { name = "rustup"; - text = + #Rustup doesn't allow local toolchains to contain 'nightly' in the name + #so the toolchain is linked with the name nix and rustup is wrapped in a shellscript + #which calls the nix toolchain instead of the nightly one + (writeShellApplication + { + name = "rustup"; + text = '' - if [ "$1" = run ] && { [ "$2" = nightly-2023-09-01 ] || [ "$2" = 1.72-x86_64-unknowl-linux-gnu ]; } - then - echo using nix toolchain - ${rustup}/bin/rustup run nix "''${@:3}" - else - echo using plain rustup "$@" - ${rustup}/bin/rustup "$@" - fi + if [ "$1" = run ] && { [ "$2" = nightly-2023-09-01 ] || [ "$2" = 1.72-x86_64-unknowl-linux-gnu ]; } + then + echo using nix toolchain + ${rustup}/bin/rustup run nix "''${@:3}" + else + echo using plain rustup "$@" + ${rustup}/bin/rustup "$@" + fi ''; - } - ) - rustup - wasm-pack - binaryen # provides wasm-opt + } + ) + rustup + wasm-pack + binaryen # provides wasm-opt - dune_3 - ] ++ commonOverrides.buildInputs ; + dune_3 + ] ++ commonOverrides.buildInputs; inherit (nixpkgs) lib; # All the submodules required by .gitmodules @@ -127,72 +140,79 @@ (lib.splitString "\n" (builtins.readFile ./.gitmodules)))); # Warn about missing submodules - requireSubmodules = let - ref = r: "[34;1m${r}[31;1m"; - command = c: "[37;1m${c}[31;1m"; - in lib.warnIf (!builtins.all (x: x) - (map (x: builtins.pathExists ./${x} && builtins.readDir ./${x} != { }) - submodules)) '' - Some submodules are missing, you may get errors. Consider one of the following: - - run ${command "./pin.sh"} and use "${ - ref "o1js" - }" flake ref, e.g. ${command "nix develop o1js"} or ${ - command "nix build o1js" - }; - - use "${ref "git+file://$PWD?submodules=1"}"; - - use "${ - ref "git+https://github.com/o1-labs/o1js?submodules=1" - }"; - - use non-flake commands like ${command "nix-build"} and ${ - command "nix-shell" - }. - ''; + requireSubmodules = + let + ref = r: "[34;1m${r}[31;1m"; + command = c: "[37;1m${c}[31;1m"; + in + lib.warnIf + ( + !builtins.all (x: x) + (map (x: builtins.pathExists ./${x} && builtins.readDir ./${x} != { }) + submodules) + ) '' + Some submodules are missing, you may get errors. Consider one of the following: + - run ${command "./pin.sh"} and use "${ + ref "o1js" + }" flake ref, e.g. ${command "nix develop o1js"} or ${ + command "nix build o1js" + }; + - use "${ref "git+file://$PWD?submodules=1"}"; + - use "${ + ref "git+https://github.com/o1-labs/o1js?submodules=1" + }"; + - use non-flake commands like ${command "nix-build"} and ${ + command "nix-shell" + }. + ''; - o1js-npm-deps = pkgs.buildNpmPackage - { name = "o1js"; - src = with pkgs.lib.fileset; - (toSource { - root = ./.; - fileset = unions [ - ./package.json - ./package-lock.json - ]; - }); - # If you get ERROR: npmDepsHash is out of date - # you can update the hash with `nix run o1js#update-npm-deps`. - # Failing that you can remove the hash from ./npmDepsHash and try again - # which should get an error message with the correct hash - # You can also just push and CI should suggest a fix which updates the hash - npmDepsHash = builtins.readFile ./npmDepsHash; - # The prepack script runs the build script, which we'd rather do in the build phase. - npmPackFlags = [ "--ignore-scripts" ]; - dontNpmBuild = true; - installPhase = '' - runHook preInstall + o1js-npm-deps = pkgs.buildNpmPackage + { + name = "o1js"; + src = with pkgs.lib.fileset; + (toSource { + root = ./.; + fileset = unions [ + ./package.json + ./package-lock.json + ]; + }); + # If you get ERROR: npmDepsHash is out of date + # you can update the hash with `nix run o1js#update-npm-deps`. + # Failing that you can remove the hash from ./npmDepsHash and try again + # which should get an error message with the correct hash + # You can also just push and CI should suggest a fix which updates the hash + npmDepsHash = builtins.readFile ./npmDepsHash; + # The prepack script runs the build script, which we'd rather do in the build phase. + npmPackFlags = [ "--ignore-scripts" ]; + dontNpmBuild = true; + installPhase = '' + runHook preInstall - mkdir -p $out/lib - cp -r node_modules $out/lib + mkdir -p $out/lib + cp -r node_modules $out/lib - runHook postInstall - ''; - }; - test-vectors = rust-platform.buildRustPackage { - src = pkgs.lib.sourceByRegex ./src/mina/src - [ - "^lib(/crypto(/proof-systems(/.*)?)?)?$" - ]; - sourceRoot = "source/lib/crypto/proof-systems/poseidon/export_test_vectors"; - patchPhase = - '' - cp ${./src/mina/src/lib/crypto/proof-systems/Cargo.lock} . + runHook postInstall ''; - name = "export_test_vectors"; - version = "0.1.0"; - cargoSha256 = ""; - CARGO_TARGET_DIR = "./target"; - cargoLock = { lockFile = ./src/mina/src/lib/crypto/proof-systems/Cargo.lock ; }; }; - in { + test-vectors = rust-platform.buildRustPackage { + src = pkgs.lib.sourceByRegex ./src/mina/src + [ + "^lib(/crypto(/proof-systems(/.*)?)?)?$" + ]; + sourceRoot = "source/lib/crypto/proof-systems/poseidon/export_test_vectors"; + patchPhase = + '' + cp ${./src/mina/src/lib/crypto/proof-systems/Cargo.lock} . + ''; + name = "export_test_vectors"; + version = "0.1.0"; + cargoSha256 = ""; + CARGO_TARGET_DIR = "./target"; + cargoLock = { lockFile = ./src/mina/src/lib/crypto/proof-systems/Cargo.lock; }; + }; + in + { formatter = pkgs.nixfmt; inherit mina; devShells = { @@ -200,11 +220,11 @@ mina-shell = requireSubmodules inputs.mina.devShells."${system}".with-lsp; default = requireSubmodules (pkgs.mkShell { shellHook = - '' - RUSTUP_HOME=$(pwd)/.rustup - export RUSTUP_HOME - rustup toolchain link nix ${rust-channel} - ''; + '' + RUSTUP_HOME=$(pwd)/.rustup + export RUSTUP_HOME + rustup toolchain link nix ${rust-channel} + ''; packages = bindings-pkgs; }); @@ -217,29 +237,29 @@ o1js-bindings = pkgs.stdenv.mkDerivation { name = "o1js_bindings"; src = with pkgs.lib.fileset; - (toSource { - root = ./.; - fileset = unions [ - ./src/mina - ./src/bindings/scripts - ./src/bindings/js - ./src/bindings/crypto - ./src/bindings/lib - ./src/bindings/mina-transaction/gen/dune - (fileFilter (file: file.hasExt "js") ./src/bindings/mina-transaction) - ./src/bindings/ocaml/lib - ./src/bindings/ocaml/dune - ./src/bindings/ocaml/dune-project - (fileFilter (file: file.hasExt "ml") ./src/bindings/ocaml) - ./package.json - ./package-lock.json - ./src/bindings/ocaml/jsoo_exports - ./dune-project - ./.prettierrc.cjs - ./src/build - ./src/snarky.d.ts - ]; - }); + (toSource { + root = ./.; + fileset = unions [ + ./src/mina + ./src/bindings/scripts + ./src/bindings/js + ./src/bindings/crypto + ./src/bindings/lib + ./src/bindings/mina-transaction/gen/dune + (fileFilter (file: file.hasExt "js") ./src/bindings/mina-transaction) + ./src/bindings/ocaml/lib + ./src/bindings/ocaml/dune + ./src/bindings/ocaml/dune-project + (fileFilter (file: file.hasExt "ml") ./src/bindings/ocaml) + ./package.json + ./package-lock.json + ./src/bindings/ocaml/jsoo_exports + ./dune-project + ./.prettierrc.cjs + ./src/build + ./src/snarky.d.ts + ]; + }); inherit (inputs.mina.devShells."${system}".default) PLONK_WASM_NODEJS PLONK_WASM_WEB @@ -254,29 +274,29 @@ SKIP_MINA_COMMIT = true; JUST_BINDINGS = true; patchPhase = '' - patchShebangs ./src/bindings/scripts/ - patchShebangs ./src/bindings/crypto/test-vectors/ + patchShebangs ./src/bindings/scripts/ + patchShebangs ./src/bindings/crypto/test-vectors/ ''; buildPhase = - '' - RUSTUP_HOME=$(pwd)/.rustup - export RUSTUP_HOME - rustup toolchain link nix ${rust-channel} - cp -r ${o1js-npm-deps}/lib/node_modules/ . + '' + RUSTUP_HOME=$(pwd)/.rustup + export RUSTUP_HOME + rustup toolchain link nix ${rust-channel} + cp -r ${o1js-npm-deps}/lib/node_modules/ . - mkdir -p src/bindings/compiled/node_bindings - echo '// this file exists to prevent TS from type-checking `o1js_node.bc.cjs`' \ - > src/bindings/compiled/node_bindings/o1js_node.bc.d.cts + mkdir -p src/bindings/compiled/node_bindings + echo '// this file exists to prevent TS from type-checking `o1js_node.bc.cjs`' \ + > src/bindings/compiled/node_bindings/o1js_node.bc.d.cts - npm run build:update-bindings + npm run build:update-bindings - mkdir -p $out/mina-transaction - pushd ./src/bindings - rm -rf ./compiled/_node_bindings - cp -Lr ./compiled $out - cp -Lr ./mina-transaction/gen $out/mina-transaction/ - popd - ''; + mkdir -p $out/mina-transaction + pushd ./src/bindings + rm -rf ./compiled/_node_bindings + cp -Lr ./compiled $out + cp -Lr ./mina-transaction/gen $out/mina-transaction/ + popd + ''; }; kimchi = pkgs.kimchi-rust-wasm; ocaml-js = prj.pkgs.__ocaml-js__;