Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0758473

Browse files
committedDec 12, 2024·
add kernel cross build support for faster builds on x86_64-linux
This adds the option `raspberry-pi-nix.kernel-build-system`, which can be used to drastically decrease the build times. Description of the option: The build system to compile the kernel on. Only the linux kernel will be cross compiled, while most of the derivations are still pulled from cache.nixos.org. Use this if you cannot or don't want to use the nix-community cache and either: - you are building on an x86_64 system using binfmt_misc for aarch64-linux. - or if your x86_64 builder has a better CPU than your aarch64 builder.
1 parent aaec735 commit 0758473

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed
 

‎overlays/default.nix

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ let
2626
boards = [ "bcm2711" "bcm2712" ];
2727

2828
# Helpers for building the `pkgs.rpi-kernels' map.
29-
rpi-kernel = { version, board }:
29+
rpi-kernel = { version, board, pkgs ? final }:
3030
let
3131
kernel = builtins.getAttr version versions;
3232
version-slug = builtins.replaceStrings [ "v" "_" ] [ "" "." ] version;
3333
in
3434
{
35-
"${version}"."${board}" = (final.buildLinux {
35+
"${version}"."${board}" = (pkgs.buildLinux {
3636
modDirVersion = version-slug;
3737
version = version-slug;
3838
pname = "linux-rpi";
@@ -70,9 +70,21 @@ let
7070
'';
7171
});
7272
};
73+
7374
rpi-kernels = builtins.foldl'
7475
(b: a: final.lib.recursiveUpdate b (rpi-kernel a))
7576
{ };
77+
78+
rip-kernels-cross = buildSystem: builtins.foldl'
79+
(b: a: final.lib.recursiveUpdate b (rpi-kernel (
80+
a // {
81+
pkgs = import final.pkgs.path {
82+
system = buildSystem;
83+
crossSystem = "aarch64-linux";
84+
};
85+
}
86+
)))
87+
{ };
7688
in
7789
{
7890
# disable firmware compression so that brcm firmware can be found at
@@ -114,11 +126,16 @@ in
114126

115127
} // {
116128
# rpi kernels and firmware are available at
117-
# `pkgs.rpi-kernels.<VERSION>.<BOARD>'.
129+
# `pkgs.rpi-kernels.<VERSION>.<BOARD>'.
118130
#
119131
# For example: `pkgs.rpi-kernels.v6_6_54.bcm2712'
120132
rpi-kernels = rpi-kernels (
121133
final.lib.cartesianProduct
122134
{ board = boards; version = (builtins.attrNames versions); }
123135
);
136+
137+
rpi-kernels-cross = buildSystem: rip-kernels-cross buildSystem (
138+
final.lib.cartesianProduct
139+
{ board = boards; version = (builtins.attrNames versions); }
140+
);
124141
}

‎rpi/default.nix

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ in
1818
type = types.str;
1919
description = "Kernel version to build.";
2020
};
21+
kernel-build-system = mkOption {
22+
type = types.nullOr (types.enum [ "x86_64-linux" ]);
23+
default = null;
24+
description = ''
25+
The build system to compile the kernel on.
26+
27+
Only the linux kernel will be cross compiled, while most of the derivations are still pulled from cache.nixos.org.
28+
29+
Use this if you cannot or don't want to use the nix-community cache and either:
30+
- you are building on an x86_64 system using binfmt_misc for aarch64-linux.
31+
- or if your x86_64 builder has a better CPU than your aarch64 builder.
32+
'';
33+
example = "x86_64-linux";
34+
};
2135
board = mkOption {
2236
type = types.enum [ "bcm2711" "bcm2712" ];
2337
description = ''
@@ -334,7 +348,11 @@ in
334348
"reset-raspberrypi" # required for vl805 firmware to load
335349
];
336350
};
337-
kernelPackages = pkgs.linuxPackagesFor pkgs.rpi-kernels."${version}"."${board}";
351+
kernelPackages =
352+
if cfg.kernel-build-system == null then
353+
pkgs.linuxPackagesFor pkgs.rpi-kernels."${version}"."${board}"
354+
else
355+
pkgs.linuxPackagesFor (pkgs.rpi-kernels-cross cfg.kernel-build-system)."${version}"."${board}";
338356
loader = {
339357
grub.enable = lib.mkDefault false;
340358
initScript.enable = !cfg.uboot.enable;

0 commit comments

Comments
 (0)
This repository has been archived.