Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
186 lines (182 loc) · 6.64 KB
/
Copy pathflake.nix
File metadata and controls
186 lines (182 loc) · 6.64 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
{
inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1"; # unstable Nixpkgs
fenix = {
url = "https://flakehub.com/f/nix-community/fenix/0.1";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
fenix,
}:
let
inherit (nixpkgs) lib;
validationSource = lib.cleanSourceWith {
src = self;
filter =
path: type:
let
relative = lib.removePrefix "${self}/" (toString path);
inSourceTree = lib.any (root: relative == root || lib.hasPrefix "${root}/" relative) [
"crates/libcfd"
"crates/libcfd-rpc"
];
safePath = lib.all (
part:
!(lib.hasPrefix "." part)
&& !(builtins.elem part [
"state"
"target"
"research"
])
) (lib.splitString "/" relative);
in
if type == "directory" then
toString path == toString self || relative == "crates" || (inSourceTree && safePath)
else
type == "regular"
&& (
builtins.elem relative [
"Cargo.toml"
"Cargo.lock"
]
|| (
inSourceTree
&& safePath
&& (
lib.hasSuffix ".rs" relative
|| lib.hasSuffix ".capnp" relative
|| builtins.baseNameOf relative == "Cargo.toml"
|| relative == "crates/libcfd/src/edge/transport/quic/cloudflare_origin_ca.pem"
)
)
);
};
perSystem =
lib.genAttrs
[
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
]
(
system:
let
pkgs = nixpkgs.legacyPackages.${system};
rustToolchain = fenix.packages.${system}.stable.withComponents [
"clippy"
"rustc"
"cargo"
"rustfmt"
"rust-src"
];
rustPlatform = pkgs.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
nativeBuildInputs = with pkgs; [
rustToolchain
pkg-config
cmake
go
libclang
capnproto
gitMinimal
];
buildInputs = [ pkgs.openssl ] ++ lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.glibc.dev;
rustTarget = lib.replaceStrings [ "-" ] [ "_" ] pkgs.stdenv.hostPlatform.rust.rustcTarget;
buildEnvironment = {
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
}
// lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.glibc.dev}/include";
# BoringSSL's C++ include_next breaks with the GCC wrapper's -isystem ordering.
"CC_${rustTarget}" = "${pkgs.gcc.cc}/bin/gcc";
"CXX_${rustTarget}" = "${pkgs.gcc.cc}/bin/g++";
CFLAGS = "-B${pkgs.glibc}/lib/ -L${pkgs.glibc}/lib -L${pkgs.gcc.cc.lib}/lib";
CXXFLAGS = "-B${pkgs.glibc}/lib/ -L${pkgs.glibc}/lib -L${pkgs.gcc.cc.lib}/lib";
};
in
{
checks = {
secret-hygiene =
pkgs.runCommand "libcfd-secret-hygiene"
{
nativeBuildInputs = [
pkgs.gitMinimal
pkgs.gitleaks
];
}
''
cp ${./.gitignore} .gitignore
git init --quiet
git check-ignore --quiet tests/state/probe
# RFC 6455 nonce and synthetic b"top-secret" test credentials only.
cat > "$TMPDIR/gitleaks.toml" <<'EOF'
[extend]
useDefault = true
[[allowlists]]
description = "Public protocol example and synthetic test credentials"
regexTarget = "secret"
regexes = ['^dGhlIHNhbXBsZSBub25jZQ==$', '^dG9wLXNlY3JldA==$']
EOF
gitleaks dir ${validationSource} --config "$TMPDIR/gitleaks.toml" --redact --no-banner
touch "$out"
'';
validation = rustPlatform.buildRustPackage {
pname = "libcfd-validation";
version = "0.3.0";
src = validationSource;
cargoLock.lockFile = ./Cargo.lock;
inherit nativeBuildInputs buildInputs;
env = buildEnvironment // {
CARGO_NET_OFFLINE = "true";
CARGO_INCREMENTAL = "0";
CARGO_PROFILE_DEV_DEBUG = "0";
CARGO_PROFILE_TEST_DEBUG = "0";
};
auditable = false;
dontUseCmakeConfigure = true;
buildPhase = ''
runHook preBuild
export CARGO_BUILD_JOBS="$NIX_BUILD_CORES"
cargo fmt --all --check
cargo check --workspace --all-targets --all-features
cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo test --workspace --all-features
cargo check --workspace --all-targets
runHook postBuild
'';
doCheck = false;
installPhase = ''
mkdir -p "$out"
touch "$out/passed"
'';
};
};
devShells.default = pkgs.mkShell {
inherit nativeBuildInputs buildInputs;
packages = with pkgs; [
cargo-deny
cargo-edit
cargo-watch
rust-analyzer
nixfmt
];
env = buildEnvironment // {
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library";
};
};
formatter = pkgs.nixfmt;
}
);
in
{
checks = lib.mapAttrs (_: config: config.checks) perSystem;
devShells = lib.mapAttrs (_: config: config.devShells) perSystem;
formatter = lib.mapAttrs (_: config: config.formatter) perSystem;
};
}