-
-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathflake.nix
More file actions
273 lines (252 loc) · 10.2 KB
/
flake.nix
File metadata and controls
273 lines (252 loc) · 10.2 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#
# flake.nix - PCP Nix packaging
#
# Quick Start:
# nix build # Build PCP package
# nix develop # Development shell
# nix flake show # List all outputs
#
# Run All Tests:
# nix run .#pcp-test-all # Container + K8s + MicroVM tests
#
# Individual Tests:
# nix run .#pcp-container-test # Docker/Podman lifecycle
# nix run .#pcp-k8s-test # Kubernetes DaemonSet (needs minikube)
# nix run .#pcp-test-all-microvms # All MicroVM variants
#
# K8s Manifests (no minikube needed):
# nix build .#pcp-k8s-manifests # All manifests + README
# nix build .#pcp-k8s-manifest-daemonset # Individual DaemonSet YAML
#
# MicroVM with TAP networking (for Grafana dashboards):
# nix run .#pcp-check-host # Verify host environment
# sudo nix run .#pcp-network-setup # Create TAP bridge (requires sudo)
# nix build .#pcp-microvm-grafana-tap && ./result/bin/microvm-run
# # Access Grafana at http://10.177.0.20:3000
# nix run .#pcp-vm-stop # Stop VM
# sudo nix run .#pcp-network-teardown # Cleanup (requires sudo)
#
# See also: ./docs/HowTos/nix/index.rst
#
{
description = "Performance Co-Pilot (PCP) - system performance monitoring toolkit";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
microvm = {
url = "github:astro/microvm.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
microvm,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
nixDir = ./build/nix;
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
# Import modular package definition
# Pass self for stable source hashing - see build/nix/package.nix for details
pcp = import (nixDir + "/package.nix") { inherit pkgs; src = self; };
# Import shared constants and variant definitions
constants = import (nixDir + "/constants.nix");
variants = import (nixDir + "/variants.nix") { inherit constants; };
nixosModule = import (nixDir + "/nixos-module.nix");
# ─── MicroVM Generator ───────────────────────────────────────────
# Creates a MicroVM runner with the specified configuration.
# See build/nix/microvm.nix for full parameter documentation.
mkMicroVM = {
networking ? "user",
debugMode ? true,
enablePmlogger ? true,
enableEvalTools ? false,
enablePmieTest ? false,
enableGrafana ? false,
enableBpf ? false,
portOffset ? 0,
variant ? "base",
}:
import (nixDir + "/microvm.nix") {
inherit pkgs lib pcp microvm nixosModule nixpkgs system;
inherit networking debugMode enablePmlogger enableEvalTools
enablePmieTest enableGrafana enableBpf
portOffset variant;
};
# ─── Variant Package Generator ───────────────────────────────────
# Generates MicroVM packages for all variants and networking modes.
mkVariantPackages = lib.foldl' (acc: variantName:
let
def = variants.definitions.${variantName};
portOffset = constants.variantPortOffsets.${variantName};
# User-mode networking variant
userPkg = {
name = variants.mkPackageName variantName "user";
value = mkMicroVM ({
networking = "user";
inherit portOffset;
variant = variantName;
} // def.config);
};
# TAP networking variant (if supported)
tapPkg = lib.optionalAttrs def.supportsTap {
name = variants.mkPackageName variantName "tap";
value = mkMicroVM ({
networking = "tap";
inherit portOffset;
variant = variantName;
} // def.config);
};
in
acc // { ${userPkg.name} = userPkg.value; }
// lib.optionalAttrs (tapPkg ? name) { ${tapPkg.name} = tapPkg.value; }
) {} variants.variantNames;
# Import lifecycle testing framework (Linux only)
lifecycle = lib.optionalAttrs pkgs.stdenv.isLinux (
import (nixDir + "/lifecycle") { inherit pkgs lib; }
);
# Import container module (Linux only) - returns { image, inputsHash }
containerModule = lib.optionalAttrs pkgs.stdenv.isLinux (
import (nixDir + "/container.nix") { inherit pkgs pcp; }
);
# Import container testing framework (Linux only)
containerTest = lib.optionalAttrs pkgs.stdenv.isLinux (
import (nixDir + "/container-test") {
inherit pkgs lib pcp;
containerInputsHash = containerModule.inputsHash or "";
}
);
# Import Kubernetes testing framework (Linux only)
k8sTest = lib.optionalAttrs pkgs.stdenv.isLinux (
import (nixDir + "/k8s-test") {
inherit pkgs lib pcp;
containerInputsHash = containerModule.inputsHash or "";
}
);
# Import standalone K8s manifest generator (Linux only)
k8sManifests = lib.optionalAttrs pkgs.stdenv.isLinux (
import (nixDir + "/k8s-manifests") { inherit pkgs lib; }
);
# Import test-all runner (Linux only)
testAll = lib.optionalAttrs pkgs.stdenv.isLinux (
import (nixDir + "/test-all") {
inherit pkgs lib containerTest k8sTest;
}
);
in
{
packages = {
default = pcp;
inherit pcp;
} // lib.optionalAttrs pkgs.stdenv.isLinux (
{
# OCI container image (Linux only)
pcp-container = containerModule.image;
}
# MicroVM packages for all variants
// mkVariantPackages
# Lifecycle testing packages
// lifecycle.packages
# Container testing packages
// containerTest.packages
# Kubernetes testing packages
// k8sTest.packages
# Standalone K8s manifests
// k8sManifests.packages
# Test-all runner
// testAll.packages
);
checks = lib.optionalAttrs pkgs.stdenv.isLinux {
vm-test = import (nixDir + "/vm-test.nix") {
inherit pkgs pcp;
};
};
# Import modular development shell
devShells.default = import (nixDir + "/shell.nix") { inherit pkgs pcp; };
# ─── Apps (Linux only) ─────────────────────────────────────────────
apps = lib.optionalAttrs pkgs.stdenv.isLinux (
let
networkScripts = import (nixDir + "/network-setup.nix") { inherit pkgs; };
vmScripts = import (nixDir + "/microvm-scripts.nix") { inherit pkgs; };
# ─── MicroVM Test Apps ────────────────────────────────────────────
# Generate test apps for each variant
mkTestApp = variant: networkMode:
let
testName = variants.mkTestAppName variant networkMode;
isTap = networkMode == "tap";
portOffset = constants.variantPortOffsets.${variant};
sshPort = constants.ports.sshForward + portOffset;
host = if isTap then constants.network.vmIp else "localhost";
in {
name = testName;
value = {
type = "app";
program = "${import (nixDir + "/tests/microvm-test.nix") {
inherit pkgs lib;
variant = "${variant}-${networkMode}";
inherit host sshPort;
}}/bin/pcp-test-${variant}-${networkMode}";
};
};
# Generate test apps for all variants
testApps = lib.foldl' (acc: variantName:
let
def = variants.definitions.${variantName};
userTest = mkTestApp variantName "user";
tapTest = lib.optionalAttrs def.supportsTap (mkTestApp variantName "tap");
in
acc // { ${userTest.name} = userTest.value; }
// lib.optionalAttrs (tapTest ? name) { ${tapTest.name} = tapTest.value; }
) {} variants.variantNames;
in {
# Network management
pcp-check-host = {
type = "app";
program = "${networkScripts.check}/bin/pcp-check-host";
};
pcp-network-setup = {
type = "app";
program = "${networkScripts.setup}/bin/pcp-network-setup";
};
pcp-network-teardown = {
type = "app";
program = "${networkScripts.teardown}/bin/pcp-network-teardown";
};
# VM management
pcp-vm-check = {
type = "app";
program = "${vmScripts.check}/bin/pcp-vm-check";
};
pcp-vm-stop = {
type = "app";
program = "${vmScripts.stop}/bin/pcp-vm-stop";
};
pcp-vm-ssh = {
type = "app";
program = "${vmScripts.ssh}/bin/pcp-vm-ssh";
};
# Comprehensive test runner
pcp-test-all-microvms = {
type = "app";
program = "${import (nixDir + "/tests/test-all-microvms.nix") { inherit pkgs lib; }}/bin/pcp-test-all-microvms";
};
}
# Per-variant test apps
// testApps
# Lifecycle testing apps
// lifecycle.apps
# Container testing apps
// containerTest.apps
# Kubernetes testing apps
// k8sTest.apps
# Test-all runner
// testAll.apps
);
}
);
}