Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
144 lines (123 loc) · 4.05 KB
/
Copy pathflake.nix
File metadata and controls
144 lines (123 loc) · 4.05 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
nixpkgs,
flake-utils,
pre-commit-hooks,
rust-overlay,
treefmt-nix,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
inherit (pkgs) mkShell;
rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
# Only rustc + cargo + rust-std are needed to actually *build* the
# package. `rust` above also drags in rustfmt/clippy/rust-analyzer/
# rust-src/rust-docs/llvm-tools (whatever rust-toolchain.toml asks
# for), and since they're all part of the same aggregated
# derivation, their /nix/store paths get embedded as plain strings
# in the compiled binary (panic locations, debug info, etc.) and
# end up as spurious runtime dependencies of the final package.
rustBuild = pkgs.rust-bin.fromRustupToolchain {
channel = (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain.channel;
};
rustPlatform = pkgs.makeRustPlatform {
rustc = rustBuild;
cargo = rustBuild;
};
formatter =
(treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
settings = {
allow-missing-formatter = true;
verbose = 0;
global.excludes = [ "*.lock" ];
formatter = {
nixfmt.options = [ "--strict" ];
rustfmt.package = rust;
};
};
programs = {
nixfmt.enable = true;
prettier.enable = true;
rustfmt = {
enable = true;
package = rust;
};
taplo.enable = true;
};
}).config.build.wrapper;
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
deadnix.enable = true;
nixfmt.enable = true;
treefmt = {
enable = true;
package = formatter;
};
};
};
in
{
packages.default = rustPlatform.buildRustPackage {
name = "ai-jail";
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
nativeBuildInputs = [
pkgs.makeWrapper
pkgs.bubblewrap
];
# curl is required by tests/filtered_egress.rs to drive fixture
# traffic through the proxy bridge during checkPhase.
nativeCheckInputs = [ pkgs.curl ];
BWRAP_BIN = "${pkgs.bubblewrap}/bin/bwrap";
# Belt-and-suspenders: strip any /nix/store path that might still
# get baked into the binary (panic!()/file!() locations, debug
# info, ...) so Nix's reference scanner has nothing left to
# falsely latch onto, even for the now-much-smaller build toolchain.
RUSTFLAGS = "--remap-path-prefix=${builtins.storeDir}=/build";
postFixup = ''
wrapProgram "$out/bin/ai-jail" \
--set BWRAP_BIN "${pkgs.bubblewrap}/bin/bwrap"
'';
};
formatter = formatter;
checks = { inherit pre-commit-check; };
devShells.default = mkShell {
name = "ai-jail";
buildInputs = [
rust
formatter
pkgs.bubblewrap
pkgs.curl
];
shellHook = ''
export BWRAP_BIN="${pkgs.bubblewrap}/bin/bwrap"
'';
};
}
);
}