-
Notifications
You must be signed in to change notification settings - Fork 42
/
flake.nix
146 lines (131 loc) · 5.62 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
{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
crane.url = "github:ipetkov/crane";
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
imports = [inputs.treefmt-nix.flakeModule];
flake.hydraJobs = builtins.removeAttrs inputs.self.packages ["aarch64-linux"];
perSystem = {
pkgs,
config,
system,
self',
...
}: let
inherit (inputs.nixpkgs) lib;
craneLib = inputs.crane.mkLib pkgs;
clean = root:
lib.cleanSourceWith {
src = lib.cleanSource (craneLib.path root);
filter = orig_path: type: let
path = builtins.toString orig_path;
base = builtins.baseNameOf path;
parentDir = builtins.baseNameOf (builtins.dirOf path);
matchesSuffix = lib.any (suffix: lib.hasSuffix suffix base) [".rs" ".toml" ".md"];
isCargoFile = base == "Cargo.lock";
isCargoConfig = parentDir == ".cargo" && base == "config";
isOpenApiYaml = base == "openapi.yaml";
isFakeAggregatorDefaultData = lib.hasInfix "/mithril-aggregator-fake/default_data/" path;
isTestDataAsset = lib.hasInfix "/test_data/" path;
in
type == "directory" || matchesSuffix || isCargoFile || isCargoConfig || isOpenApiYaml
|| isFakeAggregatorDefaultData || isTestDataAsset;
};
buildInputs =
[
pkgs.gnum4
pkgs.pkg-config
pkgs.openssl
]
++ lib.optional (pkgs.stdenv.isDarwin) [
pkgs.darwin.apple_sdk.frameworks.CoreServices
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
pkgs.darwin.configdHeaders
pkgs.darwin.libiconv
];
commonsArgs = {
pname = "mithril";
version = "0.0.1";
src = clean ./.;
inherit buildInputs;
CARGO_TERM_VERBOSE = "true";
};
buildDeps = cargoToml: cargoArtifacts:
(craneLib.buildDepsOnly (commonsArgs
// lib.optionalAttrs (cargoToml != null) rec {
inherit (craneLib.crateNameFromCargoToml {inherit cargoToml;}) pname version;
cargoExtraArgs = "-p ${pname}";
}))
.overrideAttrs (_: {
inherit cargoArtifacts;
preInstall = let
# Need to remove dummy builds of local builds so that they can be built again
localLibs = "dummy|mithril|stm|multi_sig|size_benches|digester";
in ''
shopt -s extglob
rm ''${CARGO_TARGET_DIR:-target}/release/deps/*@(${localLibs})*
rm -r ''${CARGO_TARGET_DIR:-target}/release/*@(${localLibs})*
rm -r ''${CARGO_TARGET_DIR:-target}/release/build/*@(${localLibs})*
rm -r ''${CARGO_TARGET_DIR:-target}/release/.fingerprint/*@(${localLibs})*
'';
});
buildPackage = cargoToml: baseCargoArtifacts: args:
craneLib.buildPackage (commonsArgs
// lib.optionalAttrs (cargoToml != null) rec {
inherit (craneLib.crateNameFromCargoToml {inherit cargoToml;}) pname version;
cargoExtraArgs = "-p ${pname}";
}
// {
cargoArtifacts = buildDeps cargoToml baseCargoArtifacts;
}
// args);
mithril-stm = buildPackage ./mithril-stm/Cargo.toml null {};
mithril-common = buildPackage ./mithril-common/Cargo.toml mithril-stm.cargoArtifacts { cargoExtraArgs = "-p mithril-common --features full"; };
mithril = buildPackage null mithril-common.cargoArtifacts {
doCheck = false;
};
in {
packages = {
default = mithril;
inherit mithril mithril-stm mithril-common;
mithril-client = buildPackage ./mithril-client/Cargo.toml mithril.cargoArtifacts { cargoExtraArgs = "-p mithril-client --features full"; };
mithril-client-cli = buildPackage ./mithril-client-cli/Cargo.toml mithril.cargoArtifacts {};
mithril-aggregator = buildPackage ./mithril-aggregator/Cargo.toml mithril.cargoArtifacts {};
mithril-signer = buildPackage ./mithril-signer/Cargo.toml mithril.cargoArtifacts {};
mithril-persistence = buildPackage ./internal/mithril-persistence/Cargo.toml mithril.cargoArtifacts {};
mithrildemo = buildPackage ./demo/protocol-demo/Cargo.toml mithril.cargoArtifacts {};
mithril-end-to-end = buildPackage ./mithril-test-lab/mithril-end-to-end/Cargo.toml null {};
};
devShells.default = pkgs.mkShell {
inputsFrom = [self'.packages.mithril-client-cli];
nativeBuildInputs = [
pkgs.cargo
pkgs.rustc
pkgs.libiconv
config.treefmt.package
pkgs.gnumake
];
shellHook = ''
export RUST_BACKTRACE=1
ln -sf ${config.treefmt.build.configFile} treefmt.toml
'';
};
formatter = pkgs.writeShellApplication {
name = "treefmt";
text = "exec ${config.treefmt.package}/bin/treefmt";
};
treefmt = {
programs.alejandra.enable = true;
programs.rustfmt.enable = true;
projectRootFile = "flake.nix";
};
};
};
}