-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
156 lines (142 loc) · 4.66 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
{
description = "Fleek SGX";
inputs = {
nixpkgs.url = "github:ozwaldorf/nixpkgs/sgx";
crane.url = "github:ipetkov/crane";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
};
nixConfig = {
extra-trusted-substituters = [ "https://cache.garnix.io" ];
extra-trusted-public-keys = [ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ];
};
outputs =
{
self,
nixpkgs,
crane,
fenix,
flake-utils,
...
}:
flake-utils.lib.eachSystem
[
"x86_64-linux"
"aarch64-darwin"
]
(
system:
let
pkgs = (import nixpkgs { inherit system; });
craneLib = (crane.mkLib pkgs).overrideToolchain (
fenix.packages.${system}.fromToolchainFile {
dir = ./.;
sha256 = "X4me+hn5B6fbQGQ7DThreB/DqxexAhEQT8VNvW6Pwq4=";
}
);
src = craneLib.path ./.;
# Common arguments
commonArgs = {
inherit src;
strictDeps = true;
pname = "fn-sgx";
version = "0.1.0";
packages = [ pkgs.protobuf ];
nativeBuildInputs = with pkgs; [
pkg-config
protobuf
sgxs-tools
fortanix-sgx-tools
];
buildInputs = with pkgs; [
cacert
openssl_3
protobufc
# For linking to `dcap_quoteprov`
sgx-dcap-default-qpl
];
} // commonVars;
commonVars = {
OPENSSL_NO_VENDOR = 1;
OPENSSL_LIB_DIR = "${pkgs.lib.getLib pkgs.openssl_3}/lib";
OPENSSL_INCLUDE_DIR = "${pkgs.lib.getDev pkgs.openssl_3.dev}/include";
};
# Build *just* the cargo dependencies, so we can reuse all of that
# work (e.g. via cachix or github artifacts) when running in CI
cargoArtifacts = craneLib.buildDepsOnly (commonArgs);
in
{
# Allow using `nix flake check` to run tests and lints
checks = {
# Check formatting
fmt = craneLib.cargoFmt {
inherit (commonArgs) pname src;
cargoExtraArgs = "--all";
};
# Check clippy lints
clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets --all-features -- -Dclippy::all -Dwarnings";
}
);
# # Run tests with cargo-nextest
nextest = craneLib.cargoNextest (
commonArgs
// {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
cargoNextestExtraArgs = "--all --exclude fleek-service-sgx-enclave --target x86_64-unknown-linux-gnu";
}
);
};
packages = rec {
default = fn-sgx-enclave;
fn-sgx-enclave =
let
# SGXS binary stream parameters
ENCLAVE_HEAP = "0x100000000";
ENCLAVE_STACK = "0x200000";
ENCLAVE_THREADS = "134";
TARGET = "target/x86_64-fortanix-unknown-sgx/release/fleek-service-sgx-enclave";
in
craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
pname = "fn-sgx-enclave";
doCheck = false;
cargoExtraArgs = "--locked --bin fleek-service-sgx-enclave";
installPhase = ''
# Convert elf to sgxs with our parameters
ftxsgx-elf2sgxs ${TARGET} \
--heap-size ${ENCLAVE_HEAP} \
--stack-size ${ENCLAVE_STACK} \
--threads ${ENCLAVE_THREADS}
# Install to output dir
mkdir -p $out
mv ${TARGET}.sgxs $out/enclave.sgxs
'';
}
);
};
# Allow using `nix develop` on the project
devShells.default = craneLib.devShell (
commonVars
// {
# Inherit inputs from checks
checks = self.checks.${system};
name = "fleek-sgx-dev";
packages = with pkgs; [ rust-analyzer ];
}
);
# Allow using `nix fmt` on the project
formatter = pkgs.nixfmt-rfc-style;
}
);
}