-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
238 lines (217 loc) · 8.1 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
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
{
description =
"CVM-Eval -- Evaluation environment for AMD SEV-SNP and Intel TDX";
inputs = {
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-2311.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
};
outputs = { self, nixpkgs-unstable, nixpkgs-2311, flake-utils, pre-commit-hooks }:
(flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
nixpkgs-direct = nixpkgs-unstable;
pkgs = nixpkgs-unstable.legacyPackages.${system};
pkgs-2311 = nixpkgs-2311.legacyPackages.${system};
make-disk-image = import (pkgs.path + "/nixos/lib/make-disk-image.nix");
selfpkgs = self.packages.x86_64-linux;
python3 = nixpkgs-unstable.legacyPackages.${system}.python3;
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
nixpkgs-fmt.enable = true;
black.enable = true;
clang-format.enable = true;
};
};
#kernel = {
# src = ../linux;
# version = "6.8.0";
# makeFlags = pkgs.linuxPackages_6_8.kernel.makeFlags;
# kernelOlder = x: false;
#};
in
rec {
packages = {
# SPDK is for SSD preconditioning
spdk = pkgs.callPackage ./nix/spdk.nix { inherit pkgs; };
qemu-amd-sev-snp =
pkgs.callPackage ./nix/qemu-amd-sev-snp.nix { inherit pkgs; };
ovmf-amd-sev-snp =
pkgs.callPackage ./nix/ovmf-amd-sev-snp.nix { inherit pkgs; };
# Note: this does not work yet!
qemu-tdx =
pkgs.callPackage ./nix/qemu-tdx.nix { inherit pkgs; };
ovmf-tdx =
pkgs.callPackage ./nix/ovmf-tdx.nix { inherit pkgs; };
# qcow image with Linux kernel
normal-guest-image = make-disk-image {
config = self.nixosConfigurations.normal-guest.config;
inherit (pkgs) lib;
inherit pkgs;
format = "qcow2";
partitionTableType = "efi";
installBootLoader = true;
diskSize = 32768;
touchEFIVars = true;
};
# qcow image with Linux kernel with snp support
snp-guest-image = make-disk-image {
config = self.nixosConfigurations.snp-guest.config;
inherit (pkgs) lib;
inherit pkgs;
format = "qcow2";
partitionTableType = "efi";
installBootLoader = true;
diskSize = 32768;
touchEFIVars = true;
};
# qcow image with Linux kernel with tdx support
tdx-guest-image = make-disk-image {
config = self.nixosConfigurations.tdx-guest.config;
inherit (pkgs) lib;
inherit pkgs;
format = "qcow2";
partitionTableType = "efi";
installBootLoader = true;
diskSize = 32768;
touchEFIVars = true;
};
# file system image w/o kernel
guest-fs = make-disk-image {
config = self.nixosConfigurations.fs.config;
inherit (pkgs) lib;
inherit pkgs;
format = "qcow2";
partitionTableType = "none";
# installBootLoader option set up /sbin/init, etc.
installBootLoader = true;
diskSize = 32768;
contents = [
{
source = ./config/phoronix/phoronix-test-suite.xml;
target = "/etc/phoronix-test-suite.xml";
}
];
};
# shell for linux kernel build
kernel-deps = pkgs.callPackage ./nix/kernel-deps.nix { };
# WIP: build perf with nix
#perf = pkgs.callPackage ./nix/perf.nix { kernel = kernel; };
};
devShells = {
default = pkgs.mkShell {
name = "devshell";
buildInputs =
let
inv-completion = pkgs.writeScriptBin "inv-completion" ''
inv --print-completion-script zsh
'';
in
with pkgs;
[
python3
python3.pkgs.invoke
python3.pkgs.colorama
python3.pkgs.click
python3.pkgs.seaborn
python3.pkgs.pandas
python3.pkgs.binary
python3.pkgs.lxml
python3.pkgs.ipython
python3.pkgs.psutil
just
git
tig
fzf
bpftrace
gdb
jq
bridge-utils
hwloc
numactl
sysstat
fio
cryptsetup
iperf # iperf3
memtier-benchmark
wrk
] ++ [ inv-completion ]
++ pre-commit-check.enabledPackages;
inherit (pre-commit-check) shellHook;
};
# for running benchmarks
blender = pkgs.callPackage ./benchmarks/application/blender/shell.nix { inherit pkgs; };
pytorch = pkgs.callPackage ./benchmarks/application/pytorch/shell.nix { inherit pkgs; };
# 2024-05-30: keras in the latest pkgs has some dependency issues; use pkgs-2311
tensorflow = pkgs.callPackage ./benchmarks/application/tensorflow/shell.nix { pkgs = pkgs-2311; };
sqlite = pkgs.callPackage ./benchmarks/application/sqlite/shell.nix { inherit pkgs; };
network = pkgs.callPackage ./benchmarks/network/shell.nix { inherit pkgs; };
sev_attestation = pkgs.callPackage ./benchmarks/attestation/sev/shell.nix { inherit pkgs; };
};
})) // {
lib.nixpkgsRev = nixpkgs-unstable.shortRev;
# nixOS configurations to create a guest image
nixosConfigurations =
let
# 2024-05-30: the latest nixosSystem of unstable seems really unstable?
# nix stores get easily corrupted when a VM is killed abruptly
# use nixpkgs-2311 for the time being
nixosSystem = nixpkgs-2311.lib.nixosSystem;
pkgs = nixpkgs-unstable.legacyPackages.x86_64-linux;
# use gcc13 (same as Ubuntu 24.04)
gcc = pkgs.gcc13;
selfpkgs = self.packages.x86_64-linux;
kernelConfig = { config, lib, pkgs, ... }: {
boot.kernelPackages = pkgs.linuxPackages_6_8;
};
# bake in packages for running benchmarks
extraEnvPackages =
self.devShells.x86_64-linux.blender.nativeBuildInputs
++ self.devShells.x86_64-linux.pytorch.nativeBuildInputs
++ self.devShells.x86_64-linux.tensorflow.nativeBuildInputs
++ self.devShells.x86_64-linux.sqlite.nativeBuildInputs
++ self.devShells.x86_64-linux.network.nativeBuildInputs
++ self.devShells.x86_64-linux.sev_attestation.nativeBuildInputs;
guestConfig = (import ./nix/guest-config.nix { inherit extraEnvPackages; _gcc = gcc; });
in
{
# File system image w/o kernel
fs = nixosSystem {
system = "x86_64-linux";
modules = [
guestConfig
];
};
# Normal Linux guest (mainline)
normal-guest = nixosSystem {
system = "x86_64-linux";
modules = [
guestConfig
kernelConfig
./nix/nixos-generators-qcow.nix
];
};
# SEV-SNP guest
snp-guest = nixosSystem {
system = "x86_64-linux";
modules = [
guestConfig
kernelConfig
./nix/snp-guest-config.nix
./nix/nixos-generators-qcow.nix
];
};
# TDX guest
tdx-guest = nixosSystem {
system = "x86_64-linux";
modules = [
guestConfig
kernelConfig
./nix/tdx-guest-config.nix
./nix/nixos-generators-qcow.nix
];
};
};
};
}