aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
blob: 967fff53fc0cd4f8efe4a1689658e56128cff892 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
{
  description = "zkVMs benchmarks";

  nixConfig = {
    extra-substituters = "https://nix-blockchain-development.cachix.org";
    extra-trusted-public-keys = "nix-blockchain-development.cachix.org-1:Ekei3RuW3Se+P/UIo6Q/oAgor/fVhFuuuX5jR8K/cdg=";
  };

  inputs = {
    mcl-blockchain.url = "github:metacraft-labs/nix-blockchain-development";
    mcl-blockchain-old.url = "github:metacraft-labs/nix-blockchain-development?rev=f717747a4ce11d5764578d8ee1c505d00bf8a81e";
    nixpkgs.follows = "mcl-blockchain/nixpkgs";
    crane.follows = "mcl-blockchain/crane";
    fenix.follows = "mcl-blockchain/fenix";
    flake-parts.follows = "mcl-blockchain/flake-parts";
    systems.url = "github:nix-systems/default";
  };

  outputs =
    inputs:
    inputs.flake-parts.lib.mkFlake { inherit inputs; } {
      systems = import inputs.systems;

      perSystem =
        {
          inputs',
          pkgs,
          lib,
          system,
          ...
        }:
        let
          craneLib-default = inputs.crane.mkLib pkgs;
          callPackage = lib.callPackageWith pkgs;

          zkvms = builtins.attrNames (
            lib.filterAttrs (_: type: type == "directory") (builtins.readDir ./zkvms)
          );

          guests = builtins.attrNames (
            lib.filterAttrs (_: type: type == "directory") (builtins.readDir ./guests)
          );

          createPackages =
            guestName:
            let
              guest = if guestName == null then "graph_coloring" else guestName;
              postfix = if guestName == null then "" else "/" + guest;

              args-zkVM = {
                inherit craneLib-default;
                zkvmLib = (import ./zkvmLib.nix) pkgs guest;
              };
            in
            lib.foldr (
              host: accum:
              accum
              // {
                "${host}${postfix}" = callPackage ./zkvms/${host}/default.nix args-zkVM;
              }
            ) { } zkvms;

          hostPackages = lib.foldr (guest: accum: accum // (createPackages guest)) { } guests;

          guestPackages = lib.foldr (
            guest: accum:
            accum
            // {
              ${guest} = callPackage ./zkvms_guest_io/default.nix {
                inherit guest;
                inherit zkvms;
                inherit hostPackages;
                inherit craneLib-default;
                rev = inputs.self.rev or inputs.self.dirtyRev;
              };
            }
          ) { } guests;
        in
        {
          _module.args.pkgs = import inputs.nixpkgs {
            inherit system;
            overlays = [
              inputs.mcl-blockchain.overlays.default
              inputs.fenix.overlays.default
              (_: _: {
                metacraft-labs-old = inputs'.mcl-blockchain-old.legacyPackages.metacraft-labs;
              })
            ];
          };

          packages =
            hostPackages
            // guestPackages
            // {
              rust-format-all = callPackage ./rust-format-all.nix { };
              update-nix-dependencies = callPackage ./update-nix-dependencies.nix {
                zkvms = builtins.map (name: inputs.mcl-blockchain.packages.${system}.${name}) zkvms;
              };
            };

          devShells.default = pkgs.mkShell {
            buildInputs = with pkgs; [
              (fenix.stable.withComponents [
                "cargo"
                "clippy"
                "rust-src"
                "rustc"
                "rustfmt"
                "rust-analyzer"
              ])

              # Possibly required system libraries by Rust crypto/networking crates
              pkg-config
              openssl
            ];

            shellHook = ''
              echo "zkVMs benchmarks development environment"
              echo "Available packages: ${builtins.concatStringsSep ", " (builtins.attrNames hostPackages)}"
            '';
          };

          formatter = pkgs.nixfmt-rfc-style;
        };
    };
}