-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathflake.nix
167 lines (139 loc) · 5.42 KB
/
flake.nix
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
{
description = "Build barretenberg-sys";
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs/nixos-22.11";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
# All of these inputs (a.k.a. dependencies) need to align with inputs we
# use so they use the `inputs.*.follows` syntax to reference our inputs
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
crane = {
url = "github:ipetkov/crane";
# All of these inputs (a.k.a. dependencies) need to align with inputs we
# use so they use the `inputs.*.follows` syntax to reference our inputs
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
flake-compat.follows = "flake-compat";
rust-overlay.follows = "rust-overlay";
};
};
barretenberg = {
url = "github:AztecProtocol/barretenberg";
# All of these inputs (a.k.a. dependencies) need to align with inputs we
# use so they use the `inputs.*.follows` syntax to reference our inputs
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
};
outputs =
{ self, nixpkgs, crane, flake-utils, rust-overlay, barretenberg, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
rust-overlay.overlays.default
barretenberg.overlays.default
];
};
rustToolchain = pkgs.rust-bin.stable."1.66.0".default.override {
# We include rust-src to ensure rust-analyzer works.
# See https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570/4
extensions = [ "rust-src" ];
};
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
environment = {
# rust-bindgen needs to know the location of libclang
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
};
# As per https://discourse.nixos.org/t/gcc11stdenv-and-clang/17734/7 since it seems that aarch64-linux uses
# gcc9 instead of gcc11 for the C++ stdlib, while all other targets we support provide the correct libstdc++
stdenv =
if (pkgs.stdenv.targetPlatform.isGnu && pkgs.stdenv.targetPlatform.isAarch64) then
pkgs.overrideCC pkgs.llvmPackages.stdenv (pkgs.llvmPackages.clang.override { gccForLibs = pkgs.gcc11.cc; })
else
pkgs.llvmPackages.stdenv;
# Combine the environment and other configuration needed for crane to build our Rust packages
commonArgs = environment // {
# Use our custom stdenv to build and test our Rust project
inherit stdenv;
src = craneLib.cleanCargoSource ./.;
# Running checks don't do much more than compiling itself and increase
# the build time by a lot, so we disable them throughout all our flakes
doCheck = false;
nativeBuildInputs = [
# This provides the pkg-config tool to find barretenberg & other native libraries
pkgs.pkg-config
# This provides the `lld` linker to cargo
pkgs.llvmPackages.bintools
];
buildInputs = [
pkgs.llvmPackages.openmp
pkgs.barretenberg
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
# Need libiconv on Darwin. See https://github.com/ipetkov/crane/issues/156
pkgs.libiconv
];
};
# Build *just* the cargo dependencies, so we can reuse all of that work between runs
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
barretenberg-sys = craneLib.buildPackage (commonArgs // {
pname = "barretenberg-sys";
# x-release-please-start-version
version = "0.2.0";
# x-release-please-end
inherit cargoArtifacts;
});
in
rec {
checks = {
cargo-clippy = craneLib.cargoClippy (commonArgs // {
inherit cargoArtifacts;
# TODO(blaine): It'd be nice to include these flags when running `cargo clippy` in a devShell.
cargoClippyExtraArgs = "--all-targets -- -D warnings";
doCheck = true;
});
cargo-test = craneLib.cargoTest (commonArgs // {
inherit cargoArtifacts;
# TODO(blaine): It'd be nice to include this flag when running `cargo test` in a devShell.
cargoTestExtraArgs = "--workspace";
doCheck = true;
});
};
packages.default = barretenberg-sys;
# Setup the environment to match the stdenv from `nix build` & `nix flake check`, and
# combine it with the environment settings, the inputs from our checks derivations,
# and extra tooling via `nativeBuildInputs`
devShells.default = pkgs.mkShell.override { inherit stdenv; } (environment // {
inputsFrom = builtins.attrValues checks;
nativeBuildInputs = with pkgs; [
which
starship
git
nil
nixpkgs-fmt
llvmPackages.lldb # This ensures the right lldb is in the environment for running rust-lldb
];
shellHook = ''
eval "$(starship init bash)"
echo LIBBARRETENBERG=${pkgs.barretenberg}
'';
});
});
}