aboutsummaryrefslogtreecommitdiff
path: root/zkvms/nexus/default.nix
blob: a7f74e0b4cdfdb6b0e000d8033cc86ec0fc95ae0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{ zkVM-helpers,
  stdenv,
  lib,
  just,
  metacraft-labs,
  openssl,
  pkg-config,
  craneLib-default,
}:
let
  commonArgs = {
    pname = "nexus";
    version = "infdev";

    src = with lib.fileset; toSource {
      root = ../..;
      fileset = intersection (gitTracked ../..) (unions [
          ./.
          ../../guests
          ../../guests_macro
          ../../zkvms_host_io
          ../../Vertices-010.in
      ]);
    };

    cargoLock = ./Cargo.lock;

    nativeBuildInputs = [
      metacraft-labs.nexus
      openssl
      pkg-config
    ];
  };

  craneLib = craneLib-default.overrideToolchain metacraft-labs.nexus;
  cargoArtifacts = craneLib.buildDepsOnly (zkVM-helpers.fixDeps commonArgs);
in
  craneLib.buildPackage (zkVM-helpers.withCustomPhases (commonArgs
    // rec {
      inherit cargoArtifacts;

      postPatch = ''
        ln -s ../../../../guests/graph_coloring ./zkvms/nexus/guest/src/zkp
      '';

      hostBin = "host-nexus";
      guestTarget = "riscv32i-unknown-none-elf";
      extraGuestArgs = "-- --cfg 'feature=\"no_std\"' -C link-arg=-T${guest/guest.ld}";

      buildGuestPhase = ''
        pushd guest

        cargo rustc --release --target ${guestTarget} ${extraGuestArgs}
        ln -s ../../guest/target/${guestTarget}/release/guest ../host/src/guest

        popd
      '';

      preRun = ''
        export ELF_PATH="$out/bin/guest"
        export PKG_CONFIG_PATH='${openssl.dev}/lib/pkgconfig' # Dirty hack
        export LD_LIBRARY_PATH='${lib.makeLibraryPath [ openssl ]}'
      '';

      doCheck = false;
    }))