Skip to content

Commit 97a786b

Browse files
committed
ci: build kernels with nix build
1 parent e1fc586 commit 97a786b

File tree

4 files changed

+92
-29
lines changed

4 files changed

+92
-29
lines changed

.github/workflows/build-kernel.nix

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{ lib
2+
, stdenv
3+
, fetchgit
4+
, virtme-ng
5+
, linuxManualConfig
6+
, linuxPackages_latest
7+
, name
8+
, repo
9+
, branch
10+
, commitHash
11+
, narHash
12+
, version
13+
}:
14+
15+
let
16+
src = fetchgit {
17+
url = repo;
18+
rev = commitHash;
19+
branchName = branch;
20+
21+
hash = narHash;
22+
};
23+
24+
configfile = stdenv.mkDerivation {
25+
inherit src;
26+
name = name + "-configfile";
27+
28+
buildInputs = linuxPackages_latest.kernel.buildInputs;
29+
nativeBuildInputs = linuxPackages_latest.kernel.nativeBuildInputs;
30+
31+
buildPhase = ''
32+
${virtme-ng}/bin/virtme-ng -v --kconfig --config ${./sched-ext.config}
33+
'';
34+
installPhase = ''
35+
mv .config $out
36+
'';
37+
};
38+
39+
in
40+
linuxManualConfig {
41+
inherit src version configfile;
42+
}

.github/workflows/flake.nix

+18-26
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,29 @@
1111

1212
outputs = { self, nixpkgs, flake-utils, nix-develop-gha, ... }:
1313
flake-utils.lib.eachSystem [ "x86_64-linux" ]
14-
(system: {
15-
packages.nix-develop-gha = nix-develop-gha.packages."${system}".default;
16-
17-
devShells =
18-
let
19-
pkgs = import nixpkgs { inherit system; };
20-
common = with pkgs; [ gnutar zstd ];
21-
in
22-
{
14+
(system:
15+
let
16+
pkgs = import nixpkgs { inherit system; };
17+
in
18+
{
19+
devShells = let common = with pkgs; [ gnutar zstd ]; in {
2320
update-kernels = pkgs.mkShell {
2421
buildInputs = with pkgs; common ++ [
2522
jq
2623
];
2724
};
25+
};
2826

29-
build-kernel = pkgs.mkShell {
30-
buildInputs = with pkgs; common ++ [
31-
bc
32-
bison
33-
cpio
34-
elfutils
35-
flex
36-
git
37-
jq
38-
openssl
39-
pahole
40-
perl
41-
virtme-ng
42-
zlib
43-
];
44-
};
27+
packages = {
28+
kernels = builtins.mapAttrs
29+
(name: details: (pkgs.callPackage ./build-kernel.nix {
30+
inherit name;
31+
inherit (details) repo branch commitHash narHash;
32+
version = details.kernelVersion;
33+
}))
34+
(builtins.fromJSON (builtins.readFile ./../../kernel-versions.json));
4535
};
46-
}) // flake-utils.lib.eachDefaultSystem (system:
36+
}) // flake-utils.lib.eachDefaultSystem (system:
4737
let
4838
pkgs = import nixpkgs { inherit system; };
4939
in
@@ -60,6 +50,8 @@
6050
pyproject = false;
6151
dontUnpack = true;
6252

53+
dependencies = with pkgs; [ gnumake ];
54+
6355
installPhase = "install -Dm755 ${./update-kernels.py} $out/bin/update-kernels";
6456
};
6557
in

.github/workflows/update-kernels.py

+23
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@ def get_hash_for_repo_branch(repo, branch):
1717
return result.stdout.split("\t")[0]
1818

1919

20+
def get_nar_hash_and_version(repo, branch, hash):
21+
result = subprocess.run(
22+
["nix", "flake", "prefetch", "--json", f"git+{repo}?ref={branch}&rev={hash}"],
23+
check=True,
24+
stdout=subprocess.PIPE,
25+
text=True,
26+
)
27+
j = json.loads(result.stdout)
28+
29+
result = subprocess.run(
30+
["make", "kernelversion"],
31+
cwd=j["storePath"],
32+
check=True,
33+
stdout=subprocess.PIPE,
34+
text=True,
35+
)
36+
return (j["hash"], result.stdout.rstrip())
37+
38+
2039
if __name__ == "__main__":
2140
parser = argparse.ArgumentParser(description="Update kernel locks")
2241
parser.add_argument(
@@ -51,6 +70,10 @@ def get_hash_for_repo_branch(repo, branch):
5170
v["commitHash"] = new_hash
5271
v["lastModified"] = int(time.time())
5372

73+
(narHash, kver) = get_nar_hash_and_version(v["repo"], v["branch"], v["commitHash"])
74+
v["narHash"] = narHash
75+
v["kernelVersion"] = kver
76+
5477
diff = True
5578

5679
if not diff:

kernel-versions.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@
33
"repo": "https://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git",
44
"branch": "for-next",
55
"commitHash": "d780271744822e3b8daf08416514d0296f235b98",
6-
"lastModified": 1742302520
6+
"lastModified": 1742305077,
7+
"narHash": "sha256-75seLIhtyG+C8a/2xT0HkbHSXrhaAArfzwDFR6l1A5k=",
8+
"kernelVersion": "6.13.0"
79
},
810
"bpf/bpf-next": {
911
"repo": "https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git",
1012
"branch": "master",
1113
"commitHash": "f3f8649585a445414521a6d5b76f41b51205086d",
12-
"lastModified": 1742302520
14+
"lastModified": 1742305078,
15+
"narHash": "sha256-c3CIPMt27J6Y2MKAyc0WF7crY2HITilWOSjCEFQleww=",
16+
"kernelVersion": "6.14.0-rc3"
1317
},
1418
"stable/linux-rolling-stable": {
1519
"repo": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git",
1620
"branch": "linux-rolling-stable",
1721
"commitHash": "d2ac0b15a0ef6dc8ec73cd748ecf2919a265b0be",
18-
"lastModified": 1742302520
22+
"lastModified": 1742305155,
23+
"narHash": "sha256-4Q3liUWBdP9RFDqec59I+hwBX7NHFP2EZD2ImFv1DVc=",
24+
"kernelVersion": "6.13.7"
1925
}
2026
}

0 commit comments

Comments
 (0)