-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
135 lines (121 loc) · 4.14 KB
/
Copy pathflake.nix
File metadata and controls
135 lines (121 loc) · 4.14 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
{
description = "Intermesh";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
flake-utils.url = "github:numtide/flake-utils/v1.0.0";
crane.url = "github:ipetkov/crane/v0.23.0";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, flake-utils, crane, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
# Crane is a Nix library for building Rust projects with incremental
# compilation. It splits builds into phases so dependencies are cached
# separately from the code.
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
# Minimal source for dependency compilation. Only includes files needed
# to determine and build dependencies, not the actual source code. This
# ensures cargoArtifacts only rebuilds when Cargo.lock or proto changes.
# Note we include proto in these dependencies since they rarely change
# and take a long time to build.
depsSrc = pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
./flake.nix
./flake.lock
./Cargo.toml
./Cargo.lock
./build.rs
./proto
./xtask
];
};
# Full source for building the actual binary.
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = path: type:
(craneLib.filterCargoSources path type) ||
(builtins.match ".*\\.proto$" path != null) ||
(builtins.match ".*\\.pest$" path != null);
};
# Build dependencies using only the minimal depsSrc.
cargoArtifacts = craneLib.buildDepsOnly {
src = depsSrc;
strictDeps = true;
doCheck = false;
};
# Build the final binary using full source but reusing cached deps.
intermeshUnwrapped = craneLib.buildPackage {
inherit src cargoArtifacts;
strictDeps = true;
doCheck = false;
cargoExtraArgs = "--bin intermesh";
};
# Wrap intermesh so nftables is in PATH (required by the proxy).
# TODO(ejj): interact with the kernel directly over netlink so we can
# ship a static binary without this wrapper.
intermesh = pkgs.runCommand "intermesh" {
nativeBuildInputs = [ pkgs.makeWrapper ];
} ''
mkdir -p $out/bin
makeWrapper ${intermeshUnwrapped}/bin/intermesh $out/bin/intermesh \
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.nftables ]}
'';
testTools = pkgs.buildEnv {
name = "intermesh-test-tools";
paths = [
pkgs.bash
(pkgs.writeShellScriptBin "sh" ''
exec ${pkgs.bash}/bin/bash "$@"
'')
pkgs.caddy
pkgs.coreutils
pkgs.curl
pkgs.dnsmasq
pkgs.dnsutils
pkgs.findutils
pkgs.gawk
pkgs.gnugrep
pkgs.gnused
pkgs.inetutils
pkgs.iproute2
pkgs.iputils
pkgs.netcat-openbsd
pkgs.nftables
pkgs.procps
pkgs.tcpdump
pkgs.which
];
ignoreCollisions = true;
};
in
{
packages.default = intermesh;
packages.intermesh = intermesh;
packages.test-tools = testTools;
packages.deps = cargoArtifacts;
# Development shell dependencies
devShells.default = pkgs.mkShell {
buildInputs = [
rustToolchain
pkgs.protobuf
pkgs.cmake
pkgs.ruby_3_3
pkgs.util-linux
pkgs.docker-client
pkgs.incus
pkgs.cargo-outdated
pkgs.cargo-udeps
pkgs.cargo-audit
pkgs.pkg-config
];
};
}
);
}