diff --git a/flake.nix b/flake.nix index 1a4abdb..4d5844e 100644 --- a/flake.nix +++ b/flake.nix @@ -35,20 +35,30 @@ }; }; - outputs = inputs @ {flake-parts, ...}: + outputs = inputs @ { + flake-parts, + nixpkgs, + ... + }: flake-parts.lib.mkFlake {inherit inputs;} { systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]; imports = [./packages]; perSystem = { - final, + pkgs, self', + system, ... }: { + _module.args = { + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + }; + }; devShells.default = import ./shells/all.nix { - pkgs = final; - inherit self'; + inherit pkgs self'; }; - devShells.ci = import ./shells/ci.nix {pkgs = final;}; + devShells.ci = import ./shells/ci.nix {inherit pkgs;}; }; }; } diff --git a/packages/all-packages.nix b/packages/all-packages.nix index 81f11ce..f13bd2c 100644 --- a/packages/all-packages.nix +++ b/packages/all-packages.nix @@ -59,6 +59,9 @@ rapidsnark = callPackage ./rapidsnark/default.nix { inherit ffiasm zqfield-bn254; }; + rapidsnark-gpu = callPackage ./rapidsnark-gpu/default.nix { + inherit ffiasm zqfield-bn254; + }; # Elrond / MultiversX # copied from https://github.com/NixOS/nixpkgs/blob/8df7949791250b580220eb266e72e77211bedad9/pkgs/development/python-modules/cryptography/default.nix @@ -159,7 +162,7 @@ cdt = callPackage ./cdt/default.nix {}; } // lib.optionalAttrs hostPlatform.isx86 rec { - inherit zqfield-bn254 ffiasm ffiasm-src rapidsnark; + inherit zqfield-bn254 ffiasm ffiasm-src rapidsnark rapidsnark-gpu; inherit cardano graphql; } diff --git a/packages/rapidsnark-gpu/default.nix b/packages/rapidsnark-gpu/default.nix new file mode 100644 index 0000000..47c7e42 --- /dev/null +++ b/packages/rapidsnark-gpu/default.nix @@ -0,0 +1,50 @@ +{ + lib, + cudaPackages, + stdenv, + ffiasm, + zqfield-bn254, + nlohmann_json, + gmp, + libsodium, + cmake, + fetchFromGitHub, + pkg-config, +}: let + ffiasm-c = "${ffiasm}/lib/node_modules/ffiasm/c"; +in + stdenv.mkDerivation rec { + pname = "rapidsnark-gpu"; + version = "2023-04-08"; + + src = fetchFromGitHub { + owner = "Orbiter-Finance"; + repo = "rapidsnark"; + rev = "77016322808ac58a3acd25a6235510b55172f967"; + hash = "sha256-8vy+iXkSINFregve+rej1rXyXdWxm0n1wvYfoy/0idk="; + }; + + nativeBuildInputs = [pkg-config]; + buildInputs = [nlohmann_json gmp libsodium cudaPackages.cudatoolkit] ++ ffiasm.passthru.openmp; + + buildPhase = '' + mkdir -p $out/bin + c++ \ + -I{${ffiasm-c},${zqfield-bn254}/lib} \ + ./src/{main_prover,binfile_utils,zkey_utils,wtns_utils,logger}.cpp \ + ${ffiasm-c}/{alt_bn128,misc,naf,splitparstr}.cpp \ + ${zqfield-bn254}/lib/{fq,fr}.{cpp,o} \ + $(pkg-config --cflags --libs libsodium gmp nlohmann_json) \ + -std=c++17 -pthread -O3 -fopenmp \ + -o $out/bin/prover + ''; + + installPhase = '' + # Already done in buildPhase + ''; + + meta = { + homepage = "https://github.com/iden3/rapidsnark"; + platforms = with lib.platforms; linux ++ darwin; + }; + }