Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
266 lines (234 loc) · 12.1 KB
/
Copy pathflake.nix
File metadata and controls
266 lines (234 loc) · 12.1 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
{
description = "IGLOO kernels: pristine upstream tarball + IGLOO patch series, cross-built by kernelsmith";
nixConfig = {
extra-substituters = [ "https://rehosting-tools.cachix.org" ];
extra-trusted-public-keys = [
"rehosting-tools.cachix.org-1:iNKSaFwG7MfGn6Fk7oTmIcLHqfffQ+cQIE5gWc6MlY0="
];
};
inputs = {
# Provides the (kernel version, arch) -> cross toolchain resolver. Replaces
# the embedded-toolchains Docker image, whose toolchains were unversioned
# `wget https://musl.cc/*-cross.tgz` downloads -- i.e. today's shipped
# kernels have no recorded compiler identity.
kernelsmith.url = "github:rehosting/kernelsmith";
nixpkgs.follows = "kernelsmith/nixpkgs";
# qemu ONLY, for nix/boot.nix. Deliberately not `nixpkgs`: the kernel build
# pins 24.05 (qemu 8.2.7), which predates nixpkgs shipping
# edk2-loongarch64-code.fd -- and loongarch64's kernel_fmt is vmlinuz.efi,
# a PE image that needs EFI firmware to boot at all. Pinning the harness's
# qemu separately also stops "what the kernel builds against" and "what we
# boot on" from being forced to move together; the second should track what
# penguin runs, which is never a four-year-old qemu.
nixpkgs-qemu.url = "github:NixOS/nixpkgs/nixos-25.05";
# Source only -- igloo_driver has no flake of its own yet. This is here to
# ACCEPTANCE-TEST the kernel `dev` output (see nix/driver.nix): a build tree
# that cannot build the one module we care about is broken, and this repo is
# where that should be caught. It is not a claim about which repo should own
# the driver build long-term.
igloo_driver = {
url = "github:rehosting/igloo_driver";
flake = false;
};
};
outputs =
{ self, nixpkgs, nixpkgs-qemu, kernelsmith, igloo_driver }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
qemuPkgs = nixpkgs-qemu.legacyPackages.${system};
inherit (pkgs) lib;
# Upstream bases. These are REAL RELEASE TAGS -- the point of the patchset
# migration. Previously linux/6.13 was pinned to a tree based on v6.13~5
# with three upstream commits cherry-picked forward, which no one would
# choose deliberately; those three are now simply present in the tarball.
bases = {
"4.10" = {
tag = "4.10";
hash = "sha256-PJXZ8Em9CF5cNG0sd/BjuEJfGRRg/NOun+fpTgR33Es=";
};
"6.13" = {
tag = "6.13";
hash = "sha256-553Mbrhmlca6v7B8KGGRK2NdUHXGzRzQVn0eoVX4DW4=";
};
};
matrix = import ./nix/matrix.nix;
configLib = import ./nix/config.nix { inherit pkgs; };
sourceLib = import ./nix/source.nix { inherit pkgs; };
mkKernel = import ./nix/kernel.nix { inherit pkgs kernelsmith; };
# Arches kernelsmith cannot resolve a toolchain for yet. Listed explicitly
# rather than silently dropped, so `nix build .#all` never quietly ships a
# smaller matrix than build.sh does.
#
# Now empty: riscv64 landed as a Bootlin k6 pin, and loongarch64 as a
# kernel-only gcc 13.3 (no libc toolchain exists for it from any source --
# see kernelsmith's matrix.k6LoongarchKernel). Kept as a mechanism rather
# than deleted, so a future arch gap is declared here instead of silently
# shrinking `nix build .#all` below what build.sh covers.
kernelsmithMissing = [ ];
buildable = version: builtins.filter (t: !(builtins.elem t kernelsmithMissing)) matrix.${version};
kernelSrcFor = version: sourceLib.kernelSource {
patchesRoot = ./patches;
inherit version;
base = bases.${version};
};
# Memoise per version: one patched source tree feeds every target.
sources = lib.genAttrs (builtins.attrNames matrix) kernelSrcFor;
cellFor = version: target: mkKernel {
inherit version target;
src = sources.${version};
config = configLib.rawConfig {
configsSrc = ./configs;
inherit version target;
};
};
cells = lib.listToAttrs (lib.concatMap
(version: map
(target: lib.nameValuePair "kernel-${version}-${target}" (cellFor version target))
(buildable version))
(builtins.attrNames matrix));
# ---- the release seam ---------------------------------------------
# Keep emitting the two tarballs penguin consumes today, so switching
# linux_builder to nix does not require touching penguin at all. Moving
# penguin to a flake input is a separate, later change.
analysisLib = import ./nix/analysis.nix { inherit pkgs; };
releaseLib = import ./nix/release.nix { inherit pkgs; };
mkPerf = import ./nix/perf.nix { inherit pkgs kernelsmith; };
mkDriver = import ./nix/driver.nix { inherit pkgs kernelsmith; };
bootLib = import ./nix/boot.nix { inherit pkgs qemuPkgs; };
lintLib = import ./nix/lint.nix { inherit pkgs; };
cfgTools = import ./nix/config-tools.nix { inherit pkgs; };
# Per-cell record carrying everything the assembly needs.
cellRecords = version: map
(target:
let kernel = cells."kernel-${version}-${target}"; in {
inherit version target kernel;
# Carried so nix/lint.nix can re-run savedefconfig over exactly the
# tree and fragment this cell was built from.
src = sources.${version};
config = configLib.rawConfig {
configsSrc = ./configs;
inherit version target;
};
osi = analysisLib.osiConfig { inherit kernel version target; };
cosi = analysisLib.cosiJson { inherit kernel version target; };
perf = mkPerf {
inherit version target;
src = sources.${version};
inherit (kernel) arch;
};
driver = mkDriver {
inherit kernel version target;
src = igloo_driver;
};
})
(buildable version);
allRecords = lib.concatMap cellRecords (builtins.attrNames matrix);
# Per-cell analysis/perf outputs, individually addressable. Without these
# a broken perf can only be reached through the whole release tarball,
# which rebuilds everything to show you one compiler error.
perCellOutputs = lib.listToAttrs (lib.concatMap
(r: [
(lib.nameValuePair "perf-${r.version}-${r.target}" r.perf)
(lib.nameValuePair "driver-${r.version}-${r.target}" r.driver)
(lib.nameValuePair "osi-${r.version}-${r.target}" r.osi)
(lib.nameValuePair "cosi-${r.version}-${r.target}" r.cosi)
# The one check that asks whether the kernel RUNS. Individually
# addressable so a dead cell can be reproduced in one command:
# nix build .#packages.x86_64-linux."boot-4.10-x86_64"
(lib.nameValuePair "boot-${r.version}-${r.target}"
(bootLib.forCell { inherit (r) kernel version target; }))
# Replaces `./build.sh --config-only`. Advisory, not a gate -- see
# nix/lint.nix for why asserting on it would be wrong.
(lib.nameValuePair "config-lint-${r.version}-${r.target}"
(lintLib.forCell { inherit (r) kernel config src version target; }))
])
allRecords);
in
{
packages.${system} = cells // perCellOutputs // {
default = cells."kernel-6.13-armel";
# Everything buildable today, in one derivation, for CI.
all = pkgs.linkFarm "igloo-kernels-all"
(lib.mapAttrsToList (n: v: { name = n; path = v; }) cells);
# The same payload as kernels-latest, but as a directory. This is the
# seam for Nix consumers: penguin stages `<version>/...` straight into
# /igloo_static/kernels/, so handing it the tree avoids packing an
# archive purely for the consumer to unpack again.
kernels = releaseLib.kernelsTree {
versions = map
(version: {
inherit version;
dir = releaseLib.kernelsDir { inherit version; cells = cellRecords version; };
})
(builtins.attrNames matrix);
};
# Drop-in replacements for the Docker build's release artifacts.
kernels-latest = releaseLib.kernelsTarball {
versions = map
(version: {
inherit version;
dir = releaseLib.kernelsDir { inherit version; cells = cellRecords version; };
})
(builtins.attrNames matrix);
};
kernel-devel-all = releaseLib.develTarball { cells = allRecords; };
# Catches the failure class where a cell builds fine and produces an
# artifact whose ELF class or endianness disagrees with its target name.
# See nix/shape.nix -- two such bugs shipped undetected on this branch.
shape-check = (import ./nix/shape.nix { inherit pkgs; }) { cells = allRecords; };
# Catches the strictly worse failure class shape-check cannot see: an
# artifact of exactly the right shape and size that does not run at all.
# nixdev_0.1.0's 4.10/x86_64 is one -- see nix/boot.nix.
boot-check = bootLib.all { cells = allRecords; };
# Every cell's savedefconfig lint in one build, for a config sweep.
# The nix replacement for `./build.sh --config-only` across all targets.
config-lint = lintLib.all { cells = allRecords; };
# THE config gate: does every cell END UP with what IGLOO needs?
# Reads the post-olddefconfig .config, not the fragment -- see
# nix/config-tools.nix for why that distinction is the whole point.
config-required = cfgTools.requiredCheck { cells = allRecords; };
# Duplicated assignments, and options that did not survive
# olddefconfig. Advisory.
config-redundant = cfgTools.redundancyReport {
cells = allRecords;
configsSrc = ./configs;
};
# `nix run .#config-explain -- 6.13 x86_64 CONFIG_IGLOO`
config-explain = cfgTools.explainScript;
# The analysis tools, pinned. Exposed so their provenance is inspectable
# and so igloo_driver can reuse dwarf2json for its own ISF (it runs the
# same fork over igloo.ko) instead of re-deriving the pin.
inherit (analysisLib) dwarf2json extractKernelinfo;
};
# The patched source trees, so `nix build .#sources.x86_64-linux."6.13"`
# gives you exactly what the kernel builds from -- useful for inspecting
# what the series produces without a full kernel build.
inherit sources;
# `nix run .#config-explain -- <version> <target> CONFIG_X`. An app rather
# than only a package so it is one command from a clean checkout; it reads
# configs/ and builds no kernel, so it stays instant.
apps.${system}.config-explain = {
type = "app";
program = "${cfgTools.explainScript}/bin/config-explain";
};
# Cells we cannot build until kernelsmith gains these arches.
missingArches = kernelsmithMissing;
devShells.${system}.default = pkgs.mkShell {
packages = with pkgs; [ gnumake bc bison flex openssl elfutils git ];
shellHook = ''
echo "linux_builder (nix-patchset)"
# NB: cell names contain a '.', which nix would parse as an attrpath
# separator -- quote the attribute or the build fails to resolve.
echo ' nix build .#packages.x86_64-linux."kernel-6.13-armel" one cell'
echo " nix build .#all every buildable cell"
echo " nix build .#boot-check every kernel actually boots"
echo " nix build .#config-required configs satisfy the IGLOO contract (gate)"
echo ' nix run .#config-explain -- 6.13 x86_64 CONFIG_IGLOO where does an option come from'
echo " nix build .#config-redundant duplicate / dead config lines"
echo " nix build .#config-lint savedefconfig lint (was build.sh --config-only)"
echo " ./scripts/verify-series.sh ... prove a series matches its fork branch"
'';
};
};
}